CreateFile with FILE_FLAG_NO_BUFFERING "ala" .Net

  • Thread starter Thread starter craigkenisston
  • Start date Start date
C

craigkenisston

Hi,

How can I open a file with the FILE_FLAG_NO_BUFFERING
using .net just like in the win32 days ?
 
I guess you need to open the file with no system caching. Yes .Net supports
this.. Have a look at System.Xml name space for XML files.. System.IO.File
for all the files..

Nirosh.
 
All file IO API's in the FCL are buffered, you need to PInvoke CreateFile
(kernel32) and specify the FILE_FLAG_NO_BUFFERING, the returned handle can
be wrapped by a FileStream class.
Beware that the request buffer must be sector size aligned and the request
size must be a multiple of a sector size.

Willy.
 
Hi, Willy :

Thanks for the advise, I didn't realize there's a constructor that
accept the file handle as parameter, so, this should work.
The only bad thing is that this puts my application in non-safe mode,
which was I requirement I have. I'll try to circunvent this in another
way.

Regards,
 
What do you mean with "unsafe" mode? There is nothing unsafe in using
DllImport to declare and use Win32 API's.

Willy.
 
Back
Top