SetSaveStream - Document Attachment

NwMibNwMib Member Posts: 1
I'm trying to add a Document Attachment record via an Unchase Connected Service to a Microsoft Dynamics NAV database in C# (Visual Studio 2019).
I downloaded the XML metadata from a Dynamics NAV URL. In Visual Studio, I perform an Add / Update Unchase Connected Service and point it at the metadata file. This process auto-generates a Reference.cs code-file. I then call the appropriate objects / properties / methods (see code below):-

const int SHTABLEID = 5900;
string lstrFileName = @C:\Test\Test Attachment 3.pdf;
System.IO.FileInfo lfi = new System.IO.FileInfo(lstrFileName);
NAV.API_Document_Attachment lobjDA = NAV.API_Document_Attachment.CreateAPI_Document_Attachment(SHTABLEID, "SO000006", "Order", 0, 1);
lobjDA.AttachedDate = DateTime.Now;
lobjDA.FileName = lfi.Name;
lobjDA.FileExtension = lfi.Extension.Replace(".", string.Empty);
lobjDA.FileType = "2";
FileStream lobjFS = new FileStream(lstrFileName, FileMode.Open);
var ms = new MemoryStream();
System.Guid lobjGuid = System.Guid.NewGuid();
lobjDA.DocumentReferenceID = NAV.Media.CreateMedia(lobjGuid);

gobjDSC_Bell.SetSaveStream(lobjDA.DocumentReferenceID.Content, ms, true, new DataServiceRequestArgs { ContentType = "application/pdf" }); // ERROR


The SetSaveStream line of code above produces the error: 'Value cannot be null. Parameter name: entity' Sure enough the Content property is null.
As the Content property is of type: DataServiceStreamLink and there doesn't appear to be a way of instantiating it in the conventional way
(e.g.) lobjDA.DocumentReferenceID.Content = new DataServiceStreamLink();
error CS1729: 'DataServiceStreamLink' does not contain a constructor that takes 0 arguments

The hierarchy of objects used is shown below:
lobjDA : NAV.API_Document_Attachment
lobjDA.DocumentReferenceID : NAV.Media
lobjDA.DocumentReferenceID.Content : DataServiceStreamLink

… I'm stuck in a bit of a stalemate at the moment. Any thoughts? Thanks in advance for any support given.
Sign In or Register to comment.