请各位帮忙!!!
      我要上传一个文件,结果成功后,那个文件老是为0字节,不明白了,请大侠帮忙,下面是代码
    string name = Server.MapPath("~/website/upload") + "\\" + FileUpload.FileName;
     FileUpload.PostedFile.SaveAs(name);
                                                                 在线等~~~~

解决方案 »

  1.   

    private void UploadFiles()
            {    ///获取上载文件的列表
         
                HttpFileCollection fileList = HttpContext.Current.Request.Files;
                ///定义显示的消息
                StringBuilder uploadMsg = new StringBuilder("上载的文件如下:" + "<br>");            try
                {    ///上载文件列表中的每一个文件
                    for (int i = 0;  i < fileList.Count; i++)
                    {    ///获取当前上载的文件
                        HttpPostedFile hPostedFile = fileList[i];
                        
                        ///获取上载文件的文件名称
                        string fileName = Path.GetFileName(hPostedFile.FileName);
                        if (fileName != null)
                        {    ///上载文件
                            hPostedFile.SaveAs(MapPath("../upload/") + fileName);
                            /////添加文件到数据库中
                            _flow_sub.flow_instance_id = this.flow_inst_id;
                            _flow_sub.sPath = "../upload/";
                            _flow_sub.sTitle = fileName;
                            this._flow_sub.Add();                        uploadMsg.Append("文件名称:" + fileName + "<br>");
                        }
                    }
                    ///显示上载文件的操作成功消息
                    StatusMsg.Text = uploadMsg.ToString();
                }
                catch (Exception ex)
                {
                    ///显示上载文件的操作失败消息
                    StatusMsg.Text = ex.Message;
                }
            }
      

  2.   

     //创建文件夹
    Directory.CreateDirectory(Server.MapPath(name ));
    //上传
    FileUpload1.SaveAs(Server.MapPath(("~/website/upload/" + FileUpload.FileName));
      

  3.   

    看看这个、、希望对你有帮助,其实很多错误都可以自己找出来的
    页面
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
      
      
      
    <!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" enctype="multipart/form-data">  
      
            <div>  
      
                 <input id="fileUp" name="File1" type="file" runat="server" />  
      
                <asp:Button ID="btnUpFile" runat="server" Text="上传" OnClick="btnUpFile_Click" />  
      
                <asp:Label ID="strState" runat="server" />  
      
                <img src="upfile/2.jpg" />  
      
                   
      
        </form>  
      
    </body>  
      
    </html>  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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" enctype="multipart/form-data">        <div>             <input id="fileUp" name="File1" type="file" runat="server" />            <asp:Button ID="btnUpFile" runat="server" Text="上传" OnClick="btnUpFile_Click" />            <asp:Label ID="strState" runat="server" />            <img src="upfile/2.jpg" />    </form></body></html>
    cs代码--view plaincopy to clipboardprint?
    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;   
      
      
      
    public partial class _Default:System.Web.UI.Page   
      
    {   
      
        protected void Page_Load(object sender,EventArgs e)   
      
        {   
      
      
      
        }   
      
        protected void btnUpFile_Click(object sender,EventArgs e)   
      
        {   
      
            String filepath = "",fileExtName = "",mFileName,mPath;   
      
      
      
            System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传信息<hr color=red>");   
      
      
      
            if(fileUp.PostedFile.FileName != "")   
      
            {   
      
                //取得文件路径   
      
                filepath = fileUp.PostedFile.FileName;   
      
                //取得文件扩展名   
      
                fileExtName = filepath.Substring(filepath.LastIndexOf(".") + 1);   
      
      
      
                //取得服务器上的相对路径   
      
                <FONT color=#ff0000>mPath = Server.MapPath("upfile/");   
    </FONT>   
                //取得文件名   
      
                <FONT color=#ff0000>mFileName = filepath.Substring(filepath.LastIndexOf("\\") + 1);   
    </FONT>   
      
      
                //取得上传文件的信息   
      
                strMsg.Append("上传文件类型:" + fileUp.PostedFile.ContentType.ToString() + "<br>");   
      
                strMsg.Append("客户端文件路径:" + fileUp.PostedFile.FileName + "<br>");   
      
                strMsg.Append("上传文件名:" + mFileName + "<br>");   
      
                strMsg.Append("扩展名:" + fileExtName);   
      
      
      
                //保存文件到指定目录   
      
                fileUp.PostedFile.SaveAs(mPath + mFileName);   
      
                strState.Text = strMsg.ToString();   
      
            }   
      
        }   
      
      

  4.   

    File1.PostedFile.ContentLength
    检查目录操作权限