由于水平有限,项目比较着急,没时间研究了,想求完整的上传文件代码!
谢谢了!

解决方案 »

  1.   

    http://blog.csdn.net/du9232/archive/2004/09/05/95349.aspx
      

  2.   

    .aspx页面加个
    HtmlInputFile控件,id为file1;
    .aspx.cs文件里
    file1.PostedFile.SaveAs(filename);
      

  3.   

    测试通过:
    System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
    try
    {
    for(int fileCount = 0;fileCount<files.Count;fileCount++)
    {
    //定义访问客户端上传文件的对象
    System.Web.HttpPostedFile postedFile = files[fileCount];
    // postedFile.SaveAs(Server.MapPath(System.IO.Path.GetExtension(postedFile.FileName)));
    //这里我自动根据日期为文件命名,确保文件名不重复
    string newFileName=System.DateTime.Now.ToString();
    newFileName=newFileName.Replace(":","");
    newFileName=newFileName.Replace("-","");
    newFileName=newFileName.Replace(" ","");
    newFileName+=System.IO.Path.GetExtension(postedFile.FileName); postedFile.SaveAs(Server.MapPath(@"../root/"+newFileName)); }
    }
    catch(Exception ex)
    {
    Response.Write(" <font color='Red' size='2'>'"+ ex.Message +"' </font>;");
    }