File properties dialog

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, all
How can I display File properties dialog (r-click a file in Explorer, the
click "Properties"menuitem) - C# Windows Applicatio

Thanks a lot!
 
Hi Oren,

To show the file properties dialog you will need to p/invoke the
ShellExecute Win32 API.

Add the following import to the top of your form...

\\\
using System.Runtime.InteropServices;
///

....then add the following structure, API declaration and constant...

\\\
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
public string lpVerb;
public string lpFile;
public string lpParameters;
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public int lpIDList;
public string lpClass;
public IntPtr hkeyClass;
public int dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}

[DllImport("shell32", CharSet=CharSet.Auto)]
extern static int ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

private const int SEE_MASK_INVOKELIST = 0xC;
///

....then use the following code in the your procedure where you want to show
the file properties dialog from (replacing the value assigned to lpFile with
your own file name)...

\\\
SHELLEXECUTEINFO seInfo = new SHELLEXECUTEINFO();

seInfo.cbSize = Marshal.SizeOf(seInfo);
seInfo.fMask = SEE_MASK_INVOKELIST;
seInfo.lpVerb = "properties";
seInfo.lpFile = @"C:\Windows\NOTEPAD.EXE";

ShellExecuteEx(ref seInfo);
///

Hope this helps.

Gary
 
Back
Top