Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get size of HttpPostedFileBase file

Tags:

asp.net

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(file.FileName);
}
}

How can I get the file size??

like image 640
Lisa Avatar asked Apr 25 '11 17:04

Lisa


1 Answers

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

like image 56
Kyle Trauberman Avatar answered Sep 28 '22 11:09

Kyle Trauberman