728x90
728x170

특정파일을 Windows  탐색기를 열어 선택하게 하는 코드

1.

using System.IO;

string filePath = @"D:\test.txt"; // 선택할 파일 


if (!File.Exists(filePath))

{

    return;

}


string argument = "/select, \"" + filePath + "\"";


System.Diagnostics.Process.Start("Explorer.exe", argument);



2.

[DllImport("shell32.dll", ExactSpelling = true)]

public static extern void ILFree(IntPtr pidlList);


[DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]

public static extern IntPtr ILCreateFromPathW(string pszPath);


[DllImport("shell32.dll", ExactSpelling = true)]

public static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);


string filePath = @"D:\test.txt"; // 선택할 파일 


var pidl = ILCreateFromPathW(filePath);

SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);


ILFree(pidl);



728x90
그리드형
Posted by kjun
,