Working with files in network drives

I

igg

I'm developing a .net application and I need to save files in a network
drive. I need to create a subdirectory and I've tried this:

Directory.SetCurrentDirectory(Path);

Directory.CreateDirectory("folder1");

I've tried with values of 'Path' like "Z:\Dir", "\\remoteserver\Dir", ... (Z
the mapped unit and remoteserver the name of the remote machine) but seems
that the class Directory can't work with remote drives.

Any idea?

Thanks
 
P

Pete Davis

Is this a service app or a winform app? If it's a winform app, do you as a
user have permission to create directories on this network drive?

If it's a service app, you might need to provide access rights to that
account. I don't really know how that is done, though.

Pete
 
G

Guest

Hi igg,

Thank you for posting in the community!

Based on my understanding, you can use directory to access the local drive,
but when you access a network drive, it failed.

================================
I agree with Pete that this problem may due to security permission.

When you use your code, which exception expression it shows? Please use
try...catch to show the error message for us.

In MSDN you can see that Directory.SetCurrentDirectory need
FileIOPermissionAccess.Write permission, while Directory.CreateDirectory
needs FileIOPermissionAccess.Read and FileIOPermissionAccess.Write
permission.

You may check the permission for your network drive.

===============================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I

igg

To Pete Davis: is a web application (asp.net) so perhaps I would have to
configure the permissions of the aspnet account. I've tried it, but without
success yet.

To Jeffrey: the exception is System.IO.DirectoryNotFoundException. I have
the framework in spanish so the message is 'No se puede encontrar una parte
de la ruta de acceso "Z:/".'. It's more or less like ' A part of path "Z:/"
can't be found'

The path that I use is "Z:/Dir" (Z the drive mapped and Dir the remote
directory shared). When I change it with "C:/Dir" it works perfectly.

Thanks in advance
 
F

Felix Wang

Hi Igg,

As far as I know, mapped drives are user account specific. In other words,
if you configure a mapped drive with user A, and log on with user B, user B
is not able to use the mapped drive.

The key point here is that ASP.Net worker process runs under the account
ASPNET. As a result, the worker process knows nothing about drive "Z:" that
is configured with your current user account.

I would suggest that you still use the UNC path (e.g. \\server\share). You
need to configure carefully with the share permissions and NTFS permissions
on the remote server. I believe the following article will be useful to you:

ASP.NET Security
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/ht
ml/SecNetch08.asp

You may refer to the section "Accessing Network Resources" and "Accessing
Files on a UNC File Share".

I hope this helps.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top