Accessing a shared file?

后端 未结 1 426
抹茶落季
抹茶落季 2021-01-15 22:04

I\'m trying to read a file body from a Windows shared folder by it\'s UNC path, and getting this exception: The process cannot access the file \'\\\\\\lo

1条回答
  •  时光取名叫无心
    2021-01-15 23:01

    Try changing FileShare.Delete to FileShare.ReadWrite. This will allow the file to be read and written by other applications simultaneously. In other words

    var logFile = (string)null;
    using (var fileStream = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    {
        using (var reader = new StreamReader(fileStream))
        {
            logFile = reader.ReadToEnd();
        }
    }
    

    0 讨论(0)
提交回复
热议问题