Friday, 6 March 2020

Delete read only condition files in c# or asp.net c# or windows services





public void Delete_file_ReadonlyCondition(string FilePath)
        {
         //// Set file permission to delete file
            FileAttributes attributes = File.GetAttributes(FilePath);
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                attributes &= ~FileAttributes.ReadOnly;
                File.SetAttributes(FilePath, attributes);
                File.Delete(FilePath);
            }
            else
            {
                FileInfo f = new FileInfo(FilePath);
                if (f.Exists)
                {
                    File.SetAttributes(FilePath, FileAttributes.Normal);
                    File.Delete(FilePath);
                }
            }
        }

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...