Is there a library method somewhere for figuring out whether a file has been encrypted with EFS? I see the Encrypt()
and Decrypt()
methods on FileInfo, but am looking for a way to query a file's state.
Asked
Active
Viewed 3,838 times
3

Matt
- 31,662
- 4
- 34
- 33
2 Answers
6
To expand on bdolan & matt's comment:
<snip>
using System.IO;
<snip>
FileInfo fi = new FileInfo(uri); //uri is the full path and file name
if (fi.Attributes.HasFlag(FileAttributes.Encrypted))
{
//FILE IS ENCRYPTED
}
else
{
//FILE IS SAFE
}

Atron Seige
- 2,783
- 4
- 32
- 39
5
Use GetFileAttributes()
, and check for FILE_ATTRIBUTE_ENCRYPTED
.

bdonlan
- 224,562
- 31
- 268
- 324
-
1I was looking for a .net answer, but it turns out that it is similar to your suggestion: use FileInfo.Attributes and check for FileAttributes.Encrypted – Matt Oct 23 '09 at 17:56
-
Ah, sorry, missed your C# tag. Good to hear you found an answer though :) – bdonlan Oct 23 '09 at 19:14