Solved

using my namespace copyfile with a network path

Posted on 2006-06-14
6
452 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:jakyll
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
cmjwebservices earned 500 total points
Comment Utility
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:jakyll
Comment Utility
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
Comment Utility
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
Comment Utility
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:jakyll
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now