I would like to open a file using open file dialog. If the opened file length is a multiple of 94 i would like to open that file if not i would like to throw an error m开发者_如何学Goessage
if(new FileInfo(path).Length % 94 == 0)
{
using(var reader = new StreamReader(path))
{
...
}
}
else
throw new ArgumentException("File-length not multiple of 94", "path");
Strange question! How about....
if( file.Length % 94 ) throw.....
Something like:
if (new FileInfo(filename).Length % 94 != 0)
{
...
}
You may want to set OpenFileDialog.CheckFileExists
to true, too - or do a manual check before taking the length.
精彩评论