hi frds, can anyone solve this regarding file uploading, that is when my user wants to upload a file, i set a limit upto 20 mb limit in web config, now when user uploading morethan 20 mb it have to show a error message or some validation wants to show, can anyone guide me regarding this, very urgent plz,.
thanks
regards
ram
Loading
ramarajan raPosted Aug 21, 2008, 11:10 AM
hi , thank u for ur reply, i got ur point and i sucessfully completed also i captured size of file when adding and removing file when it exceeds, thank you
take care
regards
ram
Gaurav TomarPosted Aug 21, 2008, 12:38 AM
Hello,
The code which I send to you is just an example, you need to modify it a bit according to your file size.
See below given lines carefully
int FileSizeKB = FileSize / 1024;
if (FileSizeKB < 200)
In this code we limit user to upload file which is less than 200kb.
So if you need to limit user to 20mb then change it's value to 20480kb
int FileSizeKB = FileSize/1024
if (FileSizeKB < 20480)
{
// do whatever you want
}
else
{
}
Hope you will got my point
ramarajan raPosted Aug 20, 2008, 5:17 PM
here is my coding below in button click event, can anyone solve ths solution
if (FileUpload1.PostedFile != "")
{
int FileSize = FileUpload1.PostedFile.ContentLength;
if (FileUpload1.PostedFile != null && FileSize > 0)
{
int FileSizeKB = FileSize / 1024;
if (FileSizeKB < 200)
{
//do whatever you want
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;
try
{
FileUpload1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("error occured");
}
}
}
}
Gaurav TomarPosted Aug 20, 2008, 12:42 AM
{
int FileSize = ControlName.PostedFile.ContentLength;
if (ControlName.PostedFile != null && FileSize > 0)
{
int FileSizeKB = FileSize / 1024;
if(FileSizeKB < 200)
{
//do whatever you want
}
Else
{
"show your error message";
}
Positively this will solve your problem just take file size value from your web.config file as you mention that you want to access file size from web.config