You must Sign In to post a response.
  • Category: ASP.NET

    How to Upload files from source to destination folder in

    Hi I am designing web application using vb what my aim is I have aspx page in that I created Upload Document when I click Button popup window will display where I have choose file and Destination file in choose file I have to select file and drop the file in destination folder here choose file is local path and destination folder is destination path after upload files then click OK after click Ok whatever files I dropped to destination should display in aspx page where I have Upload Document button. Can anyone help me to do this. Thanks in advance.
  • #763833
    1. Create Simple page. Have a file upload control and submit button .(handle the popup div in your code according to your requirment.

    2. File upload button will handle the file selection. Once you select the file. You can click button submit. You can get the select file details in the server side.

    3. In the server side event you can upload the file where you want.

    4. For selecting the destination you should have access permission in the server. If you are going to upload your file inside our website. You can select destination folder using server.path + your folder name. If you want to store that file outside of your web application make sure you access.

    By Nathan
    Direction is important than speed

  • #763834
    Hi Nathan for choose file I can choose file upload but for destination folder how can I choose file upload because it will select the file not to drop the file I guess what is the best option for that

  • #763835
    User can not upload/access the entire directories of the server.

    So you can give them list of folders in the drop down.
    Use can select any one of the destination folder.

    By Nathan
    Direction is important than speed

  • #763840
    Showing a destination folder structure in your web browser is bit tricky, cause application don't know the exact path of destination folder, alternatively you can bind your server folder structure in treeview and can show to user, later on he can select any file from tree view and you can upload file on that location.
    for upload purpose you can use file upload control and with the help of PostedFile.SaveAs() method you can post the file to application

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763849
    Hai Nagendra,
    You don't need to choose the file for destination but rather you need to choose the folder where you want to drop the file and when clicking OK, you need to get the file name from the chosen file name and keep the same by SaveAs and use the same file name to the destination folder.
    Also do you want to open the file which got saved in the destination folder? if so then you need to use File.Open to open the file to the browser window.
    By this way, you can achieve your functionality.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763891
    Hi when I execute the below code it shows the path is not virtual so I check the path before my dest path it shows "E:\destinationpath\testing" instead of \\destinationpath\testing from where its taking E:\ can anyone please suggest how to remove from this code what do I do changes in the code.

    Protected Sub Upload_Files(sender As Object, e As EventArgs)

    If fileUpload.HasFile Then
    Dim iUploadedCnt As Integer = 0
    Dim iFailedCnt As Integer = 0
    Dim hfc As HttpFileCollection = Request.Files

    lblFileList.Text = "Select <b>" & hfc.Count & "</b> file(s)"

    If hfc.Count <= 10 Then ' 10 FILES RESTRICTION.
    For i As Integer = 0 To hfc.Count - 1
    Dim hpf As HttpPostedFile = hfc(i)
    If hpf.ContentLength > 0 Then
    If Not File.Exists(Server.MapPath("\\Destinationpath\testing") & _
    Path.GetFileName(hpf.FileName)) Then

    Dim objDir As New DirectoryInfo(Server.MapPath("\\\\Destinationpath\testing"))
    Dim objFI As FileInfo() = _
    objDir.GetFiles(Replace(Path.GetFileName(hpf.FileName), _
    Path.GetExtension(hpf.FileName), "") & ".*")
    If objFI.Length > 0 Then
    For Each file As FileInfo In objFI
    If Replace(objFI(0).Name, Path.GetExtension(objFI(0).Name), "") = _
    Path.GetExtension(hpf.FileName), "") Then

    iFailedCnt = iFailedCnt + 1
    Exit For
    End If
    hpf.SaveAs(Server.MapPath("\\Destinationpath\testing") & _
    iUploadedCnt = iUploadedCnt + 1
    End If
    End If
    End If
    Next i
    lblUploadStatus.Text = "<b>" & iUploadedCnt & "</b> file(s) Uploaded."
    lblFailedStatus.Text = "<b>" & iFailedCnt & _
    "</b> duplicate file(s) could not be uploaded."
    lblUploadStatus.Text = "Max. 10 files allowed."
    End If
    lblUploadStatus.Text = "No files selected."
    End If
    End Sub

  • Sign In to post your comments