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

Gaurav TomarRank #1,421 · 1.2K reputationPosted Aug 19, 2008, 8:42 PM EDT
{
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
ramarajan ra41 reputationPosted Aug 20, 2008, 1:17 PM EDT
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 TomarRank #1,421 · 1.2K reputationPosted Aug 20, 2008, 8:38 PM EDT
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 ra41 reputationPosted Aug 21, 2008, 7:10 AM EDT
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