[英]System.IO.IOException: 'The handle is invalid. : '\\.\Con''
I have a WPF NET core app and trying to write file locally.我有一个 WPF NET 核心应用程序并尝试在本地写入文件。
var movies = await GetMovies(_settings.MovieFolderId);
foreach (var movie in movies)
{
Message = $"Writing locally {movie.Name}";
var meta = Path.Combine(pathToSave, $"{movie.Name}.meta");
if (!File.Exists(meta))
{
await File.WriteAllTextAsync(meta, $"{movie.Id}\r\n{movie.Parents?.FirstOrDefault() ?? string.Empty}");
}
}
and I got:我得到了:
and meta
value is : C:\\p\\bds\\Con.Air.A-MVIE.meta
meta
值是: C:\\p\\bds\\Con.Air.A-MVIE.meta
Why ?为什么 ? It does not happens to all file(s) from that iteration.
它不会发生在该迭代中的所有文件中。
Yes, as the comments say "con" is not allowed.是的,正如评论所说的“骗局”是不允许的。 Below is Microsoft Doc extract:
以下是 Microsoft Doc 摘录:
Do not use the following reserved names for the name of a file:
不要使用以下保留名称作为文件名:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9
CON、PRN、AUX、NUL、COM1、COM2、COM3、COM4、COM5、COM6、COM7、COM8、COM9、LPT1、LPT2、LPT3、LPT4、LPT5、LPT6、LPT7、LPT8和LPT9
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.