web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How get base64 string from the application/octet-stream using CRM Plugin or javascript?

(0) ShareShare
ReportReport
Posted on by

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 have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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();

               }

           }

  • Community Member Profile Picture
    on at

    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!

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans