How to validate data file size vb.net?
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.
jbutardo
Junior Poster in Training
73 posts since Jan 2012
Reputation Points: 8
Solved Threads: 1
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.
Reverend Jim
Posting Shark
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
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
jbutardo
Junior Poster in Training
73 posts since Jan 2012
Reputation Points: 8
Solved Threads: 1