17-10-12, 05:54 PM
كاتب الموضوع : Boutemine Oualid
السلام عليكم و رحمة الله و بركاتهكود :
using System.Text;
using System.Runtime.InteropServices
[DllImport("shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PathIsNetworkPath([MarshalAs(UnmanagedType.LPTStr)]string pszPath);
[DllImport("mpr.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "WNetGetConnectionW")]
public static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPWStr)]string lpLocalName, StringBuilder lpRemoteName, ref int lpnLength);
public string GetUNCPath(string NetworkPath)
{
string szRoot = NetworkPath.Substring(0, 2);
string szPath = NetworkPath;
if (PathIsNetworkPath(szPath))
{
StringBuilder szbUNC = new StringBuilder(260);
int iLength = 260;
if (WNetGetConnection(szRoot, szbUNC, ref iLength) == ERROR_SUCCESS)
{
szPath = Path.Combine(szbUNC.ToString(), Path.GetFileName(szPath));
}
}
return szPath;
}