asp.net2.0 上传大容量文件第三方控件radupload

1.web.config  中的<system.web>加入:
 <httpHandlers>
    <add verb="*" path="Telerik.RadUploadProgressHandler.aspx" type="Telerik.WebControls.RadUploadProgressHandler, RadUpload.Net2" />
 </httpHandlers>
 <httpModules>
      <add name="RadUploadModule" type="Telerik.WebControls.RadUploadHttpModule, RadUpload.Net2" />
 </httpModules>

2.引用并声明使用

页面中:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="RadUpload.Net2" Namespace="Telerik.WebControls" TagPrefix="radU" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <radU:RadProgressManager ID="RadProgressManager1" runat="server" />
        &nbsp;<br />
        <input id="file1" runat="server" class="uploadBox" name="file1" type="file" /><br />
        <radU:RadProgressArea ID="RadProgressArea1" runat="server">
        </radU:RadProgressArea>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
    </form>
</body>
</html>

 

后置代码:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.WebControls;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        //生成GUID
        Guid id = System.Guid.NewGuid();
    
        foreach (UploadedFile up in RadUploadContext.Current.UploadedFiles)
        {
            string fileName = up.GetName();
            int index = fileName.LastIndexOf(".");
            string type = fileName.Substring(index);

            up.SaveAs(Server.MapPath("~/upload")+"\\" + id.ToString() + type, true);
        }
    }
}

 



3.文件大小的控制,如果太大会出现页面报错。
web.config  中的<system.web>加入 
<httpRuntime maxRequestLength="2040000" executionTimeout="9000"/>

你可能感兴趣的:(asp.net)