?
Solved

using my namespace copyfile with a network path

Posted on 2006-06-14
6
Medium Priority
?
460 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 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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