Monday, June 7, 2010

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

In asp.net forum I have got this question many times like this, "How to get File size" or "How to get File Length". For this today I want to share with you how to get the file size in asp.net. Its very simple but helpful...

Code:C#

Add namespace:
Using System.IO;


string sMyFileName = "~/photos/test.jpg";

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

Response.Write("File Size: " + FileInBytes.ToString() +
" bytes (" + FileInMB.ToString() + " MB)");

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...