using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.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));
}
}
异常详细信息:
System.Web.HttpException: ~/img//1/1/2011 1:47:52 PMWinter.jpg
不是有效的虚拟路径。
答案 0 :(得分:3)
我有三种可能性。
:
不是Windows系统上文件名中的有效字符。~/img//1/1/
不存在。答案 1 :(得分:2)
试试这样:
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);