0

I have been working on an image/file uploader that stores an image to a virtual directory with MapPath or to a database. I have been using if statements for the button click event to check the file and attempt to save but I have not been successful.

protected void Button1_Click(object sender, EventArgs e)
{

    if (FileUpload1.HasFile)
    {

        string extension = Path.GetExtension(FileUpload1.FileName);


        if (extension == ".jpg" || extension == ".gif" || extension == ".png" || extension == ".bmp")
        {

            FileUpload1.SaveAs(Server.MapPath("../photos/" + FileUpload1.FileName));


            string imagePath = "/photos/" + FileUpload1.FileName;
1
  • 1
    Please tell us what you have tried so far, your code snippet and error if any. Commented Nov 30, 2010 at 7:06

1 Answer 1

2

please try this

FileUpload1.SaveAs(Server.MapPath(@"~\photos\" + FileUpload1.FileName));
Sign up to request clarification or add additional context in comments.

Comments

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.