1

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

AakashM
  • 62,551
  • 17
  • 151
  • 186
Developer
  • 8,390
  • 41
  • 129
  • 238
  • makes me curious why you'd want to do that. are you serializing objects? and this is some kind of a check to make sure the file isn't corrupt? – neal aise Aug 26 '10 at 08:10

3 Answers3

4
if(new FileInfo(path).Length % 94 == 0)
{
   using(var reader = new StreamReader(path))
   {
       ...
   }
}
else 
    throw new ArgumentException("File-length not multiple of 94", "path");
Justin
  • 84,773
  • 49
  • 224
  • 367
Ani
  • 111,048
  • 26
  • 262
  • 307
1

Strange question! How about....

if( file.Length % 94 ) throw.....
deepcode.co.uk
  • 1,464
  • 1
  • 14
  • 22
1

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194