Hi,
I have to read file(pdf) from sharepoint and In REST API response I am getting data with of type application/octet-stream I need to create file stream and create file(pdf).
Thanks!
*This post is locked for comments
Hi,
I have to read file(pdf) from sharepoint and In REST API response I am getting data with of type application/octet-stream I need to create file stream and create file(pdf).
Thanks!
*This post is locked for comments
I had the API hosted on Azure, which is why I didn't have the issue with Sandboxed environment, and restricted only for CORS to the CRM server. Not sure if this is an option for you.
I have checked for same but, ClientContext way throwing permission exceptions for sharepoint online credential object.
Some others developers are also not suggesting this way as it's not supported on sand box.
Please share other options..
Thanks for quick response!
This might be something else to look at, but maybe an options:
string contentType = System.Web.MimeMapping.GetMimeMapping(fileName);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
Byte[] bytes = downloadFile(item);
response.Content = new ByteArrayContent(bytes);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
response.Content.Headers.ContentDisposition.FileName = fileName;
The download file function looks like this. This was implemented for SharePoint, so you would have to modify accordingly to your requirements.
public static byte[] DownloadFile(ListItem item)
{
ClientContext ctx = ConnectToSharePoint();
List spList = ctx.Web.Lists.GetByTitle("Documents");
ctx.Load(spList);
ctx.ExecuteQuery();
ClientResult<System.IO.Stream> result = item.File.OpenBinaryStream();
ctx.ExecuteQuery();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
result.Value.CopyTo(ms);
return ms.ToArray();
}
}
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,214 Most Valuable Professional
nmaenpaa 101,156