问题描述: 
    在本机上测试上传附件成功,但放到服务器上就总是出现“附件上传失败”提示。服务器环境为:windows server 2003,oracle 9i.
-------------------------------------
上传附件代码如下:
 //上传附件,限制大小为20M以内
    protected void btnsave_Click(object sender, EventArgs e)
    {
        Boolean fileOK = false;
        String path = Server.MapPath("~/wlgw/");
        if (this.dlCon.Items.Count > 0)
        {
            if (((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).HasFile)
            {
                String fileExtension = System.IO.Path.GetExtension(((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".jpeg", ".jpg",".txt", ".rar" ,".zip"};
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i]&&((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileContent.Length <= 1024*1024*20)
                    {
                       
                        fileOK = true;
                    }
                   
                }
            }
        }        if (fileOK)
        {
            try
            {
                ((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).PostedFile.SaveAs(path
                    + ((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName);
                ((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传成功!";            }
            catch (Exception ex)
            {
                ((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "上传失败!";
            }
        }
        else
        {
            ((Label)this.dlCon.Items[0].FindControl("Label1")).Text = "请检查文件格式和文件大小!";
        
        }
                //listbox接受FileUpload1传过来的文件名称
        ((ListBox)this.dlCon.Items[0].FindControl("lst")).Items.Insert(0,((FileUpload)this.dlCon.Items[0].FindControl("FileUpload1")).FileName);    }
-----------------------------------------
下载附件代码如下:
 protected void btnDownload_Click(object sender, EventArgs e)
    {
       
        string strFileUpladPath = Server.MapPath("~/wlgw/");
        ////从列表框中读取选择的文件
        string strFileName = ((ListBox)this.dlCon.Items[0].FindControl("lst")).SelectedValue;
        if (strFileName != null && strFileName !="")
        { ////组合成物理路径
            string strFilePhysicalPath = strFileUpladPath + strFileName;
            //调用另存为对话框
            FileDownload(strFilePhysicalPath);
        }
        else
        {
            Response.Write("<script language='JavaScript'>alert('请选择附件!');</script>");                   }
    }

解决方案 »

  1.   

    服务器能否允许上传20M的附件,问一下空间提供商俺不用这个上传控件,功能太少了,推荐一个给楼主
    CuteWebUI.AjaxUploader  
      

  2.   

    20M,先改一下web.config吧.加上这一句<system.web>
    <httpRuntime executionTimeout="36000" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false"/>
    </system.web>
    不行再去问空间提供商.
      

  3.   

     String path = Server.MapPath("~/wlgw/"); 我的路径是绝对路径,在服务器端源程序文件夹下我建了一个wlgw文件夹,用来保存附件,在数据库中我保存的是文件名称。
      

  4.   

    你保存上传数据的这个文件夹是否有IIS帐户写的权限?
      

  5.   

    我在此处将IIS中源程序文件夹中的"INTERNET 来宾"和“users ”用户权限的"写入"打上勾就可以上传图片了.