开发者

How can i open a file such that its length should be multiple of 94

开发者 https://www.devze.com 2023-01-12 23:07 出处:网络
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开发者_如何学Goessageif(new File

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消