i want to compress image size into 40 or 50 kb with my this code is it possible
string CustomerID = "";
if (Session["RoleID"] != null)
{
CustomerID = Request.Form["CustomerID"];
//string CustomerID = Request.Form["Customer.CustomerID"];
if (CustomerID != null)
{
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
//var fileName = Path.GetFileName(file.FileName);
var fileExtension = Path.GetExtension(file.FileName);
var allowedExtensions = new[] { ".bmp", ".png", ".jpg", "jpeg", ".gif" };
if (allowedExtensions.Contains(fileExtension))
{
//Delete files
var pathD = Server.MapPath("~/Avatar/1");
var images = Directory.GetFiles(pathD, CustomerID + ".*");
for (int i = 0; i < images.Length; i++)
System.IO.File.Delete(Server.MapPath(("~/Avatar/1/") + Path.GetFileName(images[i])));
//Up files
var fileName = CustomerID + fileExtension;
var path = Path.Combine(Server.MapPath("~/Avatar/1/"), fileName);
file.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
file.SaveAs(path);
//Session["Avatar"] = fileName;
}