fileupload控件导致服务器错误

时间:2012-07-16 07:18:29

标签: c# asp.net http file-upload

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.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)
{
    String fn = FileUpload1.FileName;
    string fp = Server.MapPath("images");
    if (fp.EndsWith("\\") == false)
    {
        fp = fp + "\\";
    }
    fp = fp + fn;
    FileUpload1.PostedFile.SaveAs(fp);
}
}

运行此代码时,我收到以下错误:

     HTTP错误400 - 错误请求。
  版本信息:    ASP.NET Development Server 10.0.0.0

1 个答案:

答案 0 :(得分:0)

如果images文件夹位于您网站的根目录,则路径应为此

string fp = Server.MapPath(~"/images");

并且还尝试在几天前在另一个brwose bcz上运行该网站我看到了同样的问题但是当他在不同的浏览上运行代码时它工作正常。

请参阅以下帖子 HTTP Error 400 - Bad Request due to FileUpload control in vb.net

相关问题