开发者

System.Web.HttpException Error

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using S开发者_C百科ystem.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Expt : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void Bttnadd_Click(object sender, EventArgs e)
    {
       FileUpload1.SaveAs(MapPath("~/img//"+DateTime.Now.ToString()+FileUpload1.FileName));

    }
}

Exception Details: System.Web.HttpException: ~/img//1/1/2011 1:47:52 PMWinter.jpg is not a valid virtual path.


Three possibilities jump out at me.

  • : isn't a valid character in filenames on Windows systems.
  • Directory ~/img//1/1/ doesn't exist.
  • It doesn't like the double forward slash.


Try like this:

var path = MapPath("~/img");
var datePart = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss-");
var filename = Path.Combine(path, datePart + FileUpload1.FileName);
FileUpload1.SaveAs(filename);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜