ProcessStartInfo.FileName Property

Gets or sets the application or document to start.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public string FileName { get; set; }
/** @property */
public String get_FileName ()

/** @property */
public void set_FileName (String value)

public function get FileName () : String

public function set FileName (value : String)

Property Value

The name of the application to start, or the name of a document of a file type that is associated with an application and that has a default open action available to it. The default is an empty string ("").

You must set at least the FileName property before starting the process. The file name is any application or document. Here a document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer using the Folder Options dialog available through the operating system. The Advanced button leads to a dialog that shows whether there is an open action associated with a specific registered file type.

The set of file types available to you depends in part on the value of the UseShellExecute property. If UseShellExecute is true, you are able to start any document and perform operations on the file, such as printing, with the Process component. When UseShellExecute is false, you are able to start only executables with the Process component.

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
	/// <summary>
	/// Shell for the sample.
	/// </summary>
	class MyProcess
		// These are the Win32 error code for file not found or access denied.
		const int ERROR_FILE_NOT_FOUND =2;
		const int ERROR_ACCESS_DENIED = 5;

		/// <summary>
		/// Prints a file with a .doc extension.
		/// </summary>
		void PrintDoc()
			Process myProcess = new Process();
				// Get the path that stores user documents.
				string myDocumentsPath = 

				myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; 
				myProcess.StartInfo.Verb = "Print";
				myProcess.StartInfo.CreateNoWindow = true;
			catch (Win32Exception e)
				if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
					Console.WriteLine(e.Message + ". Check the path.");

				else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
					// Note that if your word processor might generate exceptions
					// such as this, which are handled first.
					Console.WriteLine(e.Message + 
						". You do not have permission to print this file.");

		public static void Main()
			MyProcess myProcess = new MyProcess();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions