Reputation: 2491
I'm trying to develop a website with File upload and download option using vb.net and asp.net with Visual Studio 2008. Can anyone help me about how can I provide the facility of uploading a file into the server and then a download link will be available for the common users to download the file from the server. Thanks in advance.
Upvotes: 2
Views: 24110
Reputation: 1
Dim FileToCopy As String
FileToCopy = "F:\fd_demo_limits.swf"
Dim filenameTest = System.IO.Path.GetFileName(FileToCopy)
Dim path As String = "E:\"
Dim filename As String = "communicate.png"
Dim file_ As New System.IO.FileInfo(path + filename)
Dim file_ContentLength As String = "900000" ' check file Length file_.Length = 833740
If (file_.Length > file_ContentLength) Then
MsgBox("file length is large")
Exit Sub
End If
Dim allow_send_pic() As String = {".jpg", ".png", ".gif", "ico", ".png"}
Dim Extension As String = System.IO.Path.GetExtension(filename)
If Array.IndexOf(allow_send_pic, Extension.ToLower()) = -1 Then
MsgBox("File extension not valid")
Exit Sub
End If
If System.IO.File.Exists(FileToCopy) = True Then
While (System.IO.File.Exists(path + filename))
filename = "Copy of " + filename
End While
System.IO.File.Copy(FileToCopy, path + filename)
MsgBox("File Copied")
End If
Upvotes: -1
Reputation: 26376
You can use asp:FileUpload
control to upload file to your server, a location with permission to write file
It's as simple as putting the control in your .aspx
file
<asp:FileUpload runat="server" ID="MyFileUpload" />
Codebehind
If (MyFileUpload.HasFile) Then
MyFileUpload.SaveAs('the full path to directory ' & filename)
End If
You can store the file description in database with their path, retrieve this on your page and display to user
You can also browse your directory and list the files on your page
Upvotes: 1
Reputation: 303
Use FileUpLoad control. Here is a sample for uploading (in c#) : http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx
Upvotes: 2