How to get filenames from shared network directory?

  • Thread starter Thread starter Goran Djuranovic
  • Start date Start date
G

Goran Djuranovic

Hi All,
The following code works fine in VB.NET (Windows app and Web app projects) when converted to VB.
It also works fine in C#, BUT only in Windows app project. All tested applications contain only this code on loading of the application (form).

Why does it not work in C# Web app project? Could this be a bug? I am using VS.NET 2003 EA

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("\\\\MyServer\\MyFolder\\MySubFolder1\\MySubFolder2\\MySubFolder3\\MySubFolder4\\");
System.IO.FileInfo[] fi = new System.IO.FileInfo[500];
fi = di.GetFiles();
foreach (System.IO.FileInfo f in fi)
{
Response.Write(f.FullName + "<br>");
// Console.WriteLine(f.FullName);
}

Goran Djuranovic
 
Hello, Goran!

GD> Why does it not work in C# Web app project? Could this be a bug? I am
GD> using VS.NET 2003 EA

GD> System.IO.DirectoryInfo di = new
GD> System.IO.DirectoryInfo("\\\\MyServer\\MyFolder\\MySubFolder1\\MySubFol
GD> der2\\MySubFolder3\\MySubFolder4\\");
GD> System.IO.FileInfo[] fi = new System.IO.FileInfo[500];
GD> fi = di.GetFiles();
GD> foreach (System.IO.FileInfo f in fi)
GD> {
GD> Response.Write(f.FullName + "<br>");
GD> // Console.WriteLine(f.FullName);
GD> }

No, it is not a bug, its all about security.

When your code executes in the web app context you work under ASP.NET account, which may not have access to network share.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hi Vadym,
Thanks for your response.

So, are you saying that security is different in C# than VB?
I am asking this because the same code works on ASP.NET application written
in VB.NET. Read my previous post again.

Goran
 
Hello, Goran!

GD> So, are you saying that security is different in C# than VB?
GD> I am asking this because the same code works on ASP.NET application
GD> written in VB.NET. Read my previous post again.

Can you post VB version of code, and define how the code written in C# is not working, is there any exception being thrown or smth else?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
You are running as the ASP.NET account so you need to have permissions
to do that.
 
Back
Top