EDN Admin
Well-known member
I have used winAPI to get map drives full path (Example if it is Z:myFolder then it should give as \ServerNameORIPMyFolder.
I have written a code in an library project, which is being called in web service.
Web service is running under windows authentication with Indentity Impersonate = TRUE. I have checked all possible configuration in IIS as well.
Could anybody guide?
[size="2 color="#0000ff"][size="2 color="#0000ff"]
public[/size][size="2 color="#0000ff"]
[/size][/size]
static class Pathing
{
[
DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WNetGetConnection(
[
MarshalAs(UnmanagedType.LPTStr)] string localName,
[
MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
ref int length);
/// <summary>
/// Given a path, returns the UNC path or the original. (No exceptions
/// are raised by this function directly). For example, "P:2008-02-29"
/// might return: "\networkserverSharesPhotos2008-02-09"
/// </summary>
/// <param name="originalPath The path to convert to a UNC Path</param>
/// <returns>A UNC path. If a network drive letter is specified, the
/// drive letter is converted to a UNC or network path. If the
/// originalPath cannot be converted, it is returned unchanged.</returns>
public static string GetUNCPath(string originalPath)
{
StringBuilder sb = new StringBuilder(512);
int size = sb.Capacity;
// look for the {LETTER}: combination ...
if (originalPath.Length > 2 && originalPath[1] == :)
{
// dont use char.IsLetter here - as that can be misleading
// the only valid drive letters are a-z && A-Z.
char c = originalPath[0];
if ((c >= a && c <= z) || (c >= A && c <= Z))
{
int error = WNetGetConnection(originalPath.Substring(0, 2),
sb,
ref size);
if (error == 0)
{
DirectoryInfo dir = new DirectoryInfo(originalPath);
string path = Path.GetFullPath(originalPath)
.Substring(
Path.GetPathRoot(originalPath).Length);
return Path.Combine(sb.ToString().TrimEnd(), path);
}
else
{
RemoteNameInfo info =new RemoteNameInfo();
info =
WNet.GetRemoteNameInfo(originalPath);
}
}
}
return originalPath;
}
}
nilesh k
View the full article
I have written a code in an library project, which is being called in web service.
Web service is running under windows authentication with Indentity Impersonate = TRUE. I have checked all possible configuration in IIS as well.
Could anybody guide?
[size="2 color="#0000ff"][size="2 color="#0000ff"]
public[/size][size="2 color="#0000ff"]
[/size][/size]
static class Pathing
{
[
DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WNetGetConnection(
[
MarshalAs(UnmanagedType.LPTStr)] string localName,
[
MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
ref int length);
/// <summary>
/// Given a path, returns the UNC path or the original. (No exceptions
/// are raised by this function directly). For example, "P:2008-02-29"
/// might return: "\networkserverSharesPhotos2008-02-09"
/// </summary>
/// <param name="originalPath The path to convert to a UNC Path</param>
/// <returns>A UNC path. If a network drive letter is specified, the
/// drive letter is converted to a UNC or network path. If the
/// originalPath cannot be converted, it is returned unchanged.</returns>
public static string GetUNCPath(string originalPath)
{
StringBuilder sb = new StringBuilder(512);
int size = sb.Capacity;
// look for the {LETTER}: combination ...
if (originalPath.Length > 2 && originalPath[1] == :)
{
// dont use char.IsLetter here - as that can be misleading
// the only valid drive letters are a-z && A-Z.
char c = originalPath[0];
if ((c >= a && c <= z) || (c >= A && c <= Z))
{
int error = WNetGetConnection(originalPath.Substring(0, 2),
sb,
ref size);
if (error == 0)
{
DirectoryInfo dir = new DirectoryInfo(originalPath);
string path = Path.GetFullPath(originalPath)
.Substring(
Path.GetPathRoot(originalPath).Length);
return Path.Combine(sb.ToString().TrimEnd(), path);
}
else
{
RemoteNameInfo info =new RemoteNameInfo();
info =
WNet.GetRemoteNameInfo(originalPath);
}
}
}
return originalPath;
}
}
nilesh k
View the full article