How to launch file properties window from winform?
-
How can I launch the file properties window (i.e. the window launched by right clicking in windows explorer -> properties) from a win forms app (I have the filename). Jim -- modified at 7:20 Tuesday 13th December, 2005
-
How can I launch the file properties window (i.e. the window launched by right clicking in windows explorer -> properties) from a win forms app (I have the filename). Jim -- modified at 7:20 Tuesday 13th December, 2005
First, declare the following in your class.
private const int SEE_MASK_INVOKELIST = 0xC;
public struct SHELLEXECUTEINFO
{
public int cbSize;
public int 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 int dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}[DllImport( "shell32.dll", CharSet=CharSet.Auto )]
static extern bool ShellExecuteEx( ref SHELLEXECUTEINFO lpExecInfo );Then, in your code, invoke it with the following.
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf( info );
info.lpVerb = "properties";
info.lpFile = @"THE\PATH\TO\YOUR\FILE\HERE";
info.hwnd = Handle;
info.fMask = SEE_MASK_INVOKELIST;
ShellExecuteEx( ref info );.Now, more importantly, I had no idea how to do this until you asked. Here's how I figured it out.
- I Googled for: C# "file properties" dialog. This led me to learn about using ShellExecuteEx.
- Go to http://www.pinvoke.net to learn about ShellExecuteEx.
- Copied the code from the Web page to my project and BAM! it worked.
Now, you have an immediate and long-term answer. <smile />
-
First, declare the following in your class.
private const int SEE_MASK_INVOKELIST = 0xC;
public struct SHELLEXECUTEINFO
{
public int cbSize;
public int 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 int dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}[DllImport( "shell32.dll", CharSet=CharSet.Auto )]
static extern bool ShellExecuteEx( ref SHELLEXECUTEINFO lpExecInfo );Then, in your code, invoke it with the following.
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf( info );
info.lpVerb = "properties";
info.lpFile = @"THE\PATH\TO\YOUR\FILE\HERE";
info.hwnd = Handle;
info.fMask = SEE_MASK_INVOKELIST;
ShellExecuteEx( ref info );.Now, more importantly, I had no idea how to do this until you asked. Here's how I figured it out.
- I Googled for: C# "file properties" dialog. This led me to learn about using ShellExecuteEx.
- Go to http://www.pinvoke.net to learn about ShellExecuteEx.
- Copied the code from the Web page to my project and BAM! it worked.
Now, you have an immediate and long-term answer. <smile />
Thanks, I did search on Google but not with quite the right phrase it seems. Thats another site for the bookmarks :) Jim
-
Thanks, I did search on Google but not with quite the right phrase it seems. Thats another site for the bookmarks :) Jim
Jim, Glad I could help. I understand the "not with quite the right phrase" deal. I have done some interesting research into Information Retrieval and understand that Google is powerful for pretty simple searches, but not the contextual stuff. I hope that last section didn't sound too pedantic. I don't want to insult your intelligence. Just thought I'd give you an insight into my problem solving steps. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty