Saturday, December 19, 2009

File Upload in Asp.net

private string IMAGEurl()
{
string saveLocation = "";
string imageurl = "/images/thumbnail/UnknownSuper.gif";
try
{
string imageName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
string extention = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("."));

saveLocation = string.Empty;
saveLocation = Server.MapPath("/images/user");

imageName = txtUsername.Text.ToString() + extention;

saveLocation = saveLocation + "/" + imageName;
// jerry 01-07-2009
Bitmap photo = objvalid.ResizeImage(File1.PostedFile.InputStream, 300, 300);// width height
photo.Save(saveLocation);
//
// File1.PostedFile.SaveAs(saveLocation);

saveLocation = string.Empty;
saveLocation = Server.MapPath("/images/thumbnail");
saveLocation = saveLocation + "/" + imageName;
Bitmap photoFile = objvalid.ResizeImage(File1.PostedFile.InputStream, 64, 64);// width height
photoFile.Save(saveLocation);
imageurl = "/images/thumbnail/" + imageName;
}
catch
{ }
return imageurl;
}

No comments:

Post a Comment