473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

File Size

I am giving users the option to upload files from their hard disk to
the server but only those files will be uploaded whose size is less
tha or equal to 1 MB.

I am using the ASP.NET FileUpload control to design the interface.
This is the code:

<script runat="server">
Sub Page_Load(.....)
If (Page.IsPostBack) Then
If (fudFile1.FileName <"") Then
If (fudFile1.FileBytes.Length / 1048576 1) Then
lblMessage.Text = "File size cannot exceed 1 MB"
Else
fudFile1.SaveAs(Server.MapPath(fudFile1.FileName))
lblMessage.Text = "File uploaded"
End If
End If
End If
End Sub
</script>

<form runat="server">
<asp:FileUpload ID="fudFile1" runat="server"/><br><br>
<asp:Button ID="btnUpload" Text="UPLOAD FILE" runat="server"/>
<asp:Label ID="lblMessage" runat="server"/>
</form>

Now what I find is if I try to upload a file whose size is greater
than 1 MB but less than or equal to 4 MB, then, as expected, the Label
renders the message "File size cannot exceed 1 MB" but if the file
size exceeds 4 MB, then the Label doesn't render the "File size cannot
exceed 1 MB" message.

Instead, IE just renders the omnipresent "The page cannot be
displayed" page with the error "Cannot find server or DNS Error" at
the very end of the page.

Why isn't the Label displaying the "File size cannot exceed 1 MB"
message when the file size is greater than 1 MB but less than or equal
to 4 MB? How do I ensure that even if the file size exceeds 4 MB,
users are still shown the Label with the message "File size cannot
exceed 1 MB"?

Feb 18 '07 #1
7 1889
Try If fudFile1.PostedFile.ContentLength 4194304

<rn**@rediffmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>I am giving users the option to upload files from their hard disk to
the server but only those files will be uploaded whose size is less
tha or equal to 1 MB.

I am using the ASP.NET FileUpload control to design the interface.
This is the code:

<script runat="server">
Sub Page_Load(.....)
If (Page.IsPostBack) Then
If (fudFile1.FileName <"") Then
If (fudFile1.FileBytes.Length / 1048576 1) Then
lblMessage.Text = "File size cannot exceed 1 MB"
Else
fudFile1.SaveAs(Server.MapPath(fudFile1.FileName))
lblMessage.Text = "File uploaded"
End If
End If
End If
End Sub
</script>

<form runat="server">
<asp:FileUpload ID="fudFile1" runat="server"/><br><br>
<asp:Button ID="btnUpload" Text="UPLOAD FILE" runat="server"/>
<asp:Label ID="lblMessage" runat="server"/>
</form>

Now what I find is if I try to upload a file whose size is greater
than 1 MB but less than or equal to 4 MB, then, as expected, the Label
renders the message "File size cannot exceed 1 MB" but if the file
size exceeds 4 MB, then the Label doesn't render the "File size cannot
exceed 1 MB" message.

Instead, IE just renders the omnipresent "The page cannot be
displayed" page with the error "Cannot find server or DNS Error" at
the very end of the page.

Why isn't the Label displaying the "File size cannot exceed 1 MB"
message when the file size is greater than 1 MB but less than or equal
to 4 MB? How do I ensure that even if the file size exceeds 4 MB,
users are still shown the Label with the message "File size cannot
exceed 1 MB"?

Feb 18 '07 #2
You get the file size on server side, that is after the file has already
been uploaded. Files larger than 4M fail to upload and this causes your IE
error. I am not aware of any simple ways of evaluating file size on client
side.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<rn**@rediffmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>I am giving users the option to upload files from their hard disk to
the server but only those files will be uploaded whose size is less
tha or equal to 1 MB.

I am using the ASP.NET FileUpload control to design the interface.
This is the code:

<script runat="server">
Sub Page_Load(.....)
If (Page.IsPostBack) Then
If (fudFile1.FileName <"") Then
If (fudFile1.FileBytes.Length / 1048576 1) Then
lblMessage.Text = "File size cannot exceed 1 MB"
Else
fudFile1.SaveAs(Server.MapPath(fudFile1.FileName))
lblMessage.Text = "File uploaded"
End If
End If
End If
End Sub
</script>

<form runat="server">
<asp:FileUpload ID="fudFile1" runat="server"/><br><br>
<asp:Button ID="btnUpload" Text="UPLOAD FILE" runat="server"/>
<asp:Label ID="lblMessage" runat="server"/>
</form>

Now what I find is if I try to upload a file whose size is greater
than 1 MB but less than or equal to 4 MB, then, as expected, the Label
renders the message "File size cannot exceed 1 MB" but if the file
size exceeds 4 MB, then the Label doesn't render the "File size cannot
exceed 1 MB" message.

Instead, IE just renders the omnipresent "The page cannot be
displayed" page with the error "Cannot find server or DNS Error" at
the very end of the page.

Why isn't the Label displaying the "File size cannot exceed 1 MB"
message when the file size is greater than 1 MB but less than or equal
to 4 MB? How do I ensure that even if the file size exceeds 4 MB,
users are still shown the Label with the message "File size cannot
exceed 1 MB"?

Feb 18 '07 #3
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:OJ**************@TK2MSFTNGP05.phx.gbl...
I am not aware of any simple ways of evaluating file size on client side.
I'm pretty sure the only options are a Java applet or an ActiveX control...
Feb 18 '07 #4
It can be done with Javascript, but only if the browser local security is
low enough to allow it. Its probably OK for intranets, but not for an
internet scenario.

This example is quite comprehensive but its a bit old now. Should still be
a good pointer.

http://www.faqts.com/knowledge_base/view.phtml/aid/1685

--
--
Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog


"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u9**************@TK2MSFTNGP06.phx.gbl...
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:OJ**************@TK2MSFTNGP05.phx.gbl...
>I am not aware of any simple ways of evaluating file size on client side.

I'm pretty sure the only options are a Java applet or an ActiveX
control...

Feb 18 '07 #5
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Vd******************************@eclipse.net. uk...
It can be done with Javascript, but only if the browser local security is
low enough to allow it. Its probably OK for intranets, but not for an
internet scenario.

This example is quite comprehensive but its a bit old now. Should still
be a good pointer.

http://www.faqts.com/knowledge_base/view.phtml/aid/1685
Well, yes, but that's using an ActiveX object - specifically
FileSystemObject - so no use for anything other than IE...
Feb 18 '07 #6
If I recall it, it works in both IE and Netscape et al as it taps into Java
objects for non IE browsers but it has to be ran as a trusted script. Hence
my caveat that it was no good for internet. I'd only ever look to use
something as quirky as this in an extreme case.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ep**************@TK2MSFTNGP05.phx.gbl...
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Vd******************************@eclipse.net. uk...
>It can be done with Javascript, but only if the browser local security is
low enough to allow it. Its probably OK for intranets, but not for an
internet scenario.

This example is quite comprehensive but its a bit old now. Should still
be a good pointer.

http://www.faqts.com/knowledge_base/view.phtml/aid/1685

Well, yes, but that's using an ActiveX object - specifically
FileSystemObject - so no use for anything other than IE...

Feb 18 '07 #7
On in any case where the users trust the server. For example, medical
practices providing services to their doctors.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:wO******************************@eclipse.net. uk...
If I recall it, it works in both IE and Netscape et al as it taps into
Java objects for non IE browsers but it has to be ran as a trusted script.
Hence my caveat that it was no good for internet. I'd only ever look to
use something as quirky as this in an extreme case.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ep**************@TK2MSFTNGP05.phx.gbl...
>"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Vd******************************@eclipse.net .uk...
>>It can be done with Javascript, but only if the browser local security
is low enough to allow it. Its probably OK for intranets, but not for
an internet scenario.

This example is quite comprehensive but its a bit old now. Should still
be a good pointer.

http://www.faqts.com/knowledge_base/view.phtml/aid/1685

Well, yes, but that's using an ActiveX object - specifically
FileSystemObject - so no use for anything other than IE...


Feb 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
4
by: M P | last post by:
Can you help me find an asp code that will upload a file from my PC to web server? Mark
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
2
by: Dan | last post by:
Hi, I know this code is not entirely javascript, but bare with me. Can you please tell me why this does not work: page: filemanager.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: cleary1981 | last post by:
Hi, I have created a script in PHP thats generates an SVG image. Want I want to do is have PHP save this as example.svg. Can this be done? Heres my code <?php require "config.php"; $proj_id =...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.