private static void WriteAlternateStream(string _path, string _text)
{
var stream = CreateFileW(_path, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_ALWAYS, 0, IntPtr.Zero);
using (FileStream fs = new FileStream(stream,FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(_text);
sw.Close();
}
}
}
public static void Id(string _PathExe)
{
var x = _PathExe + ":Zone.Identifier";
WriteAlternateStream(x, "[ZoneTransfer]\r\nZoneId=1");
}
У меня выскакивает:
Предупреждение 1 "System.IO.FileStream.FileStream(System.IntPtr, System.IO.FileAccess)" является устаревшим: "This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access) instead. http://go.microsoft.com/fwlink/?linkid=14202"
Можно ли это заменить?
Добавил текст
Я обычно импортировал:
[DllImport("kernel32.dll", EntryPoint = "CreateFileW")]
public static extern System.IntPtr CreateFileW(
[InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string lpFileName,
uint dwDesiredAccess,uint dwShareMode,
[InAttribute()] IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
[InAttribute()] IntPtr hTemplateFile);
Но если заменить его на:
[DllImport("kernel32.dll", SetLastError = true, CharSet=CharSet.Unicode)]
static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
То получаю ошибку в var stream = CreateFileW(
что:
Элемент "CreateFileW" не существует в текущем контексте.
Решение проблемы
[DllImport("kernel32.dll", SetLastError = true, EntryPoint = "CreateFileW", CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFileW(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
var stream = CreateFileW(
- проще было бы заменить наvar stream = CreateFile(