asp.net file size

后端 未结 4 1186
一个人的身影
一个人的身影 2021-01-24 07:51

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         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 08:19

    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:

    
    

    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.

提交回复
热议问题