Notifications
Announcements
No record found.
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
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();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
result.Value.CopyTo(ms);
return ms.ToArray();
}
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!
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.
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.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2