Search this blog

Monday, June 1, 2009

Update File attributes Readonly to normal mode thru C#

Here’s a nice little piece of code you can use to change file attributes of a particular file, its particularly useful when you’re trying to delete a read only file.

C# Code:

using System.IO;

string savedCardFilePath = "My absolute file path";

if (File.Exists(savedCardFilePath))

{

// Remove readonly attribute off of the file if it exists before execution

if (File.GetAttributes(savedCardFilePath) == FileAttributes.ReadOnly)

File.SetAttributes(savedCardFilePath, FileAttributes.Normal);

File.Delete(savedCardFilePath);

}

No comments:

Post a Comment