100求救2005.NET作的大文件上传代码,各位大哥谁有给小弟一份!我从网上下载的好像都缺少类!希望有的给小弟一份!分数不够在加我800多分!只要好用立刻给分!快点阿

解决方案 »

  1.   

    http://community.csdn.net/Expert/TopicView3.asp?id=5118124
      

  2.   

    完整代码列表
    WebForm1.aspx<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CSharpUpload.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
      <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name=vs_defaultClientScript content="JavaScript">
        <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" enctype="multipart/form-data" runat="server">
    <INPUT type=file id=File1 name=File1 runat="server" >
    <br>
    <input type="submit" id="Submit1" value="Upload" runat="server" NAME="Submit1">
    </form>
      </body>
    </HTML>

    WebForm1.aspx.csusing System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace CSharpUpload
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    // 
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    // 
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregionprivate void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
    {
    string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
    string SaveLocation = Server.MapPath("Data") + "\\" +  fn;
    try
    {
    File1.PostedFile.SaveAs(SaveLocation);
    Response.Write("The file has been uploaded.");
    }
    catch ( Exception ex )
    {
    Response.Write("Error: " + ex.Message);
    }
    }
    else
    {
    Response.Write("Please select a file to upload.");
    }
    }
    }
    }
      

  3.   

    备注在这:http://support.microsoft.com/kb/323246
    参考:
    http://www.codeproject.com/aspnet/fileupload.asp
    http://www.c-sharpcorner.com/UploadFile/munnamax/FileUploader02102006073548AM/FileUploader.aspx?ArticleID=c6caab38-acc1-40c6-a5ef-c2ad639bcecb
      

  4.   

    可做成自定义控件
    http://www.15seconds.com/issue/010504.htm
      

  5.   

    1、Windows Server 2003中的IIS 6.0默认设置是特别严格和安全的,最大只能传送 204800个字节,我们需要修改,以允许从IE中上传更大的附件。解决办法是:
      在“服务”里停止IIS admin service 服务。找到Windows\System32\inesrv\下的metabase.xml文件,用记事本打开,找到 ASPMaxRequestEntityAllowed 把它修改为需要的值如102400000(附件大小为100MB)。启动IIS admin service服务。2、改变了web.config中的 maxRequestLength="你的容量" 
    3、前台代码略,估计有个上传按钮吧,我暂且就认为是 Button1吧
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string clintFileName, FileExt, nFileName;
    int i;
    if (File1.PostedFile!=null)
    {
    clintFileName = File1.PostedFile.FileName;
    //取得文件名(抱括路径)里最后一个"."的索引 
    i = clintFileName.LastIndexOf(".");
    //取得文件扩展名 
    FileExt = clintFileName.Substring(i);
    //这里自动根据日期和文件大小不同为文件命名,确保文件名不重复 
    nFileName = DateTime.Now.DayOfYear.ToString() + File1.PostedFile.ContentLength.ToString();

    //保存文件到你所要的目录,这里是IIS根目录下的UDfiles目录.你可以改变. 
    //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替 
    File1.PostedFile.SaveAs(Server.MapPath("UDfiles/" + nFileName + FileExt)) ;
    //得到这个文件的相关属性:文件名,文件类型,文件大小  }
    }
    测试成功
      

  6.   

    记得在页面中加一个控件哦 protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    我的代码中有File1就是那个控件 设置为 runat=server
      

  7.   

    汗你給的也不是完整得!我一看就知道了重要得是沒有什麽類!所以我照著你得做了也實現不了!I LA SAO
      

  8.   

    --------------页面部分相信你知道怎么做,我不想再贴一大版----------------
    <form id="Form1" method="post" runat="server">
        <asp:Button id="Button1"  runat="server" Text="Button"></asp:Button>
        <INPUT type="file" runat="server" id="File1">
    </form>
    ----------------------------UploadPage.aspx完---------------------------
    sing System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace WebApp
    {
    /// <summary>
    /// test 的摘要说明。
    /// </summary>

        public class upload : System.Web.UI.Page
        {
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    private void Page_Load(object sender, System.EventArgs e)
    {
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string clintFileName, FileExt, nFileName;
    int i;
        if (File1.PostedFile!=null)
        {
    clintFileName = File1.PostedFile.FileName;
    i = clintFileName.LastIndexOf(".");
    FileExt = clintFileName.Substring(i);
    nFileName = DateTime.Now.DayOfYear.ToString() + File1.PostedFile.ContentLength.ToString();
    File1.PostedFile.SaveAs(Server.MapPath("UDfiles/" + nFileName + FileExt)) ;     }
    }
        }
    }
    -------------------------UploadPage.cs部分也完------------------------------
      

  9.   

    上穿大文件! 有很多方法! 上面都是 把文件装入内存,这样不好!不信 你长传 3G的电影看看, 不死才怪!要用byte[], 分段上传! 才是正道!!!!!!
      

  10.   

    同意 zhangzengping(张增平)说的:
    特别是经常要上传,客户多了,服务器的负担更重
      

  11.   

    我之前弄过这方面的,不过是用SunriseUpload,你可以试试看
      

  12.   

    你好我正好也在做这功能.....测试成功...如果你需要的话留下你的EMAIL我发你....
      

  13.   

    http://www.qjedu.net/Article_Print.asp?ArticleID=786
      

  14.   

    You can use the FileUpload class.
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx
      

  15.   

    不要用VS自带的上传,它的最大限制为4M。现在有很多第三方控件,可以到google或百度找找,可以传大文件文件。
      

  16.   

    webconfig里面加上这一句:
    <httpRuntime maxRequestLength="500000"> 
    </httpRuntime>
      

  17.   

    http://blog.joycode.com/dotey/archive/2005/06/12/53557.aspx
    带DEMO和全部源码。
      

  18.   

    oolongTea(江山留胜迹,我辈复登临。),还有其他各位,这哪里是上传大文件啊?
      

  19.   

    用httpmodule来实现,http可以上传2g