November 10,2005

[ASP.Net]檔案上傳的方法

if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
{
      string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
      string SaveLocation = Server.MapPath("Document") + "\\" +  fn;
      try
     {   
          File1.PostedFile.SaveAs(SaveLocation);
          Response.Write("The file has been uploaded.");
      }
      catch ( Exception exp )
      {
          Response.Write("Error: " + exp.Message);
      }
}
else
{
     Response.Write("Please select a file to upload.");
}

PS: ASP.NET 只允許將 4,096 KB(即 4 MB)以下的小檔案,較大文件有大文件的上傳方式


Posted by soboring at 樂多Roodo! │18:20 │回應(0)引用(0)筆記備忘
樂多分類:網路/3C 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/705684