Accessing Shared Folder through C#

  • Thread starter Thread starter Chandra Sekhar
  • Start date Start date
C

Chandra Sekhar

I want to access a shared folder of a different machine (Mapped to my
server) say E:\ (which is actually \\myothermac\c$\somefolder") from C#.

If I use
string strFolder = "E:\myNewFolder";
if (System.IO.Directory.Exists(strFolder))
{ ... }
it always says the directory doesn't exist. I thought it might be
something to do with security and I enabled everyone to have full access
on the other machine. But it didnt help.

I know ASPNET user will not know the share created by any other user on
the machine, but how do you suggest me do it?

I even tried this:
string strFolder = "\\\\MyOtherMachine\\c$\\myNewFolder";
if (System.IO.Directory.Exists(strFolder))
{ ... }


Could you please help me in solving this issue?

Thanks in advance.

Sekhar.
 
C$ is a system share, so it's treated differently than the normal shares.
You should probably make a different share (maybe one that doesn't start at
the root directory) and use that one. Maybe that'll help.

Chris
 
I have a program which searches our network.
This runs off a fileshare path (well a database of root
paths in my case) in the form of \\server\sharename

I do it like this...

private bool CheckPath(string sPath)
{
DirectoryInfo objDir = new DirectoryInfo(sPath);

//Check if its real!
if(objDir.Exists)
{
//find all directories
DirectoryInfo[] objSubDirs = objDir.GetDirectories();

//recurse each directory
for(int i = 0;i<objSubDirs.Length; i++)
{
CheckPath(objSubDirs.FullName);
}

//Do more stuff here
}
 
Back
Top