locked
FileInfo.CopyTo() error RRS feed

  • Question

  • User696431485 posted

    Hi


    I'm trying to copy some files from my local machine onto the server.

    I use this code -


     Dim DocumentsSourcePath As String = String.Format("{0}{1}", System.Configuration.ConfigurationManager.AppSettings("DocumentsPath").ToString(), AppId)
     Dim dir As DirectoryInfo = New DirectoryInfo(Server.MapPath(DocumentsSourcePath))
     Dim DocumentsSourcePath As String = String.Format("{0}{1}", System.Configuration.ConfigurationManager.AppSettings("DocumentsPath").ToString(), AppId)
     Dim dir As DirectoryInfo = New DirectoryInfo(Server.MapPath(DocumentsSourcePath))
     Dim f As FileInfo
    
     If Directory.Exists(DocumentsSourcePath) Then
                    For Each f In dir.GetFiles()
                        f.CopyTo(VirtualPath, True)
                    Next
     End If
    

    VirtualPath is something like  \\remoteserver\folder1\folder2\folder3\
    DocumentsSourcePath is a folder in the root dir of the application.

    The error I get is --
    The filename, directory name, or volume label syntax is incorrect.
    The filename, directory name, or volume label syntax is incorrect.
    What am I doing wrong?




    Friday, September 10, 2010 11:20 AM

Answers

  • User696431485 posted

    Got it. 

    I was supplying the path in CopyTo() but not the Filename.

    it should've been something like this --

    file.CopyTo(String.Format("{0}\{1}", Path,  file.Name))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 10, 2010 2:46 PM

All replies

  • User-366246501 posted

    refer this link, you will get complete idea: -

    http://msdn.microsoft.com/en-us/library/aa328782%28VS.71%29.aspx

    Friday, September 10, 2010 2:10 PM
  • User696431485 posted

    Got it. 

    I was supplying the path in CopyTo() but not the Filename.

    it should've been something like this --

    file.CopyTo(String.Format("{0}\{1}", Path,  file.Name))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 10, 2010 2:46 PM