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;
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156