Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

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

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Getting PDF file from Blob Storage: Error Failed to Open Document

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans