2008-03-20 上傳文件不儲存,只show訊息 3179 0 ASP.NET 上傳文件不儲存,只show訊息 If Me.FileUpload1.PostedFile.InputStream.Length < 1 Then Me.Label1.Text = "請選擇文件" Return End If Dim filename As String = Me.FileUpload1.FileName If filename.ToLower().IndexOf(".txt") = -1 Then Me.Label1.Text = "請選擇文本文件" Return End If Dim filelen As Integer = Me.FileUpload1.PostedFile.ContentLength Dim input As Byte() = New Byte(filelen) {} Dim uploadstream As System.IO.Stream = Me.FileUpload1.PostedFile.InputStream uploadstream.Read(input, 0, filelen) uploadstream.Position = 0 Dim sr As System.IO.StreamReader = New System.IO.StreamReader(uploadstream, System.Text.Encoding.Default) Me.Label1.Text = "你上傳的文件內容是:<br/><br/>" & sr.ReadToEnd() sr.Close() uploadstream.Close() uploadstream = Nothing sr = Nothing ASP.NET 回首頁