Last post Sep 27, 2012 10:25 PM by oak_silver
Sep 26, 2012 08:42 AM|chinna373|LINK
I am trying to access a mapped network drive from a service that I have created.
The service needs to create/delete folders/files on a network drive. When I tried to connect to a folder on mapped network drive (eg. N:\Storage that corresponds to \\FS1NS\SharedDir\), I get an error as "Could not find part of
I tried running the service in the Administrators account but the same problem. The thing works if I directly access the network share
Is there anykind of restriction on access to the mapped drives when tried from a service (it did work from a C# windows application).
The main purpose for doing this is becuase the service will be running on 2 different machine & will be accessing different shared folders on different servers. So in order to avoid hard coding the network share I intend to use a mapped network drive.
Following the code in Service:
public static extern int WNetGetConnection(string strLocalName, StringBuilder remoteName, ref int remoteNameLength);
private void GetValues(string FilePath)
StringBuilder remoteName = new StringBuilder();
int remoteNameLength = 300;
remoteName.Capacity = remoteNameLength;
FileInfo fi=new FileInfo(FilePath);
string folder =(fi.DirectoryName);
string remoteDrive =drive.Substring(0,2);
string strDrive = remoteDrive;
int status = WNetGetConnection(strDrive, remoteName, ref remoteNameLength); --> Returning 2250 here
string UNCPath = (remoteName.ToString());
string remotefolders = folder.Split(':');
string remotefolderpath = (remotefolders).ToString();
if (UNCPath.Trim().Length > 0)
files = Directory.GetFiles(UNCPath + remotefolderpath);
files = Directory.GetFiles(folder); --> Getting Exception here ie., "Could not find a part of the path"
Please let me know how we can resolve this.
Many thanks in advance
Sep 27, 2012 10:25 PM|oak_silver|LINK
Check this thread and see if it may help