Learner
Learner

Reputation: 1634

System.Web.HttpException Error

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

Answers (2)

Darin Dimitrov
Darin Dimitrov

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

David Yaw
David Yaw

Reputation: 27864

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.

Upvotes: 3

Related Questions