Does "File.SetAttributes" remove read-only attributes?


  • Hello to all,

    i need to clean directory when elaboration is finished.

    When i try to delete a temp file, an exception is raised: 

    Unhandled Exception: System.UnauthorizedAccessException: Access to the path 'C:\FTP_HOME\LocalUser\[xxx]\REQ_SYM_111_20170420_1.t' is denied.

    Adding a line in my my snippet:

    var fileName = @"C:\FTP_HOME\LocalUser\[xxx]\REQ_SYM_111_20170424_1.t";
    File.SetAttributes(fileName, FileAttributes.Normal);

    All files are deleted without any error.

    Why the line above is so magic?

    Thank in advance, and sorry for my english :)

    Tuesday, May 2, 2017 7:53 AM


All replies