Not able to copy files from source path to destination path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tempalli
    New Member
    • Sep 2007
    • 31

    Not able to copy files from source path to destination path

    Dear Team,

    I am using the below code where as i am not able to copy the source files to destination path. Source path is the local system D:drive and destination is Server system. When i am connecting to server system folowing with IP from local system nothing is happening but if i do the same from server system following with the same IP it works fine. kindly suggest what to do iam using Visual studio 2005.

    Code as below.......
    Code:
    Imports System
    Imports System.IO
    
       Dim strConnString As [String] = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()
            Dim con As New SqlConnection(strConnString)
            con.Open()
    
            Dim myDirInfo As DirectoryInfo
            Dim arrFileInfo As Array
            Dim myFileInfo As FileInfo
    
            Dim sourcepath = "D:\PDF_Attachments"
            Dim DestinationPath = Server.MapPath("~/MyFiles/To_be_Send/")
    
            If (Directory.Exists(sourcepath)) Then
    
                myDirInfo = New DirectoryInfo("D:\PDF_Attachments\")
                arrFileInfo = myDirInfo.GetFiles("*.Pdf")
    
                For Each fName As String In Directory.GetFiles(sourcepath)
                    If File.Exists(fName) Then
                        Dim dFile As String = String.Empty
                        dFile = Path.GetFileName(fName)
                        Dim dFilePath As String = String.Empty
                        dFilePath = DestinationPath + dFile
                        File.Delete(DestinationPath + dFile)
                        File.Copy(fName, dFilePath, True)
                    End If
                Next
    
                For Each myFileInfo In arrFileInfo
    
                    Dim command As New SqlCommand("Import_Attachments_Reminder", con)
                    Command.CommandType = CommandType.StoredProcedure
                    Try
                        Command.Parameters.AddWithValue("@Claim_No", myFileInfo.Name)
                        Command.ExecuteNonQuery()
    
                    Catch ex As Exception
                        Throw ex
                    Finally
                    End Try
    
                Next myFileInfo
    
                con.Close()
                con.Dispose()
    
            Else
                Directory.CreateDirectory("D:/PDF_Attachments")
            End If
    
            Response.Redirect("Reminder_Mails.aspx")
        End Sub
    Last edited by Frinavale; Jan 18 '12, 04:20 PM. Reason: Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    When you say "local" what do you mean?

    I'm not clear on what you are trying to accomplish.
    Are you trying to copy files from the web application's "MyFiles" to a location on the server ("D:/PDF_Attachments ")?

    Or are you trying to copy files from the user's computer to a server? If so, you're going about this the wrong way.

    -Frinny

    Comment

    • Tempalli
      New Member
      • Sep 2007
      • 31

      #3
      Dear Frinny,

      Thanks for your reply.

      I am trying to copy files from the user's computer having folder "D:PDF_Attachme nts to Server having folder("~/MyFiles/To_be_Send/").

      Dim sourcepath = "D:\PDF_Attachm ents"
      Dim DestinationPath = Server.MapPath( "~/MyFiles/To_be_Send/")

      Please help me with complete code.

      Regards,
      Tempalli

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        That isn't going to work because the user's computer and the server are in two different places. The user has to upload the files to the server. They have the whole internet in between them.

        Your server code cannot access the client's computer. It runs on a server and returns HTML to the user's browser. The browser displays the HTML to the user and the user interacts with the web application using buttons and other controls which submit requests for the server to do something.



        Check out the FileUpload control.

        -Frinny

        Comment

        • Tempalli
          New Member
          • Sep 2007
          • 31

          #5
          Dear Frinny,

          Uploading each and every file through file upload control its difficult to the user for uploading each and every file.

          Its there any other option so that the user copies all the files (*.pdf) from a perticular folder of client system to server automatically. if so please provide me the code.

          Regards,
          T.S.Anantharama m
          Last edited by Tempalli; Jan 23 '12, 03:09 PM. Reason: review

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            I've never done it but you could create an application that the user downloads and runs which does that for them. In that application you could even use something like FTP to transfer the files to the server if you want :)

            -Frinny

            Comment

            • danp129
              Recognized Expert Contributor
              • Jul 2006
              • 323

              #7
              Here are some free options:



              Here are some commercial options:


              Comment

              • PsychoCoder
                Recognized Expert Contributor
                • Jul 2010
                • 465

                #8
                You could nalso check out Uploadify for a complete jQuery upload system for multiple files at once.

                Comment

                Working...