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, ...
Suggested Answer

How can we upload files (more than 250MB) to Sharepoint using X++ code?

(0) ShareShare
ReportReport
Posted on by 15

Hi All,

I am using below X++ code to upload files to Sharepoint in D365FO and working fine for files less than 250 MB but getting error if file size exceeding to 250MB: 

3364.pastedimage1627283625583v1.png

 

Code:

str site = '/FO';
str folder = strFmt("Shared%20Documents/%1", reportFolder);
System.UriBuilder builder = new System.UriBuilder('XXXX.sharepoint.com');
str host = builder.Host;
str extId = xUserInfo::getCurrentUserExternalId();

Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider storageProvider =
new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(host, site, folder, extId);

storageProvider.ProviderId = DocuStorageProviderType::SharePoint;

stream.Position = 0;
storageProvider.SaveFile(newGuid(), filename, 'application/xlsx', stream);

 

We are able to upload manually more than 250 MB files in Sharepoint but why not using codes.

Please help.

Thanks,

Kumar Rohit

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Your problem is caused by a limit in SharePoint, not in D365FO.

    If you want to upload a file larger than 250 MB, you can't do it at once. You need to upload it in several chunks. Refer to Uploading large files to Sharepoint 365, for example.

  • WillWU Profile Picture
    22,361 on at

    Hi Kumar,

    And please check how to upload large file using the StartUpload, ContinueUpload, and FinishUpload REST endpoints:docs.microsoft.com/.../upload-large-files-sample-app-for-sharepoint

  • Kumar Rohit Profile Picture
    15 on at

    Hi Martin,

    Thanks for the reply.

    Suggested codes are in C# not in X++ so does it mean we can't write codes in X++ for larger files upload to sharepoint?

    I was checking this code but I got below issues:

    1. In X++, we use external user id to manage access rights to sharepoint and don't need to provide credentials explicitly.

    But In C#, we have to write credential explicitly. Do we have other options to connect ?

    2. We have MFA authentication for users so getting an error: The sign-in name or password does not match one in the Microsoft account system

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    The fact that some code is written in a certain language doesn't mean that it's the only language that the same thing can be written. You can go and rewrite it to X++. But you don't have to - you can create a C# class library, put C# code there and call the library from X++. Your own code above is an example of calling such a library.

    You also could (although I don't think that you should) use the REST API instead of CSOM. The REST API can be used from any language on any platform.

    Or maybe you should simply avoid sending such large files through your ERP system. It might suggests that your business processes aren'r optimal and you should fix the process, not code.

  • Kumar Rohit Profile Picture
    15 on at

    Hi Martin,

    I already tried the way you are suggesting (adding C# library .dll files to x++ project reference) but getting error on executeQuery().

    using (var clientContext = new ClientContext("xxxxxx.sharepoint.com"))

               {

                   clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                   Web web = clientContext.Web;

                   clientContext.Load(web, a => a.ServerRelativeUrl);

                   clientContext.ExecuteQuery(); // Getting error: The sign-in name or password does not match one in the Microsoft account system.

                   List documentsList = clientContext.Web.Lists.GetByTitle("Documents");

                   FileCreationInformation createFile = new FileCreationInformation();

                   createFile.Url = "test.txt";

                   //use byte array to set content of the file

                   string somestring = "hello there";

                   byte[] toBytes = Encoding.ASCII.GetBytes(somestring);

                   createFile.Content = toBytes;

                   List spList = clientContext.Web.Lists.GetByTitle("Documents");

                   Microsoft.SharePoint.Client.File addedFile = spList.RootFolder.Files.Add(createFile);

                   clientContext.Load(addedFile);

                   clientContext.ExecuteQuery();

               }

    If you have any reference code in X++ would be best for me.

    Please suggest.

    Thanks,
    Kumar Rohit

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    It seems that your current problem is about SharePoint and C#, not about D365FO. It might be the best to discuss it in a SharePoint forum.

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
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans