Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2005, 08:52 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default evaluate the size of a file BEFORE it gets uploade

another question;
does anyone know the best way to determine the size of a file that's being uploaded via the html file input feild?
what i'm trying to do is limit the size of the pictures people can upload, but have no clue where to start, eg, the directoryinfo, binary*, etc, etc, so i want to ask someone with experience what they think the best method is to evaluate the size of a file in a pages _load/postback routine.
i already have the upload part working as far as simply uploading goes:
Code:
IF PAGE.IsPostBack THEN
DIM P13 AS String

IF (RIGHT(PIC.VALUE, 3)) = "jpg" THEN P13 = ".JPG"
IF (RIGHT(PIC.VALUE, 3)) = "JPG" THEN P13 = ".JPG"
IF (RIGHT(PIC.VALUE, 3)) = "gif" THEN P13 = ".GIF"
IF (RIGHT(PIC.VALUE, 3)) = "GIF" THEN P13 = ".GIF"
IF (RIGHT(PIC.VALUE, 3)) = "bmp" THEN P13 = ".BMP"
IF (RIGHT(PIC.VALUE, 3)) = "BMP" THEN P13 = ".BMP"
IF (RIGHT(PIC.VALUE, 3)) = "png" THEN P13 = ".PNG"
IF (RIGHT(PIC.VALUE, 3)) = "PNG" THEN P13 = ".PNG"


IF PIC.VALUE <> "" THEN
DIM CM2 AS OLEDBCOMMAND
DIM CN2 AS OLEDBConnection
DIM CMV2 AS String
CN2 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0;Data Source=Z:\WWW\DATA\MX.mdb")
CMV2 = "UPDATE PROFILE SET PIC" &NUM.TEXT & "='" &P13 &"' WHERE UNAME='" &UNAME.TEXT &"'"
CM2 = NEW OLEDBCOMMAND(CMV2,CN2)
cn2.open()
CM2.EXECUTENONQUERY()
CN2.Close
CN2 = NOTHING

Dim filepath As String
filepath = Path.Combine ("X:\www\profiles\USERS\" & UNAME.TEXT &"\", Path.GetFileName(DS222.Tables ("PROFILE").ROWS(0).ITEM(I).TOSTRING()))
If File.Exists(FilePath) Then
File.Delete(FilePath)
End IF

filepath = Path.Combine ("X:\www\profiles\USERS\" & UNAME.TEXT &"\", Path.GetFileName(NUM.TEXT & P13))
PIC.PostedFile.SaveAs(filepath)

END IF
RESPONSE.REDIRECT("PIC.ASPX?uname=" & UNAME.text)

END IF
i just need to figure out how to evaluate the file's size.
i tried to search this forum, and others for a good idea, but i guess this isn't that hot of a topic.
i don't really need a code example. if you could just tell me a good way to do it, i can look up the gory details myself, so it doesn't take too much of your time, but i'm not opposed to anyone offering further help.
thanks in advance: ALEX GRIM

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
__________________
---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 8th, 2005, 11:24 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

 NEVERMInd guys, i got it figured out. but thanks anyway.
oh yeah, i guess i could post my soloution in case someone else has the same problem:
Code:

' "PIC" is the name of my html input control
IF PIC.POSTEDFILE.CONTENTLENGTH > 100 THEN
RESPONSE.WRITE("THIS IS TOO DAMNED BIG!!!<BR>")
EXIT SUB
ELSE
'do your thing


good luck

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 9th, 2005, 06:02 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Another possible way would be to set up the limit in the web config. Though I don't know off hand what the node is you'd need to change, I think there is a property somewhere to limit the size of the incoming request. This should cause the server to more quickly reject the request. (Not sure if the browser first sends the size of the request as a check before shipping off the whole thing, this might make for a faster rejection.) However, this wouldn't be as "user friendly" as your message.

-Peter
 
Old May 9th, 2005, 10:10 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

ACTUALLY the browser does send some sort of header, but i don't know the syntax for accesing it's value, eg: "request.header('ContentLength')", so i just did it my way.

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 10th, 2005, 03:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

CONTENT_LENGTH will return the complete size of the entire posted form (not just the posted file). This wouldn't be that bad to check because from a percentage standpoint the size of the file will most likely be the largest portion of the request.

Accessing the value of the posted size won't be of much use in rejecting the request however. The problem is that the entire request will get uploaded to the server before the IIS process hands the request off to the ASP.NET worker process. So I don't see how the delay of a large upload could be avoided without how better control over the client's file choosing process.

-Peter
 
Old May 10th, 2005, 06:11 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

where you say "CONTENT_LENGTH", how would you use that in a statement, eg. "request.httpCONTENT_LENGTH"? and i haven't yet found a way in asp.net to filter what file extentions are used like you can in vb. but then again, i haven't tried either.

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old May 10th, 2005, 09:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Request.ServerVariables("CONTENT_LENGTH")

There are also some server variables that are available as strongly typed properties of the Request class but I don't recall what they are off hand.


I'm not sure I understand what you mean by "...what file extensions...". Oh, do you mean when you click the browse button to choose the button for upload, you want to restrict it to a particular extension? I don't think you can do that because it's a feature of the browser (and therefore probably also the operating system) and thus not something you can control easily (if at all).

-Peter
 
Old May 10th, 2005, 10:30 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

well thanks for the syntax example, i've seen it before, but i tend to not memorize things i don't think i'll need, and well, i was wrong about that one. so thanks.

---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get file size from VB? delcyan VB How-To 8 April 9th, 2010 04:52 PM
Wrox File Share - 1g file size limit b67 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 May 7th, 2007 04:24 PM
file size dotnetprogrammer VS.NET 2002/2003 3 November 17th, 2004 01:33 AM
Trouble with file size, PLEASE HELP!!! brettk_1 ASP.NET 1.0 and 1.1 Professional 3 August 25th, 2004 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.