上传大文件首先要修改web.config文件,否则上传报错。在web.config添加如下配置maxRequestLength表示能上传的最大文件值,单位是KB,requestLengthDiskThreshold表示超过多少KB之后的文件缓存到文件系统,不缓存在内存,以减轻内存负担。requestLengthDiskThreshold必须小于maxRequestLength

<configuration>
<system.web>    
<httpRuntime maxRequestLength ="1048576" requestLengthDiskThreshold ="100"/>
</system.web>
</configuration>

 

上传页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormLargeFile.aspx.cs" Inherits="WebApplication1.WebFormLargeFile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type ="text/css" >
        .fileList
        {
            margin-bottom :5px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID ="lblFile" runat ="server"  AssociatedControlID ="upFile" Text ="World Document:"></asp:Label>
        <asp:FileUpload ID ="upFile" runat ="server"  />&nbsp;
        <asp:Button ID ="btnAdd" runat ="server" onclick="btnAdd_Click" Text ="上传" />
        <hr />
        <asp:Repeater ID ="rptFiles" runat ="server" DataSourceID ="srcFiles" >
            <HeaderTemplate >
                <ul class ="fileList">
            </HeaderTemplate>
            <ItemTemplate >
            <li>
                <asp:HyperLink ID ="lnkFile" runat ="server" Text ='<%#Eval("FileName") %>' NavigateUrl ='<%#Eval("Id","~/FileHandlerLarge.ashx?Id={0}") %>'></asp:HyperLink>
            </li>
            </ItemTemplate>
            <FooterTemplate >
            </ul>
            </FooterTemplate>
        </asp:Repeater>
    </div>
    <asp:SqlDataSource ID="srcFiles" runat="server" 
        ConnectionString="Data Source=localhost;Initial Catalog=test;Integrated Security=True"  ProviderName ="System.Data.SqlClient" 
        SelectCommand="SELECT * FROM [Files]"></asp:SqlDataSource>
    </form>
</body>
</html>
View Code

相关文章:

  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案