Solved

using my namespace copyfile with a network path

Posted on 2006-06-14
6
453 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
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:jakyll
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:jakyll
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

14 Experts available now in Live!

Get 1:1 Help Now