Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading image is not working on server

Tags:

c#

asp.net

While uploading the file from local machine on to the server, it is showing me the

"Server Error in '/' Application.
Access to the path 'G://images\blog-image2.jpg' is denied."

Can someone help me out in this....Please. my c# code is this:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //Get Filename from fileupload control
    string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
    //Save images into Images folder
    fileuploadimages.SaveAs(Server.MapPath("~/images/" + filename));

    //Getting dbconnection from web.config connectionstring
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
    //Open the database connection
    con.Open();
    //Query to insert images path and name into database
    SqlCommand cmd = new SqlCommand("Insert into tblimgs(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
    //Passing parameters to query
    cmd.Parameters.AddWithValue("@ImageName", filename);
    cmd.Parameters.AddWithValue("@ImagePath", "~/images/" + filename);
    cmd.ExecuteNonQuery();
    //Close dbconnection
    con.Close();
    Response.Redirect("default.aspx");
}

what is wrong in this?

like image 807
Neil Avatar asked Jun 30 '14 14:06

Neil


1 Answers

You'll want to make sure the account you're using has access to that file path.

Also it would probably help to give access to that folder for the IIS user account (IUSR I believe).

like image 182
asven Avatar answered Oct 19 '22 22:10

asven