[英]File Upload / download using vb.net
我正在尝试使用vb.net和asp.net在Visual Studio 2008中开发一个具有文件上载和下载选项的网站。有人可以帮助我如何提供将文件上载到服务器然后下载链接的功能吗?可供普通用户从服务器下载文件。 提前致谢。
您可以使用asp:FileUpload
控件将文件上传到服务器,该位置具有写文件权限
就像将控件放入您的.aspx
文件一样简单
<asp:FileUpload runat="server" ID="MyFileUpload" />
代码隐藏
If (MyFileUpload.HasFile) Then
MyFileUpload.SaveAs('the full path to directory ' & filename)
End If
您可以将文件描述及其路径存储在数据库中,在页面上检索该文件并显示给用户
您还可以浏览目录并在页面上列出文件
使用FileUpLoad控件。 这是一个上传示例(在c#中): http : //www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx
昏暗的FileToCopy作为字符串
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.