简体   繁体   中英

Trying to launch PhotoViewer in C# but am getting conflicting information. What do I need to do?

I am using C# in Windows 11.
PhotoViewer is the default app for AVI files on my PC. I am trying to launch PhotoViewer with an AVI file using the "Process.Start" method as follows:

MessageBox.Show(fn + " exists? " + File.Exists(fn));
Process.Start("@" + fn);

The MessageBox output is "d:\dscf0001.avi exists? true."
Process.Start throws a Win32Exception with the message "The system cannot find the file specified."
What am I doing wrong?

I guess you have read from the internet, something like

Process.Start(@"D:\document.pdf");

They put the @ at the beginning because the character \ is the escape character and it needs to be disabled by @.

Refer:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim

https://www.tutorialsteacher.com/csharp/csharp-string

In your case, you don't need it.

Process.Start(fn);

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