天天看點

上傳控件(input type="file")的用法

//判斷上傳的檔案是否為空

HttpPostedFile postFile = Request.Files["upfile"];

if (postFile == null || postFile.ContentLength < 0)

{

    //提示為空或者其他操作 

//如果是文本檔案,讀取其内容

Stream s = StreamCopyTo(postFile.InputStream);

StreamReader sr = new StreamReader(s, System.Text.Encoding.Default);

strCode = sr.ReadToEnd(); //strCode就是文本檔案中的内容

s.Close();