I want to get the file size before uploading to server. I used following code
Dim fileDetails As IO.FileInfo
fileDetails = My.Computer.FileSystem.GetFileInfo(fil
Unfortunately you cannot check the file size on the client end. It shouldn't be that big of a deal, I have a few current production implementations allowing multiple file uploads that check the file size on server-side. It is not that long of a delay and I don't believe you will find a way around this.
Something to make note of, the web.config has setting within that determines the maximum length (in kilobytes) of a single request. By default, this is set to 4MB. So if your user is trying to upload more than this amount, he will receive a server error. Here is how you change this:
<system.web>
<httpRuntime maxRequestLength="4096"/>
</system.web>
You can't access the client file system from an ASP.NET page, so you'll need upload the file before checking its size and rejecting it if it's too big.
As far as i know there is no way to detect the file size serverside BEFORE the upload
The way to do this if you use a flash uploader such as SWFupload or uploadify and you can limit the file size and extension from swf upload or uploadify ( i recomend using uploadify )
The code you have implemented works only for server side objects. If you want to check the file size before allowing an upload, you would have to have an activeX control that was allowed access to the client's local file system. The best way to do this is to allow the upload and then dump unwanted files (with an error message indicating the problem). Here is how you would check the file size of an uploaded file though:
<input id="uploadFile" runat="server" type="file" />
And in the code behind:
Dim fileSize as Int64 = uploadFile.PostedFile.ContentLength
At this point if the file is too big, you can just do nothing with it, and send a message back to the user to let them know it wasn't saved.