SetSaveStream - Document Attachment

NwMib
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();
lobjFS.CopyTo(ms);
System.Guid lobjGuid = System.Guid.NewGuid();
lobjDA.DocumentReferenceID = NAV.Media.CreateMedia(lobjGuid);
gobjDSC_Bell.AddToAPI_Document_Attachment(lobjDA);
gobjDSC_Bell.SetSaveStream(lobjDA.DocumentReferenceID.Content, ms, true, new DataServiceRequestArgs { ContentType = "application/pdf" }); // ERROR
gobjDSC_Bell.SaveChanges();
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.
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();
lobjFS.CopyTo(ms);
System.Guid lobjGuid = System.Guid.NewGuid();
lobjDA.DocumentReferenceID = NAV.Media.CreateMedia(lobjGuid);
gobjDSC_Bell.AddToAPI_Document_Attachment(lobjDA);
gobjDSC_Bell.SetSaveStream(lobjDA.DocumentReferenceID.Content, ms, true, new DataServiceRequestArgs { ContentType = "application/pdf" }); // ERROR
gobjDSC_Bell.SaveChanges();
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.
0
Answers
-
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
When you provided a constructor for your class that takes arguments, the compiler no longer creates an empty constructor. Therefore, you cannot call an empty constructor because it does not exist. You would need to explicitly write the constructor that takes 0 arguments in your class's code. The constructor of the inheritance class needs to construct the base class first. since the base class does not have a default constructor (taking 0 arguments) and you are not using the non-default constructor you have now, this won't work. so either:
- Add a default constructor to your base class, in which case the code of the descending class needs no change;
Or- Call the non-default constructor of the base class from the constructor of the descending class, in which case the base class needs no change.
-1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions