by using below this code
if (FileUpload1.HasFile)
{
string savePath = Server.MapPath("~/memberspic/");
string fileName = FileUpload1.FileName;
string pathToCheck = savePath + fileName;
Random rm = new Random();
TextBox txtpass = new TextBox();
txtpass.Text = rm.Next(257871, 498371).ToString();
Guid g = Guid.NewGuid();
string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/memberspic/") + "img_pk" + txtpass.Text.ToString() + extension);
string te;
te = "~/memberspic/" + "img_pk" + txtpass.Text.ToString() + extension;
impath = pathToCheck;
cmd.Parameters.AddWithValue("@ProfilePicture", te);
}
we can save the image files in folder with this path like ~/memberspic/img_pk368811.jpg but the file size is very large.
how to compress that image file before save to folder.
please help me
it's very important to me.
Iftikar HussainPosted Jun 27, 2013, 4:09 AM
You need to change default maximum upload size in web.config file.
where
maxRequestLength - Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB).
and
executionTimeout - Indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET.
Regards,
Ifitkar
Remember to click "Mark as Answer" on the post, if it helps you.
Sanjeeb LenkaPosted Jun 27, 2013, 4:03 AM
upload more than 4mb
it will not take that . so you have to change it in web.config
within
you can increase or decrease the maxRequestLength according
to your requirement memory size is in bytes
prathyushaPosted Jun 27, 2013, 3:58 AM
i have doubt regarding using this code.
when i select 4.06 size file error will be displayed once check it.
please help me
Iftikar HussainPosted Jun 26, 2013, 7:43 AM
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
prathyushaPosted Jun 26, 2013, 7:36 AM
here i'm attaching one file.
when uploading that file size will be increased.
when i upload the file ( dimenssions 1024x768 ) this file will be compressed .it's working correctly
but first file size will be increased.no need increase.
please help me
Sanjeeb LenkaPosted Jun 26, 2013, 7:23 AM
in my attached code just modify the button click event with below code:
protected void btnsave_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
string targetPath = Server.MapPath("Images/" + filename);
Stream strm = fileupload1.PostedFile.InputStream;
var targetFile = targetPath;
int imgSize = fileupload1.PostedFile.ContentLength;
//here i am checking the image size if the size is greater than 1mb then compress otherwise direct save
//image size is in byte you can specify your image size here i am talking 90kb if more than 90kb it will compress or leave
if (imgSize > 92160)
//Based on scalefactor image size will vary
GenerateThumbnails(0.5, strm, targetFile);
else
fileupload1.SaveAs(Server.MapPath("~/Images//") + filename);
BindDataList();
}
prathyushaPosted Jun 26, 2013, 7:12 AM
but when i uploading small file like 10 kb. that file also compressed.
but i need only large file like 90kb,or 4mb files only please help me
Iftikar HussainPosted Jun 26, 2013, 7:12 AM
You can do like this
string strExtension = System.IO.Path.GetExtension(FileUpLoad1.FileName);
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
Sanjeeb LenkaPosted Jun 26, 2013, 7:06 AM
i attached a file check that . if any doubt reply.
prathyushaPosted Jun 26, 2013, 6:56 AM
when the file size is very small no need to compress. please help me
Sanjeeb LenkaPosted Jun 26, 2013, 6:53 AM
http://www.aspdotnet-suresh.com/2011/05/how-to-resize-size-image-without-losing.html