Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:
VB
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
Updated 13-Oct-12 8:26am
v3
Comments
Sergey Alexandrovich Kryukov 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 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.
[no name] 14-Oct-12 8:39am    
I think that "W is mapped to on online storage location" is your clue.
Sergey Alexandrovich Kryukov 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

I just discivered that VB2010 code will not let you write to a mapped drive letter.

Utter bullshit. 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.
 
Share this answer
 
Comments
KevinBrady57 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 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 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 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900