如何在Openfiledialog中获取当前所选文件的文件大小?
答案 0 :(得分:11)
var ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
var size = new FileInfo(ofd.FileName).Length;
}
答案 1 :(得分:3)
如此稀疏的信息,我可以告诉你的是:
new FileInfo(dialog.Filename).Length
答案 2 :(得分:2)
if (this.myOpenFileDialog.ShowDialog() == DialogResult.OK)
{
var length = new System.IO.FileInfo(this.myOpenFileDialog.FileName).Length;
}
答案 3 :(得分:0)
在mitlselect和single select两种模式下
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.Multiselect)
{
long totalsize = 0;
foreach (string siz in openFileDialog1.FileNames)
totalsize += new FileInfo(siz).Length;
MessageBox.Show(totalsize.ToString());
}
else
{
MessageBox.Show(new FileInfo(openFileDialog1.FileName).Length.ToString());
}
}