1
if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("C:\\Users\\Vinay\\Documents\\Visual Studio 2010\\WebSites\\Onlinedoctorsportal\\vini" + 
                     FileUpload1.FileName);
                Label10.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label10.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label10.Text = "You have not specified a file.";
        }
           //Stream obj = FileUpload1.FileContent;
           //Session["file"] = obj;
           //Response.Redirect("Form3.aspx");
        }
}

what i want is to save the uploaded file to a folder named vini but it is showing the file but not saving it to the specified folder as shown please help

1
  • Post exception stack trace if any. Please verify the handler of Button is attached or not. Commented Sep 24, 2011 at 7:47

3 Answers 3

5

Firstly you need to escape your string literal that points to the directory

You can do this by adding an @ before the string, or by putting double backslashes.

FileUpload1.SaveAs(@"C:\Users\Vinay\Documents\Visual Studio 2010\WebSites\Onlinedoctorsportal\vini" + FileUpload1.FileName);

OR

FileUpload1.SaveAs("C:\\Users\\Vinay\\Documents\\Visual Studio 2010\\WebSites\\Onlinedoctorsportal\\vini" + FileUpload1.FileName);

Secondly, check that the user that your ASP.NET application pool process is running under has permissions to write to the specified folder.

A quick check to see if this is the problem is to impersonate your local admin account in your web.config file.

You can do this by configuring the impersonate tag as follows:

<identity impersonate="true"
      userName="domain\user" 
      password="password" />
Sign up to request clarification or add additional context in comments.

1 Comment

i have added two back slashes as you mentioned it doesnt seem to be working still
0

This is your answer Try it....

This is Button click event Code -

  protected void Button1_Click(object sender, EventArgs e)
    {
        if (fu1.HasFile)
        {
            String filePath = "~/PDF-Files/" + fu1.FileName;
            fu1.SaveAs(MapPath(filePath));
        }

    }

I this will solve your problem.

1 Comment

Could you explain a little more how it will solve the problem ? Just saying it works isn't helping much per se.
0
    string x = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\"+FileUpload1.PostedFile.FileName;
    System.Drawing.Image image = System.Drawing.Image.FromFile(x);
    string newPath = FileUpload1.FileName;
    image.Save(Server.MapPath(newPath))    ;
    Image1.ImageUrl = "~//" +  newPath ;
    Image1.DataBind();

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.