You must Sign In to post a response.
- Category: ASP.NET
- #7638331. 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.
Direction is important than speed
- #763834Hi 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
- #763835User 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.
Direction is important than speed
- #763840Showing 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]
- #763849Hai 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)
- #763891Hi 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)
' CHECK IF ANY FILE HAS BEEN SELECTED.
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") & _
Dim objDir As New DirectoryInfo(Server.MapPath("\\\\Destinationpath\testing"))
Dim objFI As FileInfo() = _
Path.GetExtension(hpf.FileName), "") & ".*")
If objFI.Length > 0 Then
' CHECK IF FILE WITH SAME NAME EXISTS (IGNORING THE EXTENTIONS).
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
' SAVE THE FILE IN A FOLDER.
hpf.SaveAs(Server.MapPath("\\Destinationpath\testing") & _
iUploadedCnt = iUploadedCnt + 1
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."
lblUploadStatus.Text = "No files selected."