[VB / ASP.NET] FileUpload控件,档案上传
http://www.dotblogs.com.tw/mis2000lab/archive/2008/04/24/3455.aspx
以前写ASP要靠第三协力厂商提供的控件才能上传,现在有了「FileUpload」控件,变得很简单。
底下这两个网址,MS提供的范例非常精彩且实用!照抄都能学到东西~棒!
http://msdn2.microsoft.com/zh-tw/library/system.web.ui.webcontrols.fileupload.aspx
http://msdn2.microsoft.com/zh-tw/library/ms227669.aspx
========================================================
这是最基本的用法,上面的URL有其它变形,很实用!
Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Specify the path on the serverto
' save the uploaded file to.
Dim savePath As String = "c:\temp\uploads\"
' Before attempting to performoperations
' on the file, verify that theFileUpload control contains a file.
If (FileUpload1.HasFile)Then
' Get the name ofthe file to upload.
Dim fileNameAs String = FileUpload1.FileName
' Append the nameof the file to upload to the path.
savePath += fileName
' Call the SaveAsmethod to save the
' uploaded fileto the specified path.
' This example doesnot perform all
' the necessaryerror checking.
' If a file withthe same name
' already existsin the specified path,
' the uploaded fileoverwrites it.
FileUpload1.SaveAs(savePath)
' Notify the userof the name the file was saved under.
UploadStatusLabel.Text = "Your file was saved as " & fileName
Else
' Notify the userthat a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload."
End If
End Sub
这是我写的一个小范例,请笑纳----
此范例已经收录在本书第十八章
此范例已经收录在书籍里面出版了。请看: ASP.NET案例精编 / 清华大学出版社
[C#]FileUpload控件「批次上传 / 多档案同时上传」的范例
http://www.dotblogs.com.tw/mis2000lab/archive/2008/10/14/fileupload_csharp_081014.aspx
[VB]FileUpload控件「批次上传 / 多档案同时上传」的范例 (VB语法)
http://www.dotblogs.com.tw/mis2000lab/archive/2008/05/14/3986.aspx
此范例已经收录在书籍里面出版了。请看: ASP.NET案例精编 / 清华大学出版社
[习题]FileUpload上传档案时,若发现上传的目录不存在,能否自动新建此目录?
http://www.dotblogs.com.tw/mis2000lab/archive/2010/05/27/fileupload_io_create_dir_20100527.aspx
请注意档案上传的风险,请看:
检 查上传档案扩展名真的有效吗?分析 IIS6 扩展名解析弱点!!
....................................................................................................寄信给我 mis2000lab (at)雅虎.com.台湾 ........
ASP.NET案例精编(清华大学出版社 / 作者MIS2000Lab)
http://www.china-pub.com/46063
2009/5/15上市
市场价 :¥59.80 RMB(人民幣)