I have a project in which, there is a Images on page with 400*300 resolution. When I hover Image, I have <a>
and it opens as a full screen.
Now, when I upload an image, i save it to database column ITM_PATH
. And there is another column ITM_LARGE
. Now I want to do that, if I upload an image, the simple image will be stored at ITM_PATH
and the same image but with 2400*1594 resolution in ITM_LARGE
column. I have searched this but I got no solution.
Code for Upload Image:
protected void btnSubmit_Click(object sender, EventArgs e)
{
HttpFileCollection fileCollection = Request.Files;
string fileName="";
string largeFile = "";
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile uploadfile = fileCollection[i];
fileName = Path.GetFileName(uploadfile.FileName);
if (uploadfile.ContentLength > 0)
{
uploadfile.SaveAs(Server.MapPath("~/Photo-Upload/") + fileName);
lblMessage.Text += fileName + "Saved Successfully<br>";
fileName = "Photo-Upload/" + fileName;
}
}
using (Bitmap bitmap = (Bitmap)System.Drawing.Image.FromFile(fileName))
{
using (Bitmap newbitmap = new Bitmap(bitmap))
{
newbitmap.SetResolution(2400, 1594);
newbitmap.Save(fileName + "Large", ImageFormat.Jpeg);
largeFile = newbitmap.ToString(); ;
}
}
int _Itm_Id = GetMaxNo();
if (_Itm_Id > 0)
{
ConnectDataBase();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_GENERAL";
cmd.Parameters.AddWithValue("@SP_STATUS", "INSERT_ITM");
cmd.Parameters.AddWithValue("@ITM_ID", _Itm_Id);
cmd.Parameters.AddWithValue("@ITM_CAT_ID", ddlCategory.SelectedValue);
cmd.Parameters.AddWithValue("@ITM_NAME", txtItemName.Text);
cmd.Parameters.AddWithValue("@ITM_PATH", fileName);
cmd.Parameters.AddWithValue("@ITM_LARGE", largeFile);
//cmd.Parameters.AddWithValue("@ITM_PRICE", Convert.ToDecimal(txtPrice.Text));
int retval = cmd.ExecuteNonQuery();
if (retval > 0)
lblMessage.Text = "Record Successfully Inserted!!!";
else
lblMessage.Text = "Server Error!!! Please Try Again...";
ClearAll();
}
}
i am retrieving image in repeater by getting its url from database column.
EDIT
I searched for the same, and found bitmap
as a solution, so i added that code, but file not found
exception is coming. Any other idea or edits??
Exception is coming at first line of bitmap