web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Error while uploading file to Sharepoint through X++

(0) ShareShare
ReportReport
Posted on by 80

Hi All,

 

I have a requirement to upload PDF file to sharepoint online in D365FnO. I am using the below code snippet, this snippet is being used in a lot of examples online for uploading the PDF file to share point.

 

I am giving an external id that is working. The sharepoint link given in the document management parameters are validated successfully. I do not see any issue on the setup.

 

But when running the below piece of code, I get an error at the line storageProvider.SaveFile 

34BE5360.PNG

externalId = xUserInfo::getExternalId("XXX.YY");

        //externalId = "10033FFFAE505117";

        System.Byte[] value = this.runAndSaveSSRSReport();

        System.IO.MemoryStream stream = new System.IO.MemoryStream(value);

       // System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(System.Convert::FromBase64String(value));

        // Instantiate SharePoint document storage provider with sharepoint address path.

        Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider = new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(

        defaultSPServer,

        spSite,

        spFolderPath,

        externalId);

 

        storageProvider.ProviderId = DocuStorageProviderType::SharePoint;

 

        if (storageProvider != null)

        {

            // Generates a unique file name in case the file name already exists on SharePoint path.

           // str uniqueFilename = storageProvider.GenerateUniqueName(filename);

            // Upload file to SharePoint Online path.

            Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation location = storageProvider.SaveFile(

            newGuid(),

            FileName,

            fileContetType,

            stream);

 

 Is there some configuration I am missing? Will be very helpful if someone can shed light on this, 

Thanks in advance

Sabarish

I have the same question (0)
  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    Why you are using code when you can set up a SharePoint site specifically for files related to Dynamics 365 Finance ?

  • Navneeth Nagrajan Profile Picture
    2,438 Super User 2025 Season 2 on at

    Hello Sabarish,

    Are you able to retrieve the connection string and the user credentials in a variable through code? Another question is are you able to connect to the SharePoint site successfully through the userId that you are retrieving in the externalId variable?

    Is this like a helper class that you are trying to build to upload PDF files? 


    Thanks,
    Navneeth Nagrajan | Dynamics 365 Technical Consultant

  • Verified answer
    WillWU Profile Picture
    22,363 on at

    Hi Sabarish,

    You should have a SharePoint Online domain and an account which has enough access rights to upload and manage files, and the D365fFO user should have “ExternalId”.

    Make sure the following values of parameters are correct.

    defaultSPServer,

    spSite,

    spFolderPath,

    externalId.

    You can refer to this blogs:

    https://d365dev.com/

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans