DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Add(col5);
dataGridView1.Columns[5].Name = "Column5";
DataGridViewTextBoxColumn col6 = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Add(col6);
dataGridView1.Columns[6].Name = "Column6";
2014年11月24日 星期一
2014年11月17日 星期一
計算目錄大小及檔案數量
1.使用.Net Framework 4.5
2.using System.IO
3.計算目錄大小:
static long CalculateDirectorySize(DirectoryInfo directory, bool includeSubdirectories)
{
long totalSize = directory.EnumerateFiles().Sum(file => file.Length);
if (includeSubdirectories)
{
totalSize += directory.EnumerateDirectories().Sum(dir => CalculateDirectorySize(dir, true));
}
return totalSize
}
4.計算被指定目錄的檔案數量(含子目錄)
static string CalculateDirectoryFiles(string directory)
{
string fileCount = null;
DirectoryInfo dir = new DirectoryInfo(directory);
int files = dir.EnumerateFiles("*.*", SearchOption.AllDirectories).Count();
fileCount = files.ToString("#,0");
return fileCount;
}
2.using System.IO
3.計算目錄大小:
static long CalculateDirectorySize(DirectoryInfo directory, bool includeSubdirectories)
{
long totalSize = directory.EnumerateFiles().Sum(file => file.Length);
if (includeSubdirectories)
{
totalSize += directory.EnumerateDirectories().Sum(dir => CalculateDirectorySize(dir, true));
}
return totalSize
}
4.計算被指定目錄的檔案數量(含子目錄)
static string CalculateDirectoryFiles(string directory)
{
string fileCount = null;
DirectoryInfo dir = new DirectoryInfo(directory);
int files = dir.EnumerateFiles("*.*", SearchOption.AllDirectories).Count();
fileCount = files.ToString("#,0");
return fileCount;
}
2014年11月5日 星期三
用foreach逐行讀取DataGridView資料
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string Column1 = row.Cells[0].Value.ToString();
string Column2 = row.Cells[1].Value.ToString();
}
訂閱:
文章 (Atom)