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
2010-08-26 07:20:10
+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
2010-08-26 07:20:16
+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
2010-08-26 07:22:32
should be a comment, not an answer
RichK
2010-08-26 09:03:56
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
2010-08-26 14:26:06