Author |
Topic |
Mamatha
Posting Yak Master
102 Posts |
Posted - 2005-05-09 : 03:09:39
|
HiI want to know the size of a file in C#.NET,i am new to C#.net.Please give me the solution to find size of a particular file in C#.NET.Thanks in advanceMamatha |
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2005-05-09 : 03:36:46
|
It's in the documentation. Do you have the SDK docs installed ?System.IO.FileInfo fi = new System.IO.FileInfo(filepath);fi.Length();DamianIta erat quando hic adveni. |
 |
|
Denverjames2009
Starting Member
1 Post |
Posted - 2009-01-02 : 17:04:07
|
You know what I hate most about people? When they answer a question with, "it's in the documentation" like they are trying to make you feel stupid. If it's such an inconvenience to answer, and you're just going to refer someone to "the documentation", then don't even bother! This world is a lot more content without people like you! Please, just stay under your rock. |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2009-01-02 : 17:10:34
|
maybe he forgot to look in the documentation and needs stating the obvious ___________________________________________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.1 out! |
 |
|
jinlye
Starting Member
1 Post |
Posted - 2009-10-30 : 06:46:30
|
If Merkin had the documentation he might have seen that .Length is a property and not a method, so doesn't take brackets after it. |
 |
|
May Chan
Starting Member
6 Posts |
Posted - 2009-11-26 : 07:15:25
|
using System;using System.IO;class Program{ static void Main() { // The name of the file const string fileName = "test.txt"; // Create new FileInfo object and get the Length. FileInfo f = new FileInfo(fileName); long s1 = f.Length; // Change something with the file. Just for demo. File.AppendAllText(fileName, " More characters."); // Create another FileInfo object and get the Length. FileInfo f2 = new FileInfo(fileName); long s2 = f2.Length; // Print out the length of the file before and after. Console.WriteLine("Before and after: " + s1.ToString() + " " + s2.ToString()); // Get the difference between the two sizes. long change = s2 - s1; Console.WriteLine("Size increase: " + change.ToString()); }}____________www.absolutesteal.com |
 |
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-11-26 : 17:50:53
|
whats wrong with giving someone a pointer towards documentation ? |
 |
|
behrman
Yak Posting Veteran
76 Posts |
|
Paul daniel
Starting Member
3 Posts |
Posted - 2009-12-28 : 04:46:16
|
HiTo get the filesize(bytes,kilobytes,megabytes or GB] Check this code..public static string GetFileSize(long Bytes) { if (Bytes >= 1073741824) { Decimal size = Decimal.Divide(Bytes, 1073741824); return String.Format("{0:##.##} GB", size); } else if (Bytes >= 1048576) { Decimal size = Decimal.Divide(Bytes, 1048576); return String.Format("{0:##.##} MB", size); } else if (Bytes >= 1024) { Decimal size = Decimal.Divide(Bytes, 1024); return String.Format("{0:##.##} KB", size); } else if (Bytes > 0 & Bytes < 1024) { Decimal size = Bytes; return String.Format("{0:##.##} Bytes", size); } else { return "0 Bytes"; } } |
 |
|
behrman
Yak Posting Veteran
76 Posts |
Posted - 2010-01-03 : 10:44:23
|
You can use System.IO.FileInfoexample:System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c:\getmysize.txt");// write file length in bytes to textbox1this.textBox1.Text = fileInfo.Length.ToString();Hope this helps,behamanRAQ Report: Web-based Excel-like Java reporting tool |
 |
|
|