[VB / ASP.NET] FileUpload控件,档案上传

[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 扩展名解析弱点!!

 

 

 

 

 

转载于:https://www.cnblogs.com/mis2000lab/archive/2010/10/15/FileUpload_VB_Csharp.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值