3

In my software i need to show the property dialog of a file and navigate to a specific tab in that property dialog? please tell me how to acheive this using c#?

or Is it possible to replace the default property dialog with a custom one?

Artemix
  • 2,113
  • 2
  • 23
  • 34
logeeks
  • 4,849
  • 15
  • 62
  • 93
  • I'm not sure it's even possible to show the default property dialog for a file programatically. You could probably emulate it though, or create something similar to it, and display the info you need there. What info exactly is it you need? – Kjartan Aug 31 '12 at 11:01

2 Answers2

3
private bool properties(string Filename) 
{
    SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
    info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
    info.lpVerb = "properties";
    info.lpParameters = "Details";
    info.lpFile = Filename;
    info.nShow = SW_SHOW;
    info.fMask = SEE_MASK_INVOKEIDLIST;
    return ShellExecuteEx(ref info);
}

By setting info.lpParameters to name of the tab you want it gets opened with that tab selected. In my case "Details"...

Yes you need that declaration that codeteq wrote.

This is the declaration that I use:

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;

[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;

}

Ivan
  • 31
  • 3
  • How your solution differ from codeteq's answer? Please add some comments. It won't work without P/Invoke declarations that codeteq has shown. – Artemix May 29 '13 at 10:49
  • In the future, if you copy content from anywhere else (someone else's answer, or some other website or a book) it is required that you clearly link to where you got it from. – Andrew Barber May 29 '13 at 14:16
  • Ok, didn't know it was my first post. I just wanted to help. – Ivan May 30 '13 at 11:29
0

You must use P/Invoke to achieve this:

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;

[DllImport("shell32.dll")]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

public static void 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;
    ShellExecuteEx(ref info);
}

don't know if it's even possible to select a specific tab (in a nice way)...

codeteq
  • 1,502
  • 7
  • 13