var fileName = CustomerID + fileExtension;
var path = Path.Combine(Server.MapPath("~/Avatar/1/"), fileName);
//file.SaveAs(path);
//Session["Avatar"] = fileName;
FileUpload MyFile = new FileUpload();
MyFile = path;
System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(MyFile.PostedFile.InputStream);
int imageHeight = imageToBeResized.Height;
int imageWidth = imageToBeResized.Width;
int maxHeight = 400;
int maxWidth = 400;
imageHeight = (imageHeight * maxWidth) / imageWidth;
imageWidth = maxWidth;
if (imageHeight > maxHeight)
{
imageWidth = (imageWidth * maxHeight) / imageHeight;
imageHeight = maxHeight;
}
Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
System.IO.MemoryStream stream = new MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
byte[] imasave = new byte[stream.Length + 1];
stream.Read(imasave, 0, imasave.Length);
string result = System.Text.Encoding.UTF8.GetString(imasave);
file.SaveAs(result);