C # Opens the file under the specified path

Source: Internet
Author: User
C # Opens the file under the specified path

 <summary>////Open the file under the specified path, such as Word, Excel, Dll, picture, etc. (provided that you have installed the software to open the program)///</summary>/ <param name= "NewFileName" >eg:d:\test\ template 8.doc</param>//<param name= "NewFileName" >eg:d:\test\ Template 8.doc</param> private void OpenFile (string newfilename) {Process process = new process ()            ;            ProcessStartInfo ProcessStartInfo = new ProcessStartInfo (newfilename); Process. StartInfo = processstartinfo;# Region Below this is commented out code (can be used to open the code in full screen)////to establish a new system process//system.diagnostics.process Proce            SS = new System.Diagnostics.Process (); Set the file name, here is the real path of the picture + file name (suffix required)//process.            Startinfo.filename = NewFileName; This is a critical part.                Sets the process run parameters, at which time the picture is displayed for the maximized window. Process.            startinfo.arguments = "Rundll32.exe c://windows//system32//shimgvw.dll,imageview_fullscreen"; This entry is not available if the shell is used to execute the program, because the system defaults to true, but if the setting must be true//process. Startinfo.usesheLlexecute = true; #endregion try {process.                Start (); try {//process.                WaitForExit ();                } catch (Exception ex) {throw ex;            }} catch (Exception ex) {throw ex;                    } finally {try {if (process! = NULL) {process.                        Close ();                    Process = NULL; }} catch {}}}

Today, at the time of the test, I don't know who

Process. StartInfo = ProcessStartInfo;

After this sentence, added a sentence:

Process. Startinfo.useshellexecute = false;

Did not notice at first, and then always reported the following error:

The specified executable is not a validapplication for this OS platform.

Explain:

Processstartinfo.useshellexecute property: Gets or sets a value that indicates whether the process is started using the operating system shell.

Property value:
True if the shell is used when the process is started, otherwise, the process is created directly from the executable file. The default is true. Set the property to False to redirect the input stream, output stream, and error stream. Or not.
When you start a process by using the operating system shell, you can use the Process component to start any document (which can be any registered file type associated with the executable file that has the default open action) and perform operations (such as printing) on the file. If UseShellExecute is false, the executable file can only be started using the process component.

The above is C # Open the contents of the file under the specified path, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.