0

I'm trying to download a file from shared drive to desktop but it keeps throwing an error that its not a virtual path. Here is my code:

if (Directory.Exists(Server.MapPath("M://SharedDrive//" +  username)))
{
   File.Copy("M://SharedDrive//" + username, "C:\\Documents and Settings\\user\\Desktop\\" + username, true);
}
yoozer8
  • 7,361
  • 7
  • 58
  • 93
DAK
  • 1,395
  • 4
  • 22
  • 35
  • It's not a valid path either... walk through your code above in the debugger and see what is actually being sent as the first parameter to `File.Copy`. – M.Babcock Mar 07 '12 at 20:54

2 Answers2

3

Are you doing this from in an ASP.NET application? (I'm guessing since you are using Server.MapPath). Then you have two problems:

  1. IIS runs in the service session, which has no access to the users' mapped drives such as M:. IIS can only access physical drives, or UNC paths (the latter requires security to be set up correctly).
  2. IIS has no access to a user's desktop.

Please explain a bit more detailed what you are trying to achieve if we are to be able to help.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
0

If you copy file to/from network location, you should login or impersonate user.

Check these;

arunes
  • 3,464
  • 2
  • 21
  • 31