Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display a file's Properties dialog from C#?

Tags:

c#

how to open an file's Properties dialog by a button

private void button_Click(object sender, EventArgs e) {     string path = @"C:\Users\test\Documents\tes.text";     // how to open this propertie } 

Thank you.

For example if want the System properties

Process.Start("sysdm.cpl");     

But how do i get the Properties dialog for a file path?

like image 994
User6996 Avatar asked Dec 20 '09 19:12

User6996


People also ask

How do I Display properties dialog box for folder or file?

You can also Alt-click on a file or folder to access its properties. The General tab of the Properties dialog box will provide you with information such as the full path to the file or folder, its size, what application is configured to open it, and the date it was created, last modified, and accessed.

How would you display a folder properties?

To view information about a file or folder, right-click it and select Properties. You can also select the file and press Alt + Enter . The file properties window shows you information like the type of file, the size of the file, and when you last modified it.

How do I get File Explorer properties?

In File Explorer, hold down the ALT key and simply double click the file or folder. The Properties window will open directly! You don't need to right click and select the Properties menu item. If you prefer exclusively using the keyboard, you can select the file and press Alt+Enter.

How do I open folder properties in keyboard?

Ctrl+Shift+N creates a new folder in your current directory. Alt+Enter opens the file properties so you can view file size, sharing settings, and creation date.


2 Answers

Solution is:

using System.Runtime.InteropServices;  [DllImport("shell32.dll", CharSet = CharSet.Auto)] static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SHELLEXECUTEINFO {     public int cbSize;     public uint fMask;     public IntPtr hwnd;     [MarshalAs(UnmanagedType.LPTStr)]     public string lpVerb;     [MarshalAs(UnmanagedType.LPTStr)]     public string lpFile;     [MarshalAs(UnmanagedType.LPTStr)]     public string lpParameters;     [MarshalAs(UnmanagedType.LPTStr)]     public string lpDirectory;     public int nShow;     public IntPtr hInstApp;     public IntPtr lpIDList;     [MarshalAs(UnmanagedType.LPTStr)]     public string lpClass;     public IntPtr hkeyClass;     public uint dwHotKey;     public IntPtr hIcon;     public IntPtr hProcess; }  private const int SW_SHOW = 5; private const uint SEE_MASK_INVOKEIDLIST = 12; public static bool ShowFileProperties(string Filename) {     SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();     info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);     info.lpVerb = "properties";     info.lpFile = Filename;     info.nShow = SW_SHOW;     info.fMask = SEE_MASK_INVOKEIDLIST;     return ShellExecuteEx(ref info);         }  // button click private void button1_Click(object sender, EventArgs e) {     string path = @"C:\Users\test\Documents\test.text";     ShowFileProperties(path); } 
like image 95
User6996 Avatar answered Oct 15 '22 04:10

User6996


Call Process.Start, passing a ProcessStartInfo containing the name of the file, and with the ProcessStartInfo.Verb set to properties. (For more info, see the description of the unmanaged SHELLEXECUTEINFO structure, which is what ProcessStartInfo wraps, and in particular the lpVerb member.)

like image 43
itowlson Avatar answered Oct 15 '22 03:10

itowlson