Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi coders i have an upload image page in which i have file up-loader control and one drop-down list. flow of my code
 
First user select file from the system using file up-loader and then select department from the drop-down list and click on submit button when user click on submit button image path save in the database and images save into the selected department folder.
 
protected void Page_Load(object sender, EventArgs e)
{
    AutoNumber();
}
public void AutoNumber()
{
    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT COUNT(Priority) as Tot FROM Images", con);
    SqlDataReader dr;
 
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        int i = Convert.ToInt32(dr["tot"]);
 
        if (i > 0)
        {
            int j = i + 1;
            lblPriority.Text = "0" + j.ToString();
        }
        else
        {
            lblPriority.Text = "1";
        }
 
    }
    con.Close();
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
 
    //con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebGallery"].ConnectionString;
    string DepartmentID = ddlDepartment.SelectedValue;
    string Description = tbImageName.Text.Trim();
    string Priority = lblPriority.Text.Trim();
 
    //Get Filename from fileupload control
    string imgName = fileuploadimages.FileName.ToString();
    //sets the image path if exist then store image in that place else create one
    string imgPath = "Images/Departments/" + "" + ddlDepartment.SelectedValue + "/";
    bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
    if (!IsExists)
        System.IO.Directory.CreateDirectory(Server.MapPath(imgPath));
    //then save it to the Folder
    fileuploadimages.SaveAs(Server.MapPath(imgPath + imgName));
    //Open the database connection
    con.Open();
    //Query to insert * into images into database
    SqlCommand cmd = new SqlCommand("insert into Images(ImageName, Description, Path, Priority,DepartmentID) values (@ImageName, @Description, @Path, @Priority,@DepartmentID)", con);
    //Passing parameters to query
    cmd.Parameters.AddWithValue("@ImageName", imgName);
    cmd.Parameters.AddWithValue("@Description", Description);
    cmd.Parameters.AddWithValue("@Path", imgPath + imgName);
    cmd.Parameters.AddWithValue("@Priority", lblPriority.Text);
    cmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
    cmd.ExecuteNonQuery();
    //Close dbconnection
    con.Close();
    tbImageName.Text = string.Empty;
}
}
 
Now what i want :
 
Now i want add one more drop-down list in which priority of images come from the database. when user browse image select department and select priority that image store image at that priority and image which is already at that image move by 1 and so on till the last image.
 
this is my related reference question their i did'nt get any solution so i thought to modify my question ask again i hope you don't mind guys
 

http://stackoverflow.com/questions/17209459/how-to-put-an-image-into-selected-postition-and-store-in-database/17210510?noredirect=1#comment24930508_17210510[^]
Posted 8-Jul-13 6:27am
Edited 8-Jul-13 6:29am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Finally i got my answer:
 
protected void btnSubmit_Click1(object sender, EventArgs e)
   {
       //con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebGallery"].ConnectionString;
       string DepartmentID = ddlDepartment.SelectedValue;
       string Description = tbImageName.Text.Trim();
       //string Priority = lblPriority.Text.Trim();
       string Priority = ddlPriority.SelectedValue;
       //Get Filename from fileupload control
       string imgName = fileuploadimages.FileName.ToString();
       //sets the image path if exist then store image in that place else create one
       string imgPath = "Images/Departments/" + "" + ddlDepartment.SelectedValue + "/";
       bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
       if (!IsExists)
           System.IO.Directory.CreateDirectory(Server.MapPath(imgPath));
       //then save it to the Folder
       fileuploadimages.SaveAs(Server.MapPath(imgPath + imgName));
       //Open the database connection
       con.Open();
       //Query to insert * into images into database

       SqlCommand cmd = new SqlCommand("Update Images set Priority=Priority+1 where Priority>='" + ddlPriority.SelectedValue + "'" + "Insert into Images(ImageName,Description,Path,Priority,DepartmentID) values(@ImageName,@Description,@Path,@Priority,@DepartmentID)", con);
       //Passing parameters to query
       cmd.Parameters.AddWithValue("@ImageName", imgName);
       cmd.Parameters.AddWithValue("@Description", Description);
       cmd.Parameters.AddWithValue("@Path", imgPath + imgName);
       cmd.Parameters.AddWithValue("@Priority", Priority);
       cmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
       cmd.ExecuteNonQuery();
       //Close dbconnection
       con.Close();
       tbImageName.Text = string.Empty;
      // Response.Redirect(Request.RawUrl);
   }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 244
3 BillWoodruff 210
4 Maciej Los 192
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100