I 开发者_如何学编程have a small form that allow user to upload an avatar I used WebImage to get the file uploaded from client (WebImage.GetImageFromRequest() that return WebImage object), in the server i have to check to size of avatar, how can i do that?
Edit: I mean the length of it, the length in kb
http://msdn.microsoft.com/en-us/library/system.web.helpers.webimage(v=vs.99).aspx
The WebImage class has properties that expose the Height and Width of the image in pixels. So this will give you the size of the image.
EDIT
I think this post might help you with that, but it requires you have the image saved to disk.
How to get the file size of a "System.Drawing.Image"
Additionally, you could do something like this, though it'll have some overhead as you'll be putting all of the bytes into memory...
WebImage uploadedImage = WebImage.GetImageFromRequest("somefile");
long sizeInKBytes = uploadedImage.GetBytes().Length / 1024;
精彩评论