public static bool WriteStringToFile(string filePath, string str)
        {
            IntPtr hStream = UnsafeNativeApis.CreateFileFromApp(filePath,
                                                                GENERIC_WRITE,
                                                                0,
                                                                IntPtr.Zero,
                                                                CREATE_ALWAYS,
                                                                (uint)File_Attributes.BackupSemantics, IntPtr.Zero);

            if (hStream.ToInt64() == -1)
            {
                return(false);
            }

            byte[] buffer = Encoding.UTF8.GetBytes(str);
            int    dwBytesWritten;

            unsafe
            {
                fixed(byte *pBuffer = buffer)
                {
                    UnsafeNativeApis.WriteFile(hStream, pBuffer, buffer.Length, &dwBytesWritten, IntPtr.Zero);
                }
            }

            UnsafeNativeApis.CloseHandle(hStream);
            return(true);
        }