code_junkie

Changing a Read Only attribute on a file

Nov 13th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public bool UpdateResFile(string fileName, string language, string objectName, string NewValue)
  2. {
  3. FileInfo fi = new FileInfo(fileName);
  4. try
  5. {
  6. //Do Stuff
  7. xDoc.Save(fileToUpdate);
  8. }
  9. catch (UnauthorizedAccessException)
  10. {
  11. //fi.IsReadOnly = false;
  12. File.SetAttributes(fileName, FileAttributes.Normal);
  13. //fi.Attributes -= FileAttributes.ReadOnly;
  14. return UpdateResFile(fileName, language, objectName, NewValue);
  15. }
  16. catch (System.Exception ex)
  17. {
  18. Console.WriteLine(ex.Message);
  19. return false;
  20. }
  21. return true;
  22. }
Add Comment
Please, Sign In to add comment