1

I am trying to re-write a part of my application from ATL/COM(C++) to WPF, C#. In the older application they use

m_inputFile = new CFile(fileName,CFile::modeRead);
DWORD fileLength= (DWORD) m_inputFile->GetLength();

But when I use FileInfo.Length in C# application, this gives incorrect value. What is the correct way to implement logical length of file in C#? Any advise is greatly appreciated.

user2495173
  • 311
  • 2
  • 5
  • 17
  • 1
    FileInfo.Length works. Something else is going on. – nos May 17 '14 at 00:47
  • 2
    If you are opening the file in text mode and reading the contents **and** the file contains Windows line-endings the line endings will be converted from two bytes to one. This will cause the number of bytes read to be different than the value returned by a call to `FileInfo.Length`. – Captain Obvlious May 17 '14 at 02:01
  • how is the fileLength value being used? – Gayot Fow May 17 '14 at 11:11
  • I only have 128 bits in my file and FileInfo.Length returns 134 as the length. This is how fileLength value is used as follows: this.nBlocks = (int)Math.Round((double)(this.fileLength) / 16); – user2495173 May 19 '14 at 17:23

0 Answers0