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]범위 에 속 합 니 다.
주석:미 완성,기대 하 세 요.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.