Access Network Location from C#

  • Thread starter Thread starter Sekhar
  • Start date Start date
S

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))
{ ... }
I even tried this:
string strFolder = "\\\\myothermac\\c$\\somefolder"
if (System.IO.Directory.Exists(strFolder))
{ ... }

The condition is always false (though the folder exists). 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 either.

I understand the ASPNET user will not know the mapings created by
other users. But how do I overcome this?

Could you please help me in solving this issue?

Thanks in advance.

Sekhar.
 
Sekhar, I just used the following code to make sure this works and had no
problem. Are you sure the folder really exists? Are you able to map the
drive and view the folder through Explorer?

static void Main(string[] args)
{
//string dir = @"z:\";
string dir = @"\\dc\img";
Console.WriteLine(System.IO.Directory.Exists(dir));
Console.Read();
}
 
Greg, I tried using "@" but it still wont work. Here is what I used:

string strFldr = @"\\CovAspn\Projects\Assets";
Response.Write("<h3>" + System.IO.Directory.Exists(strFldr));
Response.End();

I even tried with the IP address of the machine and also reaching the
directory from the root (C$). If I type in the address on the Windows
Explorer, I am able to reach the other machine. I can map the drive with
the address I specify in the string.

Could it be something to do with the ASPNET user permissions?

I even tried accessing the same machine's directory - which runs the IIS
with its own IP address ("\\192.168.0.2\C$\Projects\Assets" - instead of
direct location) it wont work. But, giving a direct location
("C:\Projects\Assets") works. I tried with and without the "@".

What am I doing wrong?

Thanks for helping me.

Sekhar.
 
Chandra Sekhar wrote:
|| Greg, I tried using "@" but it still wont work. Here is what I used:
||
|| string strFldr = @"\\CovAspn\Projects\Assets";
|| Response.Write("<h3>" + System.IO.Directory.Exists(strFldr));
|| Response.End();
||
|| I even tried with the IP address of the machine and also reaching the
|| directory from the root (C$). If I type in the address on the Windows
|| Explorer, I am able to reach the other machine. I can map the drive
|| with the address I specify in the string.
||
|| Could it be something to do with the ASPNET user permissions?
||
|| I even tried accessing the same machine's directory - which runs the
|| IIS with its own IP address ("\\192.168.0.2\C$\Projects\Assets" -
|| instead of direct location) it wont work. But, giving a direct
|| location ("C:\Projects\Assets") works. I tried with and without the
|| "@".
||
|| What am I doing wrong?
||
|| Thanks for helping me.
||
|| Sekhar.
||
||
|| Don't just participate in USENET...get rewarded for it!

"ASPNET" doesn't have network access privileges, try running asp.net with another identity or impersonate another user.

Willy.
 
Chandra, yes, that is your problem. Try Willy's suggestion and then go from
there.
 
Back
Top