-1

I tried to upload an image and save details of the image to SQL. My SQL Table is like this:

Id    FirmId    FileName        FileURL              
1     12        firmlogo.png    /images/firmlogo.png 

.aspx:

<asp:FileUpload ID="FileUpload1" runat="server"/>
<dx:ASPxButton ID="btnLogo" runat="server" Text="" OnClick="btnLogo_Click">
</dx:ASPxButton>

Code:

public void SaveImage()
{
    if (FileUpload1.PostedFile != null)
    {
        string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        //Save files to disk
        FileUpload1.SaveAs(Server.MapPath("/images/" + FileName));
        //Add Entry to DataBase
        SqlConnection con = new SqlConnection(strConnString);
        string strQuery = "insert into FirmLogo (FileName , FileURL,FirmId) values(@FileName ,@FileURL,@FirmId)";
        SqlCommand cmd = new SqlCommand(strQuery);
        cmd.Parameters.AddWithValue("@FileName ", FileName);
        cmd.Parameters.AddWithValue("@FileURL", "/images/" + FileName);
        cmd.Parameters.AddWithValue("@FirmId", ComboFirm.SelectedItem.Value.ToString());
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;

        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            Response.Write("<center> <b>Image uploaded.</b></center> ");
        }
        catch (Exception ex)
        {
            Response.Write("<center><b>Error.Please try again.</b></center> ");
        }
        finally
        {
            con.Close();
            con.Dispose();
        }
    }
}

protected void btnUpload_Click(object sender, EventArgs e)
{
    SaveImage();
}

My question: I want image size to be width=300px, height=400px and save to my table like this

Id    FirmId    FileName        FileURL                 Width    Height       
1     12        firmlogo.png    /images/firmlogo.png    300      400

How can I add static values of width and height in my codes?

Abbas
  • 14,186
  • 6
  • 41
  • 72
user3107343
  • 2,159
  • 6
  • 26
  • 37

1 Answers1

0

you can change the sql statement

"insert into FirmLogo (FileName , FileURL,FirmId, Width ,Height) values(@FileName ,@FileURL,@FirmId, 300, 400)";

For resize Image :

Resizing image proportionally in ASP.NET C# by specifying either Height or Width

Community
  • 1
  • 1
Damith
  • 62,401
  • 13
  • 102
  • 153