locked
Copy files from one folder to another RRS feed

  • Question

  • User-71413573 posted

    hi 

    I am able to create a folder but is not able to copy files from the source to the newly created folder. Is there something that i missed out? Thanks

     

    Dim sitename As String = "~/site/" & txtUsername.Text

    Directory.CreateDirectory(Server.MapPath(sitename))
               

    Try
                    Dim f() As String = Directory.GetFiles("/site/source/")
                    For i As Integer = 0 To UBound(f)
                        File.Copy(f(i), Server.MapPath(sitename) & "\" & (f(i)))
                    Next
                Catch ex As Exception
    End Try

     

    Wednesday, February 10, 2010 8:52 PM

Answers

  • User1006193418 posted

    Hi,

    You lost Server.MapPath() method when you get the file information from the directory.

    Dim f() As String = Directory.GetFiles(Server.MapPath("/site/source/"))

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 16, 2010 3:35 PM

All replies

  • User-2129951835 posted

    the Directory.GetFiles is only get file name,not include the path, so you f(i) is missing the source path.

    Wednesday, February 10, 2010 9:47 PM
  • User1006193418 posted

    Hi,

    You lost Server.MapPath() method when you get the file information from the directory.

    Dim f() As String = Directory.GetFiles(Server.MapPath("/site/source/"))

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 16, 2010 3:35 PM