Notifications
Announcements
No record found.
using System.IO; using System.IO.Path; using Microsoft.Azure; using Blobstorage = Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; using Microsoft.Dynamics.Platform.Integration.SharePoint; using Microsoft.Dynamics.ApplicationPlatform.Services.Instrumentation; using Microsoft.DynamicsOnline.Infrastructure.Components.SharedServiceUnitStorage; using Microsoft.Dynamics.AX.Framework.FileManagement; public class ILUStoreFileToSharepoint { str docfiletype; Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider; public static ILUStoreFileToSharepoint construct() { return new ILUStoreFileToSharepoint(); } public void upload(DocuRef _docuRef) { System.Exception ex; System.IO.Stream memoryStream; Filename fileNameExt; DocuValue docuValue; str errorMessage; select firstonly docuValue where docuValue.RecId == _docuRef.ValueRecId; memoryStream = this.readfromAzureBlob(_docuRef); memoryStream.Seek(0, System.IO.SeekOrigin::Begin); fileNameExt = docuValue.FileName + '.' + docuValue.FileType; //str folderPath = "/sites/'new site'/'Folder'"; str folderPath = "/salesorder/SF001"; str fileContentType = System.Web.MimeMapping::GetMimeMapping(fileNameExt); ISharePointProxy proxy = null; DOCUPARAMETERS docuParameters; str src = ''; str hostName = ''; docuParameters = DOCUPARAMETERS::find(); str externalId; try { ttsbegin; if(docuParameters) { src = docuParameters.DefaultSharePointServer; System.UriBuilder builder = new System.UriBuilder(src); hostName = builder.Host; externalId = xUserInfo::getCurrentUserExternalId(); Info (externalId); try { //proxy = SharePointHelper::CreateProxy(hostName, '/', externalId); proxy = SharePointHelper::CreateProxy(hostName, '/sites/XXXXXProjects', externalId); } catch(Exception::CLRError) { proxy = null; } } if(proxy) { if(SharePointHelper::VerifyAuthentication(proxy)) { Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider prov = new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(proxy, folderPath); prov.SaveFileWithOverwrite(newguid(), fileNameExt, fileContentType, memoryStream); info('file uploaded'); } else { info('@ApplicationFoundation:SPServerUserNotAuthorized'); } } else { throw Error("SharePoint connection error"); } ttscommit; } catch (ex) { System.Exception e = ex; while (e != null) { errorMessage += e.Message; e = e.InnerException; } if (appl.ttsLevel() > 0) { ttsabort; } checkFailed("Process failed"); } } Public System.IO.Stream readfromAzureBlob(DocuRef _docuRef) { AsciiStreamIo file; container record; str downloadUrl; if (_docuRef.isValueAttached()) { System.IO.Stream docuRefStream = DocumentManagement::getAttachmentStream(_docuRef); return docuRefStream; } return null; } }
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
André Arnaud de Cal... 449 Super User 2025 Season 2
Martin Dráb 422 Most Valuable Professional
BillurSamdancioglu 239 Most Valuable Professional