[VB / ASP.NET] FileUpload控制項,檔案上傳

以前寫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





以前寫ASP要靠第三協力廠商提供的控制項才能上傳,現在有了「FileUpload」控制項,變得很簡單。

 
底下這兩個網址,MS提供的範例非常精彩且實用!照抄都能學到東西~棒!
http://msdn2.microsoft.com/zh-tw/library/system.web.ui.webcontrols.fileupload.aspx
 
======================================================== 
這是最基本的用法,上面的URL有其他變形,很實用!

  Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    ' Specify the path on the server to
    ' save the uploaded file to.
    Dim savePath As String = "c:\temp\uploads\"

    ' Before attempting to perform operations
    ' on the file, verify that the FileUpload
    ' control contains a file.
    If (FileUpload1.HasFile) Then
      ' Get the name of the file to upload.
      Dim fileName As String = FileUpload1.FileName

      ' Append the name of the file to upload to the path.
      savePath += fileName

      ' Call the SaveAs method to save the
      ' uploaded file to the specified path.
      ' This example does not perform all
      ' the necessary error checking.              
      ' If a file with the same name
      ' already exists in the specified path, 
      ' the uploaded file overwrites it.
      FileUpload1.SaveAs(savePath)

      ' Notify the user of the name the file
      ' was saved under.
      UploadStatusLabel.Text = "Your file was saved as " & fileName

    Else
      ' Notify the user that a file was not uploaded.
      UploadStatusLabel.Text = "You did not specify a file to upload."
    End If

  End Sub

 

  這是我寫的一個小範例,請笑納----FileUpload控制項「批次上傳 / 多檔案同時上傳」的範例

  此範例已經收錄在本書第十八章

 

 

請注意檔案上傳的風險,請看:

檢 查上傳檔案副檔名真的有效嗎?分析 IIS6 副檔名解析弱點!!

 

 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

線上課程教學,遠距教學 (Web Form 約51hr)  https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015

線上課程教學,遠距教學 (ASP.NET MVC 約75~88hr)  https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab

ASP.NET MVC線上課程 第一天 免費看 (5.5小時) 

寫信給我,不要私訊 --  mis2000lab (at) yahoo.com.台灣  或  school (at) mis2000lab.net


ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。 

................   facebook社團   https://www.facebook.com/mis2000lab   ......................

................  YouTube (ASP.NET) 線上教學影片  https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/

 

Blog文章 "附的範例" 無法下載,請看 這裡 ...... https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download

請看我們的「售後服務」範圍(嚴格認定)

...................................................................................................................................................... 

[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講

事先錄製好的影片,並非上課時側錄!   觀看影片時,有如我「一對一」跟您面對面講課

 

ASP.NET MVC 5 線上教學

         累積時數約 75~ 88小時...... 第一天(5.5小時)完整內容,"免費"讓您評估