Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > File Size

Reply
Thread Tools

File Size

 
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      02-18-2007
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"?

 
Reply With Quote
 
 
 
 
Patrick
Guest
Posts: n/a
 
      02-18-2007
Try If fudFile1.PostedFile.ContentLength > 4194304

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"?
>



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-18-2007
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


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"?
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      02-18-2007
"Eliyahu Goldin" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...

> 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...


 
Reply With Quote
 
John Timney \(MVP\)
Guest
Posts: n/a
 
      02-18-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Eliyahu Goldin" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
>
>> 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...
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      02-18-2007
"John Timney (MVP)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). 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...


 
Reply With Quote
 
John Timney \(MVP\)
Guest
Posts: n/a
 
      02-18-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "John Timney (MVP)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed). 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...
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-18-2007
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)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "John Timney (MVP)" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed). 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...
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: File Size - Big File Size Keith Thompson C Programming 6 10-03-2009 10:28 PM
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
Disconnect Between HD File Size & PS's File Size One4All Digital Photography 8 09-12-2007 03:02 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
compare file size with online file size tiewknvc9 Java 6 10-01-2006 09:30 AM



Advertisments