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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting PDF file from Blob Storage: Error Failed to Open Document

(0) ShareShare
ReportReport
Posted on by 325

Hi All,

I need help on this one. I'm getting the PDF file from Blob Storage the re-upload it to another record as Annotation (Notes). But when I tried to open the document, it prompts me "Failed to Open Document". I can successfully open a text file, an excel file or other documents except for PDF. Here's my code:

using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri)
            { Content = (requestPayload == null) ? null : new ByteArrayContent(requestPayload) })
            {
                using (var client = new HttpClient())
                {
                    var response = client.SendAsync(httpRequestMessage).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        tracer.Trace(String.Format(blobType));
                        if (blobType == "application/pdf")
                        {
                            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                        }

                        string data = response.Content.ReadAsStringAsync().Result;
                        tracer.Trace(String.Format(response.Content.Headers.ContentType.ToString()));
                        
                        byte[] byteData = System.Text.Encoding.UTF8.GetBytes(data);
                        string encoded = Convert.ToBase64String(byteData, 0, System.Text.Encoding.UTF8.GetByteCount(data));
                        return encoded;
                    }
                }
            }


*This post is locked for comments

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    if it works with other documents like excel file, my best guess is that the PDF is not stored correctly inside the blob

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans