How to calculate file length in c#:

Posted by Sekar.C under C# on 3/6/2012 | Points: 10 | Views : 2360 | Status : [Member] | Replies : 5
How to calculate file length in c#:

string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);


regard
sekar.c

Regards
Sekar.c



Responses

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
In Order to get file length (or file size)

FileStream fs = File.Open("<your-file-path>", FileMode.Open);
fs.Length;


here Fs.Length represent no. of bytes stored in File. so by dividing this no. by 1024 you'll get size in KBs

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 3/6/2012 [Member] Silver | Points: 25

Up
0
Down
FileInfo fileInfo = new FileInfo(Filename);
long fileLength= fileInfo .Length;

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/29/2012 [Member] Silver | Points: 25

Up
0
Down
@Sekar.C
Mark as answer if it helps...

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muralidosscm on: 7/3/2012 [Member] Starter | Points: 25

Up
0
Down
client side..........

function OnClientFileSelected(sender,args)
{
if(args.get_fileName().length>80)
{
alert("upload failed");
args.set_cancel(true);
}
}

server side refer above code

Regards
Muralidoss M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
string file = FileUpload1.PostedFile.FileName.ToString().Trim();
string c = file.Length.ToString();

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response