简体   繁体   中英

Invoke htm file with query string in browser from C# issue

We are trying to open a htm file in a firefox browser from a C# console app. The htm file is supposed to take the name of a video file as a query string parameter so that the file can be played back in the browser. Now both the video file and the htm are local to the C# console app.

We have used the following code:

var playerFile = Path.Combine(folderPath, "player.htm");
var medianame = Path.GetFileNameWithoutExtension(mediaFilename) + ".theora.ogv";
var url = string.Format("{0}?name={1}", playerFile, medianame);
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", url);

The url should be of the form

file:///D:/Projects/Tester/bin/Debug/Content/player.htm?name=Promo[39171369900].theora.ogv

but when the firefox browser opens up, it has the following in the address bar:

file:///D:/Projects/Tester/bin/Debug/Content/player.htm%3Fname=Promo%5B39171369900%5D.theora.ogv

Since the ? and [ ] are getting url encoded when opening up in the browser, it cannot play the video. If the %3F and %5B %5D are replaced, the file plays properly.

Can anybody provide any help.

Please use the Server.UrlDecode method to decode your url

Or try using the System.Uri.UnescapeDataString

To answer my own question, I finally solved the issue using a batch file to open the htm file and invoked the batch from the C# app, passing the filename as argument to the batch. Thanks for all your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM