12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Text;
- using Microsoft.Win32.SafeHandles;
- namespace DiskAccessLibrary
- {
- public class FileStreamUtils
- {
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool SetFileValidData(SafeFileHandle hFile, long ValidDataLength);
-
-
-
-
-
-
-
-
-
-
- public static bool SetValidLength(FileStream fileStream, long validDataLength)
- {
- bool success = SetFileValidData(fileStream.SafeFileHandle, validDataLength);
- if (!success)
- {
- int errorCode = Marshal.GetLastWin32Error();
- string message = String.Format("Unable to set valid file length, Win32 Error: {0}", errorCode);
- throw new IOException(message);
- }
- return success;
- }
- }
- }
|