Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows VB.NET file
I just discovered that VB2010 code will not let you write to a mapped drive letter.
 
For example if "W" is mapped to some location, the following will not work:
My.Computer.FileSystem.CopyFile("C:\TEST1.TXT", "W:\TEST1.TXT", True)
So, the question is, is there a method to get the absolute path for a mapped drive letter?
Posted 12-Oct-12 6:19am
Edited 13-Oct-12 8:26am
v3
Comments
Sergey Alexandrovich Kryukov at 12-Oct-12 13:18pm
   
I cannot believe that. Mapped volume is still a file system volume. I would not ever use VB.NET-specific things. How about BCL?
Try System.IO.File.Copy. Better? if not, it could be permission -- run application as administrator to check up. Anyway, you would see it in an exception.
--SA
KevinBrady57 at 12-Oct-12 13:55pm
   
I tried using System.IO.File.Copy(src, dst, True). Below is the exact code fragment that I was running:
 
Dim src As String = "C:\test\contactor.xls"
Dim dst As String = "M:\test\contactor.xls"
 
Try
System.IO.File.Copy(src, dst, True)
 
Catch ex As Exception
 
MessageBox.Show("An error occurred while attempting to copy the file" & vbCrLf & _
"The following error was thrown:" & vbCrLf & ex.Message)
End Try
 
The error message that is thron says "Could not find part of the path 'M:\test\contactor.xls"
 
I ran this from within the Visual Studio environment in debug mode. My Visual Studion environment is set-up to "Run as Administrator". My OS is Windows 7.
Wes Aday at 14-Oct-12 8:39am
   
I think that "W is mapped to on online storage location" is your clue.
Sergey Alexandrovich Kryukov at 19-Nov-12 17:42pm
   
Why would you answer your own question? It might be OK, but why your even accept it formally?! This is the real abuse.
Consider I warned you.
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I just discivered that VB2010 code will not let you write to a mapped drive letter.
 
Utter bullsh*t. Yes it will. The problem is in your code or the account you're using doesn't have create/write permissions to the path the drive letter is mapped to.
  Permalink  
Comments
KevinBrady57 at 13-Oct-12 14:24pm
   
There is not a problem in the code and I do have permission to write to the location. I can manually copy the file from the source to the destination in Windows Explorer or from the command propmpt. Also, I can copy a file if I use the absolute pathname to the destination. It just does not work when I use the drive letter.
Dave Kreskowiak at 13-Oct-12 15:25pm
   
Well, I can tell you that it works because I write tools that do this all the time.
Any mapped drive letter or UNC path can be used.
Dave Kreskowiak at 13-Oct-12 15:27pm
   
What won't work is if the source file or, if the desitination file exists, is locked by another process.
Dave Kreskowiak at 13-Oct-12 15:30pm
   
Oh, BTW, you never said what the exception ir that you get, so it's kind of difficult to tell you where to look.
KevinBrady57 at 13-Oct-12 15:44pm
   
In the response to Sergey I did. The exception that gets thrown is "Could not find part of the path".
 
The file is not locked and does not exist at the destination. As I said, I can successfully do it manually in WE or from the command prompt. I just can't do it from within the program.
Dave Kreskowiak at 13-Oct-12 18:42pm
   
The problem is described by the error message itself. For the destination filepath, the CopyFile method will NOT create any folders specified in the path, but only the file itself. Either the filepath you're giving in the source has a directory specified in it that doesn't exist or one or more folders in the destination path doesn't exist.
 
The fact that one of these paths is a mapped drive has nothing to do with it.
KevinBrady57 at 13-Oct-12 22:59pm
   
See below solution.
Dave Kreskowiak at 14-Oct-12 1:12am
   
That could mean anything. You can't map a drive to an FTP or HTTP address so that's out. Well, not using something built into Windows anyway.
 
Wes Aday at 14-Oct-12 8:39am
   
Crap meant to post that another place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100