Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetFileInformationByHandle (kernel32)
 
.
Summary
TODO - a short description

C# Signature:

    enum FileInformationClass : int
    {
        FileBasicInfo = 0,
        FileStandardInfo = 1,
        FileNameInfo = 2,
        FileRenameInfo = 3,
        FileDispositionInfo = 4,
        FileAllocationInfo = 5,
        FileEndOfFileInfo = 6,
        FileStreamInfo = 7,
        FileCompressionInfo = 8,
        FileAttributeTagInfo = 9,
        FileIdBothDirectoryInfo = 10, // 0xA
        FileIdBothDirectoryRestartInfo = 11, // 0xB
        FileIoPriorityHintInfo = 12, // 0xC
        FileRemoteProtocolInfo = 13, // 0xD
        FileFullDirectoryInfo = 14, // 0xE
        FileFullDirectoryRestartInfo = 15, // 0xF
        FileStorageInfo = 16, // 0x10
        FileAlignmentInfo = 17, // 0x11
        FileIdInfo = 18, // 0x12
        FileIdExtdDirectoryInfo = 19, // 0x13
        FileIdExtdDirectoryRestartInfo = 20, // 0x14
    }
    [StructLayout(LayoutKind.Sequential)]
    private struct FILE_BASIC_INFO
    {
        public Int64 CreationTime;
        public Int64 LastAccessTime;
        public Int64 LastWriteTime;
        public Int64 ChangeTime;
        public UInt32 FileAttributes;
    }
    [StructLayout(LayoutKind.Sequential)]
    struct FILE_DISPOSITION_INFO
    {
        public bool DeleteFile;
    }
    [StructLayout(LayoutKind.Sequential)]
    struct FILE_END_OF_FILE_INFO
    {
        public Int64 EndOfFile;
    }
    [StructLayout(LayoutKind.Explicit)]
    struct FileInformation
    {
        [FieldOffset(0)]
        public FILE_BASIC_INFO FILE_BASIC_INFO;
        [FieldOffset(0)]
        public FILE_DISPOSITION_INFO FILE_DISPOSITION_INFO;
        [FieldOffset(0)]
        public FILE_END_OF_FILE_INFO FILE_END_OF_FILE_INFO;
    }
    [DllImport("Kernel32.dll", SetLastError = true)]
    private static extern bool SetFileInformationByHandle(SafeHandle hFile, FileInformationClass FileInformationClass, ref FileInformation FileInformation, Int32 dwBufferSize);

Sample Code:

            var FileInformation = new FileInformation();
            FileInformation.FILE_DISPOSITION_INFO.DeleteFile = true;
            SetFileInformationByHandle(fileStream.SafeFileHandle, FileInformationClass.FileDispositionInfo, ref FileInformation, Marshal.SizeOf(FileInformation.FILE_DISPOSITION_INFO));

Another Sample Code:

            var FileInformation = new FileInformation();
            FileInformation..FILE_END_OF_FILE_INFO.EndOfFile = 1024; // 1KB.
            SetFileInformationByHandle(fileStream.SafeFileHandle, FileInformationClass.FileEndOfFileInfo, ref FileInformation, Marshal.SizeOf(FileInformation.FILE_END_OF_FILE_INFO));

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions