Hi,

I have this program that would upload files from the client to the server,

Now I want to validate the filesize before uploading it into the server..

How can I create this kind of validation?

Thanks.

Re: How to validate data file size vb.net? 80 80

I'm not sure what you mean by validate the file size. You can get the file size by

My.Computer.FileSystem.GetFileInfo(filename).Length

Typically you would validate it by uploading it then comparing the size of the uploaded file to the size of the local file but you say you want to validate the size BEFORE uploading it.

I also want to mention that the process to transfer a file should be via a temporary file name. For example, if you want to transfer the file "myfile.txt" the process should be

1) transfer "myfile.txt" to "myfile.txt.temp"
2) verify that Size("myfile.txt") = Size("myfile.txt.temp")
2) rename "myfile.txt.temp" to "myfile.txt"

This is done so that if an automated process at the receiving end is watching for "myfile.txt", it doesn't try to process it until after the rename, guaranteeing that the file is available. You'd be surprised how many "professional" developers get this wrong.

Re: How to validate data file size vb.net? 80 80

I'm not sure what you mean by validate the file size. You can get the file size by

My.Computer.FileSystem.GetFileInfo(filename).Length

Typically you would validate it by uploading it then comparing the size of the uploaded file to the size of the local file but you say you want to validate the size BEFORE uploading it.

I also want to mention that the process to transfer a file should be via a temporary file name. For example, if you want to transfer the file "myfile.txt" the process should be

1) transfer "myfile.txt" to "myfile.txt.temp"
2) verify that Size("myfile.txt") = Size("myfile.txt.temp")
2) rename "myfile.txt.temp" to "myfile.txt"

This is done so that if an automated process at the receiving end is watching for "myfile.txt", it doesn't try to process it until after the rename, guaranteeing that the file is available. You'd be surprised how many "professional" developers get this wrong.

I already have my solution,
fileupload1.postedfile.contentlength

anyway, thanks for the post... :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.