Kathir Subramaniam
Kathir Subramaniam

Reputation: 1245

Open pdf in web browser in C# console application

Requirement: I have a pdf file in my machine. Using console\windows application, i need to open that pdf file from browser itself. I am getting answers to open pdf file in browser using ASP.NET. But i need answer to open pdf in browser using console app.

I tried the below code:

string localURL = @"C:\MyLocation\apllication demo.pdf";
System.Windows.Controls.WebBrowser webbrowser = new System.Windows.Controls.WebBrowser();
webbrowser.Navigate(localURL);

But no use. It asusual opening in its default application.

Upvotes: 1

Views: 3527

Answers (1)

Alex
Alex

Reputation: 987

This is simply because you are supplying a wrong path.

For browser, the path would look like this:

string localURL = "file:///C:/MyLocation/apllication%20demo.pdf"

Note that %20 is a space character,so perhaps use string.Replace(" ","%20") when building the Url.

Upvotes: 3

Related Questions