setting Username&password while using DirectoryInfo()

siddharth_jain_1_at_rediffmail.com
Date: 12/13/04


Date: 13 Dec 2004 13:23:05 -0800

Hello

I am trying to get a list of shared files and subdirectories in a
particular folder on a server.
For this I am using DirectoryInfo in the following way.

DirectoryInfo folder = new
DirectoryInfo("\\\\server_name\\shared_folder_name");

 FileInfo[] fiArr = folder.GetFiles();
DirectoryInfo[] diArr = folder.GetDirectories();

foreach (FileInfo fri in fiArr)
Console.WriteLine(fri.Name);
foreach (DirectoryInfo di in diArr)
Console.WriteLine(di.Name);

Now, this works fine when the server doesnt have a password set on the
guest account.
In other cases, it gives the following runtime exception:

Unhandled Exception: System.IO.IOException: Logon failure: unknown user
name or bad password.

at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.Directory.InternalGetFileDirectoryNames(..blah blah blah)

If I know the password to access the shares of the server, how do I set
them in my program?
I would be grateful to anyone who could guide me towards solving this
problem.

Thanks



Relevant Pages

  • Re: Web service privileges
    ... for this purpose is the SOAP adapter. ... Run it as a domain user with admin privileges on the remote server. ... // Create a new DirectoryInfo object ... Call a remote service that runs as a privileged user ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: setting Username&password while using DirectoryInfo()
    ... Another option is to create a network session from the command ... > particular folder on a server. ... > For this I am using DirectoryInfo in the following way. ... > at System.IO.Directory.InternalGetFileDirectoryNames(..blah blah blah) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File Access via the Web
    ... The other server "IS" on a domain. ... I tried using DirectoryInfo, even ... If you don't want to use the asp.net identity as outlined above, an alternative is to impersonate the user in your code before attempting to access the remote folder. ... Once you are using the correct credentials, either System.IO.Directory (static methods) or DirectoryInfo should be able to access the remote folder as @"\\server\folder". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File Access via the Web
    ... The other server "IS" on a domain. ...    The key is using adequate credentials. ... access the remote folder. ... or DirectoryInfo should be able to ...
    (microsoft.public.dotnet.languages.csharp)
  • CreateDirectory working inconsistantly from ASP.net
    ... I have a web page that is trying to create folders on a file server ... webserver the code works and is able to create the new folder. ... System.IO.__Error.WinIOError(Int32 errorCode, String str) ... DirectoryInfo di = Directory.CreateDirectory; ...
    (microsoft.public.dotnet.framework.aspnet.security)