Getting filesize from OpenFileDialog?

Mary picture Mary · Aug 24, 2009 · Viewed 10.4k times · Source

How can I get the filesize of the currently-selected file in my Openfiledialog?

Answer

Alex Shnayder picture Alex Shnayder · Aug 24, 2009

You can't directly get it from the OpenFieldDialog.

You need to take the file path and consturct a new FileInfo object from it like this:

var fileInfo = new FileInfo(path);

And from the FileInto you can get the size of the file like this

fileInfo.Length

For more info look at this msdn page.