Reputation: 1634
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));
}
}
Exception Details:
System.Web.HttpException: ~/img//1/1/2011 1:47:52 PMWinter.jpg
is not a valid virtual path.
Upvotes: 0
Views: 553
Reputation: 1038720
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);
Upvotes: 2
Reputation: 27864
Three possibilities jump out at me.
:
isn't a valid character in filenames on Windows systems.~/img//1/1/
doesn't exist.Upvotes: 3