How to get size of HttpPostedFileBase file
I have a function that has a parameter of type HttpPostedFileBase and I'm getting the file's name using (Path.GetFileName):
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
foreach (var file in attachments)
{
var fileName = Path.GetFileName(fil开发者_如何学Goe.FileName);
}
}
How can I get the file size??
The ContentLength
property on the HttpPostedFileBase
class contains the number of bytes in the posted file
int byteCount = file.ContentLength;
See this link for more information:
http://msdn.microsoft.com/en-us/library/system.web.httppostedfilebase.contentlength.aspx
精彩评论