Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Document Attachment OData

(0) ShareShare
ReportReport
Posted on by 809

I'm trying to add a Document Attachment record via an OData Connected Service to a NAV database in C# (Visual Studio Professional 2017), (see code below):-

string lstrFileName = @"C:\Users\user.name\Documents\PDF\BCTest\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(5900, "SO000006", "Order", 0, 1);
lobjDA.AttachedDate = DateTime.Now;
lobjDA.FileName = lfi.Name;
lobjDA.FileExtension = lfi.Extension.Replace(".", string.Empty);
lobjDA.FileType = "2";
objContext.AddToAPI_Document_Attachment(lobjDA);
objContext.SaveChanges();
… but when it gets to SaveChanges, I get: "{"error":{"code":"Application_DialogException","message":"Please attach a document first."}}"

How do I programmatically attach a document?

  • Suggested answer
    Mohamad Vajid Profile Picture
    on at
    RE: Document Attachment OData

    Duplicate of community.dynamics.com/.../document-attachment

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans