473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Directory.GetFiles() / DirectoryInfo.GetFiles() on a remote server

Hi,

I've been trying to use Directory.GetFiles() and also
DirectoryInfo.GetFiles() to list files on a remote server using
"\\server_name\dir_name" like paths. It works fine on a test windows app, but
I get an access error message when the code is running on a asp.net app.

First I thought it was just a matter of credentials, so I started to use
windows authentication and impersonate the current user, but I still got the
same message.

Any thoughts? Is it possible to list files on a remote server when code is
running on an asp.net app?
Regards,
Daniel
Mar 22 '07 #1
2 22895
Are you sure the user you're impersonating has permission to that server and
file share?
To rule out credential issues once and for all I think you should try
impersonation using your user account since you know for sure that you have
access.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyUserName">
password="MyPassword"/>

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"Daniel Corrêa" <Daniel Corrêa@discussions.microsoft.comwrote in message
news:CF**********************************@microsof t.com...
Hi,

I've been trying to use Directory.GetFiles() and also
DirectoryInfo.GetFiles() to list files on a remote server using
"\\server_name\dir_name" like paths. It works fine on a test windows app,
but
I get an access error message when the code is running on a asp.net app.

First I thought it was just a matter of credentials, so I started to use
windows authentication and impersonate the current user, but I still got
the
same message.

Any thoughts? Is it possible to list files on a remote server when code is
running on an asp.net app?
Regards,
Daniel
Mar 22 '07 #2
Hi Steve,

Thanks for you help. A really strange thing happened. When I used the
userName and password parameters it worked fine. Then I removed these
parameters and logged in with the same user name and password. Although I
could see that the user was the same, it didn't work.

This is the test code I'm using:

Response.Write(WindowsIdentity.GetCurrent().Name + "<br />");
string[] files = Directory.GetFiles("\\\\ecomponentdc\\Temp");
if(files != null && files.Length 0)
foreach(string filePath in files)
Response.Write(filePath + "<br />");

And this is the result with and without the web.config parameters:

-With web.config parameters
E-COMPONENT\daniel.correa
\\ecomponentdc\Temp\New Text Document.txt

-No web.config parameters
E-COMPONENT\daniel.correa
Access to the path "\\ecomponentdc\Temp" is denied.

As you can see, both times the same user was impersonated, so why didn't it
work the second time? Could there be an IIS configuration, or could it be CAS
related? Any ideas?

Thanks again for your help,
Daniel


"Steve C. Orr [MCSD, MVP, CSM, ASP Inside" wrote:
Are you sure the user you're impersonating has permission to that server and
file share?
To rule out credential issues once and for all I think you should try
impersonation using your user account since you know for sure that you have
access.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyUserName">
password="MyPassword"/>

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"Daniel Corrêa" <Daniel Corrêa@discussions.microsoft.comwrote in message
news:CF**********************************@microsof t.com...
Hi,

I've been trying to use Directory.GetFiles() and also
DirectoryInfo.GetFiles() to list files on a remote server using
"\\server_name\dir_name" like paths. It works fine on a test windows app,
but
I get an access error message when the code is running on a asp.net app.

First I thought it was just a matter of credentials, so I started to use
windows authentication and impersonate the current user, but I still got
the
same message.

Any thoughts? Is it possible to list files on a remote server when code is
running on an asp.net app?
Regards,
Daniel
Mar 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dennis English | last post by:
Hi The following code came be very slow in getting creation time,filename,file length and directoryname for files in a subdirectory because it keeps checking each file sequentially in a slow...
1
by: Earl Teigrob | last post by:
Does someone have or know of an algorythm (method) that will delete all files under a give directory and its subdirectories based on a wildcard mask? I can use this for one directory for each...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
2
by: Raed Sawalha | last post by:
I have the following function to get the directory sizse, i wondering if there any better way to find directory size public static double GetDirectorySize(string DirectoryPath) { double...
1
by: Aek | last post by:
What is the best way to recursively change the permissions of the directory we are installing into? Is there a nice way to do this in C# ..NET? We are using an MSI installer and will need to add...
3
by: bijaysalotry | last post by:
I have to display image on webpage. Images are stored on some other directory of the webserver not in the project drive and directory. When I develop it, it is working on developers machine but...
2
by: Alex | last post by:
Hello, I'm creating a program to parse a directory and all files within that directory (including subdirectories), but 'directoryinfo' only parses the current directory. Is it possible to have...
1
by: sandhyabhavani | last post by:
This article is used to zip a file or directory using vb.net. The classes and method to zip a file is availale in java.io, java.util, java.util.zip class library.To import these you have to add a...
5
by: Ned White | last post by:
I have set up a virtual directory on ISS 6.0 to store the all .jpg and .swf files which i use in my project It is alias name is "OutSrc" Is it possible to acquire a list of files which exist in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.