asp.net 파일 업로드 다운로드 의 간단 한 실현

FileUpload 업로드 사용:

  
  
  
  
  1. protected void btnUpload_Click(object sender, EventArgs e)  
  2.         {  
  3.             if (FileUpload1.HasFile)  
  4.             {  
  5.                 /* */ 
  6.                 string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);  
  7.                 if (fileExt != ".doc" && fileExt != ".docx" && fileExt != ".wps")  
  8.                 {  
  9.                     lblMsg.Text = " ! :doc、docx wps";  
  10.                     return;  
  11.                 }  
  12.                 /* */ 
  13.                 if (FileUpload1.PostedFile.ContentLength > 100 * 1024)  
  14.                 {  
  15.                     lblMsg.Text = " 100KB";  
  16.                     return;  
  17.                 }  
  18.                 FileUpload1.SaveAs(Server.MapPath(" ") + FileUpload1.FileName);  
  19.                 lblMsg.Text = " !";  
  20.             }  
  21.             else 
  22.             {  
  23.                 lblMsg.Text = " ";  
  24.             }  
  25.         } 

파일 다운로드:

  
  
  
  
  1. protected void btnDownload_Click(object sender, EventArgs e)  
  2.         {  
  3.             string fileName = " . ";  
  4.             FileInfo fileInfo = new FileInfo(Server.MapPath(" ") + fileName);  
  5.             Response.ContentType = "application/octet-stream";  
  6.             Response.AddHeader("Content-Disposition""attachment;FileName=" + HttpUtility.UrlEncode(fileName));  
  7.             /* , , “ ” */ 
  8.             Response.AddHeader("Content-Length", fileInfo.Length.ToString());  
  9.             Response.WriteFile(Server.MapPath(" ") + fileName);  
  10.         } 

좋은 웹페이지 즐겨찾기