473,809 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Directory.GetFi les() / DirectoryInfo.G etFiles() on a remote server

Hi,

I've been trying to use Directory.GetFi les() and also
DirectoryInfo.G etFiles() 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 23047
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="tr ue" userName="domai n\MyUserName">
password="MyPas sword"/>

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@discuss ions.microsoft. comwrote in message
news:CF******** *************** ***********@mic rosoft.com...
Hi,

I've been trying to use Directory.GetFi les() and also
DirectoryInfo.G etFiles() 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().N ame + "<br />");
string[] files = Directory.GetFi les("\\\\ecompo nentdc\\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\danie l.correa
\\ecomponentdc\ Temp\New Text Document.txt

-No web.config parameters
E-COMPONENT\danie l.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="tr ue" userName="domai n\MyUserName">
password="MyPas sword"/>

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@discuss ions.microsoft. comwrote in message
news:CF******** *************** ***********@mic rosoft.com...
Hi,

I've been trying to use Directory.GetFi les() and also
DirectoryInfo.G etFiles() 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
1804
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 DSL connection Does anybody know how I can speed things? One suggestion was to get the remote server to only bring back creation time,filename,file length and directoryname of all
1
383
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 file in Directory.GetFiles("pic1.*") file.Delete() but will need to use a recursive algorythm to get all its subdirectories
4
3714
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 Directory.GetFileSystemEntries(path), but I would like to know how to put this together, knowing which entry is a Subdirectory and which entry is a file, and make a recursive list of the Directory structure below a specific path - - -
2
4028
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 fDirSize = 0 ; if(!System.IO.Directory.Exists(DirectoryPath)) return fDirSize;
1
9917
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 some custom actions to change the permissions on the install directory and its sub folders/files so that they can be accessed correctly via a network share later on. We would want to add Everyone full access to the install directory (its
3
1363
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 when i upload it on the server. I run it, it won't show the images. The code is given below. Private Function Showpic() As Integer Dim sDirName As String Dim lst As ArrayList = New ArrayList()
2
6686
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 it process all files within subdirectories as well? Thanks -- Alex
1
13544
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 reference vsjlib Library in .net component. .NET Classes used : Imports System.IO Imports java.io Imports java.util Imports java.util.zip
5
7303
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 that virtual directory ? For my default project directory, i can get list of the specific files like that; *******************
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.