public static System.IO.Stream generateSPResponseStream(str _url)
{
//https://avanade.sharepoint.com/sites/ISG-Intersurgical/Shared%20Documents/Design/Designs/Technical%20Design%20Documents/Post%20Development/CR%20137574%20-%20TDD%20-%20Nice%20Label%20Integration%20Entity.docx
str _urlPrefix = "https://";
str _spServer= "XXXX.sharepoint.com";
str _siteName = "sites/XXXX";
str _documentFolder = "XXXXX";
str _fileName= "XXXX";
str _fileExt= ".pdf";
System.IO.Stream Stream;
System.Net.WebException webEx;
//DocuType fileType = DocuType::find("");
System.UriBuilder builder = new System.UriBuilder('XXXX.sharepoint.com');
str extId = xUserInfo::getCurrentUserExternalId();
Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider provider;
Microsoft.Dynamics.AX.Framework.FileManagement.DocumentContents documentContents;
Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation location = new Microsoft.Dynamics.AX.Framework.FileManagement.DocumentLocation();
provider = new Microsoft.Dynamics.AX.Framework.FileManagement.SharePointDocumentStorageProvider(
_spServer, _siteName, _documentFolder, extId);
provider.ProviderId = DocuStorageProviderType::SharePoint;
str url = _urlPrefix + _spServer + "/" + _siteName + "/" + _documentFolder
+ "/" + (_fileName + _fileExt);
info(strFmt("URL : %1",URL));
System.Uri uri = new System.Uri(url);
System.Uri uri1 = new System.Uri(_urlPrefix + _spServer + "/" + _siteName
+ "/_api/Web/GetFileByServerRelativePath(decodedurl='/"
+ _siteName + "/" + _documentFolder + "/" + (_fileName + _fileExt) + "')");
//System.Uri uri1 = new System.Uri("https://intersurgicalglobal.sharepoint.com/sites/Products/_api/WebGetFileByServerRelativePath(decodedurl='/sites/Products/Shared Documents/Specifications/XXXX.pdf')");
location.NavigationUri = uri;
location.AccessUri = uri1;
documentContents = provider.GetFile(location);
try
{
if (documentContents)
{
Stream = documentContents.Content;
}
else
{
Error(strFmt("Error"));
}
}
catch(webEx)
{
Error(webEx.Message);
}
return Stream;
}
While trying above code unable to fetch the file as code is dropping in else block with error message. Is this because of any access missing ?