How to get HttpPostedFileBase file size

I have a function that has a parameter like HttpPostedFileBase , and I get the file 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

+6
source share
1 answer

The ContentLength property in the HttpPostedFileBase class contains the number of bytes in the published file

 int byteCount = file.ContentLength; 

See this link for more information:

http://msdn.microsoft.com/en-us/library/system.web.httppostedfilebase.contentlength.aspx

+23
source

Source: https://habr.com/ru/post/886633/


All Articles