简体   繁体   中英

System.IO.IOException: 'The handle is invalid. : '\\.\Con''

I have a WPF NET core app and trying to write file locally.

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

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:

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

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM