我似乎無法更改文件上的只讀標誌。我已經在Vista和XP上嘗試了這個結果,所以我不認爲這是UAC相關的問題。更改文件的只讀屬性
沒有我所做的似乎工作,雖然。請參閱下面的示例。有人能告訴我我做錯了什麼嗎?
public bool UpdateResFile(string fileName, string language, string objectName, string NewValue)
{
FileInfo fi = new FileInfo(fileName);
try
{
//Do Stuff
xDoc.Save(fileToUpdate);
}
catch (UnauthorizedAccessException)
{
//fi.IsReadOnly = false;
File.SetAttributes(fileName, FileAttributes.Normal);
//fi.Attributes -= FileAttributes.ReadOnly;
return UpdateResFile(fileName, language, objectName, NewValue);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
return true;
}
這樣做!我把支票擡高了,它運作得很好。 – JoelHess 2009-01-29 14:42:51