C\#파일 업로드 의 간단 한 실현

3457 단어 C#파일 업로드
분석
      이번 블 로 그 는 주로 파일 업로드 등 일련의 문 제 를 해결 하 는데 두 가지 측면 에서 논술 할 것 이다.즉,1G 이내 의 파일 과 1G 이상 의 파일 이다.
      1G 이내 의 파일 을 업로드 할 때 기본 적 인 세 가지 업로드 방법 을 사용 할 수 있 습 니 다.웹 컨트롤 FileUpload,html 컨트롤 HtmlInputFile 과 Html 요소로 Request.Files 를 통 해 업로드 할 수 있 습 니 다.
      1G 이상 의 큰 파일 에 대한 생각 은 다음 과 같 습 니 다.
           (1)프로 토 콜:http 프로 토 콜 또는 ftp 프로 토 콜 사용 가능
           (2)정지점 전송
           (3)플러그 인 사용
           (4)비 플러그 인 형식 구현
2.파일 크기 는[0,1G]범위 에 속 합 니 다.
     html 컨트롤 HtmlInputFile 업로드:
1.업로드 인터페이스

     2.전단 코드

<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
  <input type="file" id="file1" runat="server" /> 
  <asp:Button ID="btnUpLoad" runat="server" Text="  " OnClick="btnUpLoad_Click" /> 
  <asp:Label ID="Label1" runat="server" Text="" Style="color: Red"></asp:Label> 
 </div>
 </form>
</body>
</html>
3.백 엔 드 코드  

protected void btnUpLoad_Click(object sender, EventArgs e)
  {
   //string serverpath = Server.MapPath("~/ImageFile");
   if (file1.PostedFile.ContentLength > 0)
   {
    if (File.Exists(@"C:\Users\WJM\Desktop\FilesUpLoad\" + file1.PostedFile.FileName))
    {
     Label1.Text = "      ";
    }
    else
    {
     file1.PostedFile.SaveAs(@"C:\Users\WJM\Desktop\FilesUpLoad\" + file1.PostedFile.FileName);
     Label1.Text = "    !";
    }
    
   }
   else
   {
    Label1.Text = "    ";
   }
  }
4.프로필

<?xml version="1.0" encoding="utf-8"?>
<!--
        ASP.NET          ,   
 http://go.microsoft.com/fwlink/?LinkId=169433
 -->
<configuration>
 <system.web>
 <httpRuntime executionTimeout="36000" delayNotificationTimeout="36000" maxRequestLength="2147483647" targetFramework="4.5"></httpRuntime>
  <compilation debug="true" targetFramework="4.5" />
 <!--<httpRuntime targetFramework="4.5" />-->
 </system.web>
 <system.webServer>
 <security>
  <requestFiltering>
  <requestLimits maxAllowedContentLength="2147483648"/>
  </requestFiltering>
 </security>
 </system.webServer>
</configuration>
설명:프로필 에 익숙 하지 않 은 친 구 는 제 다른 블 로 그 를 참조 할 수 있 습 니 다ASP.NET Web.config
웹 컨트롤 FileUpload 구현 
      1.업로드 인터페이스
3.파일 크기 는[1G,10G]범위 에 속 합 니 다.
주석:미 완성,기대 하 세 요.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기