hi
i use these code to set limit size for image that users want to upload
protected void BtnUploadS_Click(object sender, EventArgs e)
{
string path = Server.MapPath(".") + "\\../image/House\\";
//4-Get File Name
string filename = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
//5-Get File Exist and if (true)Generate New Name
while (System.IO.File.Exists(path + "\\" + filename))
filename = "1" + filename;
//6-Save File to Server
if (fup1.HasFile)
{
try
{
// Set file size limit(in bytes) condition to disable the
// users to upload large files. Here 1024 bytes = 1 kilobyte.
if (fup1.PostedFile.ContentLength < 102400)
{
// SaveAs method of PostedFile property used
// to save the file at specified rooted path
fup1.PostedFile.SaveAs(Server.MapPath("~/image/house") + System.IO.Path.DirectorySeparatorChar + fup1.PostedFile.FileName);
// success message
Label21.Text = "File " + fup1.PostedFile.FileName + " uploaded successfully.";
}
else
{
// file size limit exceeded
Label21.Text = "File size of " + Convert.ToString(fup1.PostedFile.ContentLength / 1024) + " KB is exceeding the uploading limit.";
}
}
catch (Exception ex)
{
// error message
Label21.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
// warning message
Label21.Text = "Please choose a file to upload.";
}
string filename = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
//5-Get File Exist and if (true)Generate New Name
while (System.IO.File.Exists(path + "\\" + filename))
filename = "1" + filename;
fup1.PostedFile.SaveAs(path + filename);
SqlCommand _cmd = new SqlCommand("Fileup1", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
_cn.Open();
_cmd.Parameters.AddWithValue("@image", filename);
_cmd.Parameters.AddWithValue("@Behcode", data);
_cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
_cmd.ExecuteNonQuery();
ViewState["Id"] = _cmd.Parameters["@id"].Value.ToString();
_cn.Close();
SqlCommand _cmd1 = new SqlCommand("selectFUP1", _cn);
_cmd1.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd1.Parameters.AddWithValue("@Behcode", data);
//_cmd1.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlDataReader _dr=_cmd1.ExecuteReader();
while(_dr.Read()){
lblimg.Visible = false;
Upbdt.Visible = false;
Button1.Visible = true;
ThumbPic3.ImageUrl = "~/image/house/" + _dr["Image"] . ToString();
}
_cn.Close();
here i define if (fup1.PostedFile.ContentLength < 102400) this size for image but when i upload image that has more than this 100KB it show error ===File size of 756 KB is exceeding the uploading limit but it upload file i don't want users can upload file morethan 100KB but here show error but upload image why?