views:

74

answers:

4

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 message

+1  A: 

Strange question! How about....

if( file.Length % 94 ) throw.....
deepcode.co.uk
+1  A: 

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.

Jon Skeet
+4  A: 
if(new FileInfo(path).Length % 94 == 0)
{
   using(var reader = new StreamReader(path))
   {
       ...
   }
}
else 
    throw new ArgumentException("File-length not multiple of 94", "path");
Ani
A: 

I'm curious about why you want to do such a thing...

Sander
should be a comment, not an answer
RichK
Thanks for pointing that out. It seems like I can't comment on posts yet - must have something to do with my reputation score. Next time I'll wait with commenting until I do have the rights to do so :)
Sander