ddrjca
ddrjca

Reputation: 482

Using C# to load documents in default browser using a dataURI

I have a C# desktop application that receives document data from a web service.

I tried loading the documents using:

    Process.Start(new ProcessStartInfo(browserName, "data:application/pdf;base64, " + base64EncodedPDF));

however, this fails when the command line parameter exceeds the maximum allowable size.

Is there a workaround for this, one that doesn't require writing a file to the local system?

Upvotes: 1

Views: 61

Answers (1)

Eric Damtoft
Eric Damtoft

Reputation: 1423

Per microsoft docs, the character limit is 8191 characters for starting a process.

Options I can think of in order of most practical to least:

  • Writing it to a temp file (definitely the most straightforward option but you noted you wanted to avoid this)
  • Upload to cloud file storage like azure blob storage or AWS S3 and open that link
  • Using Kestrel or HttpListener to host the data from a local URL temporarily and open that
  • Using something like Selenium or PuppeteerSharp to remote control the browser and navigate to the data URL after opening the browser

Upvotes: 2

Related Questions