Wednesday 9 October 2013

How to get File size in ASP.NET/C#



I want to share with you how to get the file size in asp.net. Its very simple...

Code:C#

You will need to import the following namespace.
Using System.IO;

string sMyFileName = "~/rajadurai/raja.jpg";

FileInfo finfo = new FileInfo(Server.MapPath(sMyFileName ));
long FileInBytes = finfo.Length;
long FileInKB = finfo.Length / 1024;
long FileInMB = FileInKB /1024;

lblImgSize.Text="File Size: " + FileInBytes.ToString() +" bytes (" + FileInMB.ToString() + " MB)";

No comments:

Post a Comment