0
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.

1
  • 1
    Friend we are not here to fix your silly problems. BTW colon (:) is not valid for file names. Commented Jan 1, 2011 at 8:28

2 Answers 2

3

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.
Sign up to request clarification or add additional context in comments.

1 Comment

@ Pradeep Thanks i got it because BTW colon (:) is not valid for file names.
2

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);

2 Comments

What needs to be included to Use the Path as class
@jagdeep, the Path class is defined in the System.IO namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.