protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
Int32 id = Convert.ToInt32(Session["tempid"]);
string filename = AsyncFileUpload1.PostedFile.FileName;
string extension = filename.Substring(filename.LastIndexOf('.'));
if (int.Parse(e.FileSize)>150000)
{
string s = "File size must not exceed 150 KB";
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + s + "');</script>");
return;
}
if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg")
{
Bitmap originalBMP = new Bitmap(AsyncFileUpload1.FileContent);
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
string newfilename = "Photo_" + id + ".jpg";
//string filePath = Request.PhysicalApplicationPath + "upload\\" + newfilename;
string filePath = TEGlobal.uploadurl + newfilename;
//if (origWidth > 100 || origHeight > 130)
if (origWidth > 206 || origHeight > 260)
{
//Bitmap newBMP = resizeimage(originalBMP, origWidth, origHeight, 100, 130);
Bitmap newBMP = resizeimage(originalBMP, origWidth, origHeight, 206, 260);
newBMP.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
originalBMP.Dispose();
newBMP.Dispose();
}
else
{
AsyncFileUpload1.SaveAs(filePath);
}
string url = TEGlobal.downloadurl + newfilename + '?' + DateTime.Now.ToString("HH:MM:ss");
newpath = TEGlobal.downloadurl + newfilename + '?' + DateTime.Now.ToString("HH:MM:ss");
ScriptManager.RegisterClientScriptBlock(AsyncFileUpload1, AsyncFileUpload1.GetType(), "img", "top.document.getElementById('imagesphoto').src='" + url + "';", true);
objphoto.appid = id;
objphoto.photo = newfilename;
objupdown.UpdatePhoto(objphoto);
UpdatePanel_photo.Update();
}
else
{
string s = "Only JPG files are allowed";
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + s + "');</script>");
return;
}
}