因此,即使我们从防病毒/防火墙清除了该应用程序,我的程序仍会说UnauthorizedAccessException。错误发生在此行:
FileStream log = File.Create(path);
它说我无法访问路径。下面是上下文中的代码。
private void StartConversion1(object sender, RoutedEventArgs e)
{
String path = Properties.Settings.Default.label;
FileStream log = File.Create(path);
StreamWriter sw = new StreamWriter(log);
foreach (String f in filesToProcess1)
{
// rest of the code
谢谢
答案 0 :(得分:0)
从错误中可以明显看出这是一个权限问题
删除与目录关联的只读属性
var di = new DirectoryInfo("Path to directory");
di.Attributes &= ~FileAttributes.ReadOnly;
结论:
if(Directory.Exists(inputdirpath))
{
//Code to remove read-only attribute
//Code to create File
}