Pickle
Pickle

Reputation: 1124

Accessing a hidden share programmatically in VB.net

I have a simple method to move a folder to a new directory

        Dim firstshare As String = "\\myshare\users\" & frmDeparture.txtUsername.Text
        Dim destination As String = "\\secondshare\userarchives$\" & frmDeparture.txtUsername.Text

        Try
            If Directory.Exists(firstshare) Then
                Directory.Move(firstshare, destination)
                MsgBox("Folder moved from \\firstshare\users")
            End If
        Catch ex As Exception
            MsgBox("Error finding folder")
        End Try

This works fine if I set "destination" as a path like "\path\whatever", but if it's a hidden path (with the $) it doesn't work. Is there something special I have to do in order to access a hidden share programatically?

Upvotes: 4

Views: 409

Answers (1)

Abdusalam Ben Haj
Abdusalam Ben Haj

Reputation: 5433

You are most likely trying to move a directory from one volume/partition to another, and you are getting this error :

Source and destination path must have identical roots. Move will not work across volumes

An explanation of why this is not possible is found Here. The only way you could move directories across different volumes is to create a new directory in the destination volume and copy the files from the source. You could then delete the original files if you wish.

Upvotes: 1

Related Questions