FileUpload元件-VB範例

使用「FileUpload」控制項範例如下:


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:\存放目錄\"

    ' 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

存取路徑還要開讀寫和修改的使用權限!

留言

熱門文章