File Upload Validator

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi.
I've developer on my web page a uploader files sytem, but I can't find a
solution for looking the file size before the upload.
Please some help!!

Bye
Franc
 
You can find what you're looking with the
HtmlInputFile.PostedFile.ContentLength

You can check the length of the file before you persist it.

HTH,
Tony
 
Sorry But I dont understan as you said!!!

I've used an FilUpload asp control!!

bye
 
Hmm, ok im not working with aspnet 2.0 but there should be a property on
that server control called PostedFile. That will give you all the info about
the file being posted to the server. There is another property of the
PostedFile called ContentLength. That is where you can check the length of
the file

Does that make sense?
T
 
You can use

FileUpload.PostedFile.ContentLength

It gets the size of an uploaded file, in bytes.

Before .NET 2.0, there is only HtmlInputFile was used to upload file. It's
similar to FileUpload control.

HTH

Elton Wang
 
It's wrong because I've used this property.
I've made so:

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal _
e As System.Web.UI.ImageClickEventArgs) Handles _
ImageButton1.Click

try
If ((FileUp1.FileContent.Length \ 1024) < 4096) Then
msgbox("OK")
else
msgbox("ERROR")
end if
response.redirect("http://forum.aspnet.com")
exit try
catch Ex as HTTPException
response.redirect("hht://forum.aspitalia.com")
end try
end sub

but whe I run my page the browesr give me this error:

Server not Found

The I've think that the solution could be to control the size file.
But I can't!!!

Could you help me??
Bye
 
I think your error stems from trying to use messageboxes in ASP.NET.
This creates an error which gets caught by the catch statement. But the
catch statement is trying to use the hht protocol to find the server
forum.aspitalia.com which isn't going to work.

2 suggestions. First, don't use msgbox, second, write links correctly.
 
OK!! Sorry for the link, but it's wrong that msgboxes give problems in
ASP.NET 2.0!!!

Bye
 
unless you supply your own active/x control to do the upload, there is no
way. the builtin upload support in the browser just adds the file to the
postdata. the server determines the size by counting the number of bytes
uploaded.

asp.net has a max upload size, if the browser sends more bytes than this, it
kills the connection, because the http protocol has no other way to stop an
upload. the browser will detect the connection break and realize that no
response is coming, so it gives a page error.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top