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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Open PDF in Azure Blob from X++

(0) ShareShare
ReportReport
Posted on by 20

HI All,

I'm trying to open a PDF from an Azure Bob. The first time I'm working with Azure Blob. After some googling I found some directions, but I can't get it to work. Preferably I would like to open the PDF in a new browser page. Second best: Download it to the default download folder.

The code I used:

CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("AccountName", "Key"),true);

CloudBlobClient bclient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer blobContainer = bclient.GetContainerReference("Container");

CloudBlockBlob blob = blobContainer.GetBlockBlobReference("myPDF.pdf");

      

//The next line works; The file is downloaded to the folder, but in this case I would want to save it to the users download folder

blob.DownloadToFile("c:\\temp\\myPDF.pdf", System.IO.FileMode::Create, null, null, null);

 

//The next line is the preferred solution, but it gives me a link that does not work

new Browser().navigate(bclient.BaseUri.AbsolutePath);

Does anyone have a good example for me ?

Thanks,

Gerard

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    About downloading the file - the location is entirely up to the user. D365 SaaS application can't access or see the user's local folders. It can merely offer the file to the browser to be downloaded, and then the user or browser decides where it will be downloaded.

    I think you need to decide whether you want to offer the file to be downloaded, or display it in the browser. Once you offer it for download, you can't control what the user and browser do with it, so you also can't open it automatically.

  • GerardV Profile Picture
    20 on at

    Thanks Nikolaos,

    I would prefer showing it in the browser. Do you maybe have some good working example code ? Struggling with this....

    Cheers,

    Gerard

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    If you want to show it in a browser, then you should not download it. Instead you should create a URL for the file and open it in a browser.

    new Browser().navigate([URL to the file]);

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Why are you trying to navigate to bclient.BaseUri.AbsolutePath? Shouldn't you use blob.Uri.AbsoluteUri instead?

  • GerardV Profile Picture
    20 on at

    Thanks Martin and Nikolaos,

    When I try that I get an Resource not found. Resource is available and I have the correct privileges. I will first check this again with our IT guys and get back here after that.

    Cheers,

    Gerard

  • GerardV Profile Picture
    20 on at

    Still working on this. Will update as soon as possible.

  • Suggested answer
    GerardV Profile Picture
    20 on at

    This one is fixed. Below the correct code. Besides that I also had a permission error that is solved now.

    Thanks for the help !

            CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("XXX", "YYY"),true);
            CloudBlobClient bclient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer blobContainer = bclient.GetContainerReference("Folder");
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference("File.pdf");
    
            new Browser().navigate(blob.Uri.AbsoluteUri);

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans