string image1 = null;
if (fileUpload1.HasFile)
{
image1 = fileUpload1.FileName;
string[] ValidFileExtensions = new string[] { ".pdf", ".doc", ".docx" };
fi1 = new FileInfo(fileUpload1.FileName);
ext1 = fi1.Extension;
// loop over the array of valid file extensions to compare them with uploaded file
foreach (string extension in ValidFileExtensions)
{
if (ext1 == extension)
{
flag1 = true;
}
}
}
else
{
image1 = "nofile.pdf";
flag1 = true;
ext1 = ".pdf";
}
masters I have to upload 1 mb file. but at user end if user try to upload more than 1 mb file then 1 message should be displayed that size is more 1 mb.
string image1 = null;
if (fileUpload1.HasFile)
{
int fileSize = fileUpload1.PostedFile.ContentLength;
if (fileSize < 2100000)
{
image1 = fileUpload1.FileName;
string[] ValidFileExtensions = new string[] { ".pdf", ".doc", ".docx" };
fi1 = new FileInfo(fileUpload1.FileName);
ext1 = fi1.Extension;
// loop over the array of valid file extensions to compare them with uploaded file
foreach (string extension in ValidFileExtensions)
{
if (ext1 == extension)
{
flag1 = true;
}
}
}
else
{
// Notify the user why their file was not uploaded.
ClientScript.RegisterStartupScript(this.GetType(), "Alert", string.Format("alert('file size is more than 1 MB');"), true);
}
i tried above code but getting error web page not available.
var oFile = document.getElementById("fileUpload").files[0];
//2 mega it's enough i think
if (oFile.size > 2097152)
{
alert("THE FILE SELECTED IS TOO GROWTH ...");
return;
}
hope this help
Thanks for your time and your knowledge that's great to find any help here ..
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Contributor
2564 Points
1919 Posts
upload file with size limit 1 mb else flash message that size more than 1 mb
Sep 01, 2016 10:53 AM|mike4u|LINK
masters I have to upload 1 mb file. but at user end if user try to upload more than 1 mb file then 1 message should be displayed that size is more 1 mb.
with above code how to do it.
Contributor
2564 Points
1919 Posts
Re: upload file with size limit 1 mb else flash message that size more than 1 mb
Sep 01, 2016 11:10 AM|mike4u|LINK
i tried above code but getting error web page not available.
Contributor
2195 Points
950 Posts
Re: upload file with size limit 1 mb else flash message that size more than 1 mb
Sep 01, 2016 11:47 AM|jimmy69|LINK
Hello,
why you don't check the file size in javascript ?
hope this help
Star
9831 Points
3120 Posts
Re: upload file with size limit 1 mb else flash message that size more than 1 mb
Sep 02, 2016 05:34 AM|Brando ZWZ|LINK
Hi mike4u,
According to your description, I couldn’t find why you get the error web page not available error.
Could you please post more codes about your HTML and upload file event codes?
If you could post more relevant codes, It will be more easily for us to reproduce your problem.
Besides, if you want to check the file size before file upload, I suggest you could use CustomValidator control.
More details, you could refer to follow codes and link:
Html:
Code-behind:
Link: How to: Validate with a Custom Function for ASP.NET Server Controls
Best Regards,
Brando