2.分块上传就是利用post的方法,把数据分块上传,每块上传的数据量少,不会引起超时的问题。不说了,看代码吧。
3.用法
(1)修改web.config
1 <httpModules>
2 <add name="HttpUploadModule"
3 type="HttpModelApp.HttpUploadModule, HttpModelApp" />
4
5 </httpModules>
6 <httpRuntime
7 maxRequestLength="2000000"
8 executionTimeout="300"
9 />
(2)aspx2 <add name="HttpUploadModule"
3 type="HttpModelApp.HttpUploadModule, HttpModelApp" />
4
5 </httpModules>
6 <httpRuntime
7 maxRequestLength="2000000"
8 executionTimeout="300"
9 />
1 <form id="form1" runat="server" encType="multipart/form-data" method="post">
2 <div>
3 <INPUT id="firstFile" type="file" name="firstFile" runat="server"><br />
4 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" /><br />
5 <asp:Label ID="Label1" runat="server"></asp:Label></div>
6 </form>
(3)aspx.cs2 <div>
3 <INPUT id="firstFile" type="file" name="firstFile" runat="server"><br />
4 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" /><br />
5 <asp:Label ID="Label1" runat="server"></asp:Label></div>
6 </form>
1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 //要保存的位置
4 string strDesPath = "D:\\";
5 string strFileName = this.firstFile.PostedFile.FileName;
6 strFileName =strDesPath + strFileName.Substring(strFileName.LastIndexOf("\\"));
7 //
8 this.firstFile.PostedFile.SaveAs(strFileName);
9 this.Label1.Text = "文件保存到了:" + strFileName;
10 }
4.大文件上传的限制2 {
3 //要保存的位置
4 string strDesPath = "D:\\";
5 string strFileName = this.firstFile.PostedFile.FileName;
6 strFileName =strDesPath + strFileName.Substring(strFileName.LastIndexOf("\\"));
7 //
8 this.firstFile.PostedFile.SaveAs(strFileName);
9 this.Label1.Text = "文件保存到了:" + strFileName;
10 }
虽然可以上传大文件,但是这个大小也是有限制的,不能超过2G的大小。
有什么问题给我联系吧。
源代码下载:/Files/HeroBeast/HttpModelApp.rar