ruta propiedades openfile open obtener net desde cualquier configurar con archivos archivo abrir c# explorer

propiedades - openfiledialog c# net



Abrir una carpeta en el explorador y seleccionar un archivo (10)

La razón más posible para no encontrar el archivo es la ruta que tiene espacios. Por ejemplo, no encontrará "explorer / select, c: / space space / space.txt".

Simplemente agregue comillas dobles antes y después de la ruta, como;

explorer /select,"c:/space space/space.txt"

o haz lo mismo en C # con

System.Diagnostics.Process.Start("explorer.exe","/select,/"c:/space space/space.txt/"");

Intento abrir una carpeta en el explorador con un archivo seleccionado.

El siguiente código produce una excepción de archivo no encontrado:

System.Diagnostics.Process.Start( "explorer.exe /select," + listView1.SelectedItems[0].SubItems[1].Text + "//" + listView1.SelectedItems[0].Text);

¿Cómo puedo obtener este comando para ejecutar en C #?


La respuesta de Samuel Yang me hizo tropezar, aquí está mi valor de 3 centavos.

Adrian Hum tiene razón, asegúrate de poner comillas alrededor de tu nombre de archivo. No porque no pueda manejar espacios como señaló zourtney, sino porque reconocerá las comas (y posiblemente otros caracteres) en los nombres de archivo como argumentos separados. Así que debería verse como sugirió Adrian Hum.

string argument = "/select, /"" + filePath +"/"";


Necesita pasar los argumentos para pasar ("/ select etc") en el segundo parámetro del método de inicio.


Si su ruta contiene comas, poner comillas alrededor de la ruta funcionará cuando se use Process.Start (ProcessStartInfo).

Sin embargo, NO funcionará cuando se utilice Process.Start (string, string). Parece que Process.Start (string, string) realmente elimina las comillas dentro de tus argumentos.

Aquí hay un ejemplo simple que funciona para mí.

string p = @"C:/tmp/this path contains spaces, and,commas/target.txt"; string args = string.Format("/e, /select, /"{0}/"", p); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "explorer"; info.Arguments = args; Process.Start(info);


Solo mi valor de 2 centavos, si su nombre de archivo contiene espacios, es decir, "c: / My File Contains Spaces.txt", tendrá que rodear el nombre del archivo con comillas, de lo contrario el explorador asumirá que las otras palabras son argumentos diferentes ...

string argument = "/select, /"" + filePath +"/"";


Usa este método :

Process.Start(String, String)

El primer argumento es una aplicación (explorer.exe), el segundo argumento de método son los argumentos de la aplicación que ejecuta.

Por ejemplo:

en CMD:

explorer.exe -p

Cª#:

Process.Start("explorer.exe", "-p")


Usar Process.Start on explorer.exe con el argumento /select extrañamente solo funciona para rutas de menos de 120 caracteres.

Tuve que usar un método nativo de Windows para que funcione en todos los casos:

[DllImport("shell32.dll", SetLastError = true)] public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, uint cidl, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl, uint dwFlags); [DllImport("shell32.dll", SetLastError = true)] public static extern void SHParseDisplayName([MarshalAs(UnmanagedType.LPWStr)] string name, IntPtr bindingContext, [Out] out IntPtr pidl, uint sfgaoIn, [Out] out uint psfgaoOut); public static void OpenFolderAndSelectItem(string folderPath, string file) { IntPtr nativeFolder; uint psfgaoOut; SHParseDisplayName(folderPath, IntPtr.Zero, out nativeFolder, 0, out psfgaoOut); if (nativeFolder == IntPtr.Zero) { // Log error, can''t find folder return; } IntPtr nativeFile; SHParseDisplayName(Path.Combine(folderPath, file), IntPtr.Zero, out nativeFile, 0, out psfgaoOut); IntPtr[] fileArray; if (nativeFile == IntPtr.Zero) { // Open the folder without the file selected if we can''t find the file fileArray = new IntPtr[0]; } else { fileArray = new IntPtr[] { nativeFile }; } SHOpenFolderAndSelectItems(nativeFolder, (uint)fileArray.Length, fileArray, 0); Marshal.FreeCoTaskMem(nativeFolder); if (nativeFile != IntPtr.Zero) { Marshal.FreeCoTaskMem(nativeFile); } }


Use "/select,c:/file.txt"

Observe que debe haber una coma después / seleccionar en lugar de espacio.


// suppose that we have a test.txt at E:/ string filePath = @"E:/test.txt"; if (!File.Exists(filePath)) { return; } // combine the arguments together // it doesn''t matter if there is a space after '','' string argument = "/select, /"" + filePath +"/""; System.Diagnostics.Process.Start("explorer.exe", argument);


string windir = Environment.GetEnvironmentVariable("windir"); if (string.IsNullOrEmpty(windir.Trim())) { windir = "C://Windows//"; } if (!windir.EndsWith("//")) { windir += "//"; } FileInfo fileToLocate = null; fileToLocate = new FileInfo("C://Temp//myfile.txt"); ProcessStartInfo pi = new ProcessStartInfo(windir + "explorer.exe"); pi.Arguments = "/select, /"" + fileToLocate.FullName + "/""; pi.WindowStyle = ProcessWindowStyle.Normal; pi.WorkingDirectory = windir; //Start Process Process.Start(pi)