Solved

using my namespace copyfile with a network path

Posted on 2006-06-14
6
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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 …

751 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