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

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...