Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using my namespace copyfile with a network path

Posted on 2006-06-14
6
Medium Priority
?
461 Views
Last Modified: 2008-01-09
I am trying to make this work:

my.computer.filesystem.copyfile("afile","\\server\share\afile")

but it won't work....   "the given path's format is not supported"


help!!!  :-)

VB 2005
0
Comment
Question by:Dan Flood
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
cmjwebservices earned 2000 total points
ID: 16909762
Why not use the folderbrowserdialog and do the following:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Sub ProcessDIR()
        Cursor.Current = Cursors.WaitCursor

        Dim strPath As String
        strPath = "C:\My Documents\MyFiles\" 'Change this to your default directory

        Dim oDir As New DirectoryInfo(strPath)
        Dim oFile As FileInfo
        Dim TotalFiles As Integer
        Dim FileCount As Integer
        Dim sourcePath As String
        Dim destinationPath As String

        'count the files in oDir
        TotalFiles += oDir.GetFiles.Length()

        'subtract one for the "thumbs.db" file
        If File.Exists(strPath & "\Thumbs.db") Then
            TotalFiles -= 1
        End If

        With FolderBrowserDialog1
            .Description = "Select Directory Path for the" & System.Environment.NewLine & "files to be copied to below:"
            .SelectedPath = "C:\"
        End With

        If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
            strFilePath = Me.FolderBrowserDialog1.SelectedPath 'Select the network drive here
        Else
            Return
        End If

        For Each oFile In oDir.GetFiles
            If Not (oFile.Name = "Thumbs.db") Then
                'set source and destination path and filename
                sourcePath = strPath & "\" & oFile.Name
                destinationPath = strFilePath.ToString & "\" & oFile.Name

                If File.Exists(destinationPath) Then
                    MessageBox.Show(System.Environment.NewLine & "File exists in target folder.  " & "Please rename or move the files to a different " & "location", "File Exists",                  MessageBoxButtons.OK)
                    lblFileCopy.Hide()
                    lblInfo.Show()
                    lblInfo.Text = "File Exists.  " & "Please choose a different location."
                    Return
                Else
                    'copy file
                    File.Copy(sourcePath, destinationPath)
                    FileCount += 1
                End If

                Application.DoEvents()
            End If
        Next

        Dim msg As String = "Processing Complete!" & System.Environment.NewLine & FileCount & " files copied."
        MessageBox.Show(msg, "Application Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Cursor.Current = Cursors.Default

        Me.Close()
    End Sub 'ProcessDIR

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 

Author Comment

by:Dan Flood
ID: 16911189
That looks liks it requires user intervention.  the point of this program is to move some files around for the user in the background... the only way they notice that the program is even running is a notify icon baloon tip saying 'copy complete'
0
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16912777
Ok, try:

Imports System.IO

'set source and destination path and filename
sourcePath = "afile"
destinationPath = "\\server\share\afile"

'copy file
Try
File.Copy(sourcePath, destinationPath)
FileCount += 1
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
0
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16912803
In the context of the code posted above of course (For Each..., etc.).  It should work as long as the path never changes or the network drive becomes unavailable.
0
 

Author Comment

by:Dan Flood
ID: 16928491
thanks but this command doesn't seem to work well with \\paths... i abandoned this in favour of a VB FTP client.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question