.NETGURU
Accessing a Network Drive with Directory Object
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngbeta' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Robert Lair (VIP)
I have the following code which steps through a directory and adds each file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt" however,
if I want to access a network drive, such as "\\machine\c$" I get an "Access
Denied to Path" error message. I know that I can get to the path however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir = new Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr = dt.NewRow();

File f = (File) d;

dr[0] = f.FullName;
dr[1] = f.Name;
dr[2] = f.Length;
dr[3] = f.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

Reply to this message...
 
    
Charlie Bass
My suspicions is that it is a permissions error. Are you getting to it
directly as you or through your application?

Best,
Charlie

------------------------------------------------
2001 Web DevCon Denver, CO
June 12-15, 2001 http://www.webdevcon.com

[Original message clipped]

Reply to this message...
 
    
Scott Worley
Hmm, I have only accessed server side directories via ADSI, so would suggest
using it for this kind of operation, I suspect you have already done this
method, but thats all I can think of for the moment, will have to play on
this subject later on

scott worley

----- Original Message -----
From: "Robert Lair" <Click here to reveal e-mail address>
To: "aspngbeta" <Click here to reveal e-mail address>
Sent: Monday, April 30, 2001 3:10 PM
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

> I have the following code which steps through a directory and adds each
file
[Original message clipped]

Reply to this message...
 
    
Tim Doke
Have you tried mapping it out as a drive letter? If that isn't the problem,
perhaps it is a problem with your netbios over tcp/ip connection; that can
be modified in the advanced button under the WINS tab under tcp/ip in
network connections. I had a similar problem a while back, I got around it
by mapping the network as a drive letter.

----- Original Message -----
From: "Charlie Bass" <Click here to reveal e-mail address>
To: "aspngbeta" <Click here to reveal e-mail address>
Sent: Monday, April 30, 2001 2:16 PM
Subject: [aspngbeta] RE: Accessing a Network Drive with Directory Object

[Original message clipped]

Reply to this message...
 
    
DOUGLAS LUBEY
You might need 4 slashes \\\\machine

Some programming apps require this..
Macromedia Authorware

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 2:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt" however,
if I want to access a network drive, such as "\\machine\c$" I get an "Access
Denied to Path" error message. I know that I can get to the path however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt &# n;ew DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir &# n;ew Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr &# d;t.NewRow();

File f &# (;File) d;

dr[0] &# f;.FullName;
dr[1] &# f;.Name;
dr[2] &# f;.Length;
dr[3] &# f;.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

| [aspngbeta] member Click here to reveal e-mail address &# Y;OUR ID
| http://www.asplists.com/asplists/aspngbeta.asp &# J;OIN/QUIT
Reply to this message...
 
    
Mike Peschka
Keep in mind, too, that when you do anything through ASP (or ASP.NET)
code, it is being done as IUSR_machinename unless you've explicitly
logged in to the web site as someone else. It is possible that your
normal Windows account has access to the share, but the IUSR account
doesn't.

Mike Peschka

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 3:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each
file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt"
however,
if I want to access a network drive, such as "\\machine\c$" I get an
"Access
Denied to Path" error message. I know that I can get to the path
however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt =3D new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir =3D new Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr =3D dt.NewRow();

File f =3D (File) d;

dr[0] =3D f.FullName;
dr[1] =3D f.Name;
dr[2] =3D f.Length;
dr[3] =3D f.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

| [aspngbeta] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT

Reply to this message...
 
    
Brian G. Vallelunga
I believe I asked this same question a while back and the answer is "it
can't be done." The reasoning for this was a permissions error, but
there was no workable solution available at the time. I don't know if
this is a limitation of the .net framework or what, but after a lot of
researching, I could find no answer to the problem. I believe there
might be a knowledge base article that deals with this on MS's site, so
you may want to start there. I had no luck finding a solution, but if
you find a solution, please post it here.

-Brian

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 12:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each
file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt"
however,
if I want to access a network drive, such as "\\machine\c$" I get an
"Access
Denied to Path" error message. I know that I can get to the path
however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt =3D new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir =3D new Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr =3D dt.NewRow();

File f =3D (File) d;

dr[0] =3D f.FullName;
dr[1] =3D f.Name;
dr[2] =3D f.Length;
dr[3] =3D f.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

| [aspngbeta] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT

Reply to this message...
 
    
Juan T. Llibre (VIP)
This was well documented for ASP,
and should behave the same way for ASP.NET,
since it's a permissions problem.

Basically, when you access a dir/file on a network share,
it's your MACHINE which is accessing and the user
account doing the accessing is IUSR_computername.

Resolution is creating a user account on the computer on which
the network share resides and assigning the proper access
permissions to that account. This account MUST be named
with the EXACT name AND password which the anonymous
account has in the box hosting the web server ( and ASP.NET ).

Some database operations run under the SYSTEM account.
Those operations will fail with database files on the network share.

But directory listings and other operations on text/xml/html files,
like parse/copy/modify/delete, will work.

regards,

Juan T. Llibre
Microsoft MVP [IIS/ASP]
ASP.Net En EspaƱol : http://207.176.17.140/
==================================

----- Original Message -----
From: "Brian G. Vallelunga" <Click here to reveal e-mail address>
To: "aspngbeta" <Click here to reveal e-mail address>
Sent: Monday, April 30, 2001 8:45 PM
Subject: [aspngbeta] RE: Accessing a Network Drive with Directory Object

I believe I asked this same question a while back and the answer is "it
can't be done." The reasoning for this was a permissions error, but
there was no workable solution available at the time. I don't know if
this is a limitation of the .net framework or what, but after a lot of
researching, I could find no answer to the problem. I believe there
might be a knowledge base article that deals with this on MS's site, so
you may want to start there. I had no luck finding a solution, but if
you find a solution, please post it here.

-Brian

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 12:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each
file in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt"
however, if I want to access a network drive, such as "\\machine\c$"
I get an "Access Denied to Path" error message. I know that I can get
to the path however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir = new Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr = dt.NewRow();

File f = (File) d;

dr[0] = f.FullName;
dr[1] = f.Name;
dr[2] = f.Length;
dr[3] = f.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

Reply to this message...
 
    
Brian G. Vallelunga
I believe I asked this same question a while back and the answer is "it
can't be done." The reasoning for this was a permissions error, but
there was no workable solution available at the time. I don't know if
this is a limitation of the .net framework or what, but after a lot of
researching, I could find no answer to the problem. I believe there
might be a knowledge base article that deals with this on MS's site, so
you may want to start there. I had no luck finding a solution, but if
you find a solution, please post it here.

-Brian

-----Original Message-----
From: Mike Peschka [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 4:08 PM
To: aspngbeta
Subject: [aspngbeta] RE: Accessing a Network Drive with Directory Object

Keep in mind, too, that when you do anything through ASP (or ASP.NET)
code, it is being done as IUSR_machinename unless you've explicitly
logged in to the web site as someone else. It is possible that your
normal Windows account has access to the share, but the IUSR account
doesn't.

Mike Peschka

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 3:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each
file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt"
however,
if I want to access a network drive, such as "\\machine\c$" I get an
"Access
Denied to Path" error message. I know that I can get to the path
however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt =3D new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir =3D new Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr =3D dt.NewRow();

File f =3D (File) d;

dr[0] =3D f.FullName;
dr[1] =3D f.Name;
dr[2] =3D f.Length;
dr[3] =3D f.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

| [aspngbeta] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT

| [aspngbeta] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT

Reply to this message...
 
    
mark Mullai
For your attention.

If you are usoing winNT you will notice the difference when you assign a directory tu a website in IIS

Local drives are assigned differently than the network drive (2 different choices) That means the IIS treat them differently. Can you get a clue from this.

I think if the directory is a sub directory of the web dir assigned in IIS it will work. Others have to be accessed via a virtual dir.

Create a virtual dir in IIS for the net work drive you want to acces and then access the virtual dir from ASP.net.

This should work.

I am sure there is a similar procedure in Appache also!

Hope this helps

Mark

"Brian G. Vallelunga" <Click here to reveal e-mail address> wrote:
I believe I asked this same question a while back and the answer is "it
can't be done." The reasoning for this was a permissions error, but
there was no workable solution available at the time. I don't know if
this is a limitation of the .net framework or what, but after a lot of
researching, I could find no answer to the problem. I believe there
might be a knowledge base article that deals with this on MS's site, so
you may want to start there. I had no luck finding a solution, but if
you find a solution, please post it here.

-Brian

-----Original Message-----
From: Mike Peschka [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 4:08 PM
To: aspngbeta
Subject: [aspngbeta] RE: Accessing a Network Drive with Directory Object

Keep in mind, too, that when you do anything through ASP (or ASP.NET)
code, it is being done as IUSR_machinename unless you've explicitly
logged in to the web site as someone else. It is possible that your
normal Windows account has access to the share, but the IUSR account
doesn't.

Mike Peschka

-----Original Message-----
From: Robert Lair [mailto:Click here to reveal e-mail address]
Sent: Monday, April 30, 2001 3:11 PM
To: aspngbeta
Subject: [aspngbeta] Accessing a Network Drive with Directory Object

I have the following code which steps through a directory and adds each
file
in the directory to a DataTable. This works all and great for instances
where the directory is set to a local directory such as "C:\winnt"
however,
if I want to access a network drive, such as "\\machine\c$" I get an
"Access
Denied to Path" error message. I know that I can get to the path
however.
Anyone have any ideas?

Thanks

----- code start ---------------

DataTable dt &# n;ew DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("FileNameUrl", typeof(string)));
dt.Columns.Add(new DataColumn("FileFriendlyName", typeof(string)));
dt.Columns.Add(new DataColumn("Size", typeof(string)));
dt.Columns.Add(new DataColumn("Modified", typeof(DateTime)));

if (directory.Length > 0) {

Directory dir &# n;ew Directory(directory);

foreach (FileSystemEntry d in dir.GetFileSystemEntries ()) {

if (d is File) {

dr &# d;t.NewRow();

File f &# (;File) d;

dr[0] &# f;.FullName;
dr[1] &# f;.Name;
dr[2] &# f;.Length;
dr[3] &# f;.LastWriteTime;

dt.Rows.Add(dr);
}
}
}

----- code end ---------------

| [aspngbeta] member Click here to reveal e-mail address &# Y;OUR ID
| http://www.asplists.com/asplists/aspngbeta.asp &# J;OIN/QUIT

| [aspngbeta] member Click here to reveal e-mail address &# Y;OUR ID
| http://www.asplists.com/asplists/aspngbeta.asp &# J;OIN/QUIT

| [aspngbeta] member Click here to reveal e-mail address &# Y;OUR ID
| http://www.asplists.com/asplists/aspngbeta.asp &# J;OIN/QUIT

---------------------------------
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
Reply to this message...
 
 
System.Data.DataColumn
System.Data.DataRow
System.Data.DataTable
System.DateTime
System.IO.Directory




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification