这个就比较简单了。
1、从程序中获取需要打开的文件路路径
2、根据路径绑定到具体的列表中,如果需要好看的话可以根据文件名获取其ICON,我以前使用过的代码:
#region 根据文件路径获取图标
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
class Win32
{
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0;
public const uint SHGFI_SMALLICON = 0x1;
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
}
/// <summary>
/// 根据文件路径获取小图标
/// </summary>
/// <param name="fileName">文件路径(例如:F:\,F:\Images,F:\Images\Bg.jpg)</param>
/// <returns>Icon图标</returns>
public static Icon GetSmallIcon(stringfileName)
{
IntPtr hImgSmall;
SHFILEINFO shinfo = new SHFILEINFO();
hImgSmall = Win32.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
return System.Drawing.Icon.FromHandle(shinfo.hIcon);
}
/// <summary>
/// 根据文件路径获取大图标
/// </summary>
/// <param name="fileName">文件路径(例如:F:\,F:\Images,F:\Images\Bg.jpg)</param>
/// <returns>Icon图标</returns>
public static Icon GetLargeIcon(string fileName)
{
IntPtr hImgLarge; list
SHFILEINFO shinfo = new SHFILEINFO();
hImgLarge = Win32.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
return System.Drawing.Icon.FromHandle(shinfo.hIcon);
}
/// <summary>
/// 从文件扩展名得到文件关联图标
/// </summary>
/// <param name="fileName">文件名或文件扩展名</param>
/// <param name="smallIcon">是否是获取小图标,否则是大图标</param>
/// <returns>Icon图标</returns>
static public Icon GetFileIcon(string fileName, bool smallIcon)
{
SHFILEINFO fi = new SHFILEINFO();
Icon ic = null;
int iTotal = (int)Win32.SHGetFileInfo(fileName, 100, ref fi, 0, (uint)(smallIcon ? 273 : 272));
if (iTotal > 0)
{
ic = Icon.FromHandle(fi.hIcon);
}
return ic;
}
#endregion
3、当双击某个文件的时候使用system.Diagnostics.Process.Start(文件路径)启动点击的程序。
利用System.Diagnostics.Process.Start启动。
参考:http://www.cnblogs.com/pclook/archive/2009/05/06/1450542.html
http://www.cnblogs.com/haoliansheng/archive/2009/05/27/1490779.html