D365 FO/AX7: Sharepoint File Upload using X++

Requirement :

Uploading a file in Sharepoint online using X++ and inside from Microsoft Dynamics 365 finance and operations.


The current user id of Microsoft Dynamics 365 Finance and operations should have proper rights and privileged in Sharepoint Online.

Sample Code:

In this scenario i am creating a text file in Microsoft Dynamics 365 finance and operations and then uploading its memory Stream in Sharepoint online using X++ . You can modify the X++ code in D365 finance and operations as per your need.

class RunnableClassRun
/// /// Runs the class with the specified arguments. ///
/// The specified arguments.
public static void main(Args _args)
System.UriBuilder builder = new System.UriBuilder(“https://XXXXXX.sharepoint.com”);
str extId = xUserInfo::getExternalId();
Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider provider;
Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation documentLocation = new Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation();
provider = new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(“XXXXXX.sharepoint.com”, “sites/dummy”, “Shared%20Documents/MyFolder”, extId);
System.Byte[] reportBytes = new System.Byte[0]();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
reportBytes = enc.GetBytes(“YOUR STRING/TEXT”);
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(reportBytes);
//memoryStream = comma.getStream();
documentLocation = provider.SaveFile(newGuid(), ‘TextFile.txt’, System.Web.MimeMapping::GetMimeMapping(‘TextFile.txt’), memoryStream);



4 thoughts on “D365 FO/AX7: Sharepoint File Upload using X++”

Leave a Reply