Reading Encrypted File Attribute

  • Thread starter Thread starter Debbie Carter
  • Start date Start date
D

Debbie Carter

Would anyone know how to read the file attributes of a file on the hard
drive to check if the file is encrypted or not? I have searched Visual
Studio Help and MSDN and the samples I have found do not work.

Any help would be appreciated.

I am using VB.NET
 
Debbie Carter said:
Would anyone know how to read the file attributes of a file on the hard
drive to check if the file is encrypted or not?

\\\
Imports System.IO
..
..
..
If File.GetAttributes(FileName) And FileAttributes.Encrypted) =
FileAttributes.Encrypted Then
...
End If
///
 
Hello Herfried,
Thank you for your help but I have been trying this and it does not
work. Any other suggestions? Here is the function I have been using. This is
in a module. It always returns a false.

Imports System.IO
Public Function CheckEncrypt(ByVal fname As String)

Dim eFlag As Boolean = False

If (File.GetAttributes(fname) And FileAttributes.Encrypted) =
FileAttributes.Encrypted Then

eFlag = True

End If

Return eFlag

End Function

The file is one that I saved with cryptostream. Am I suppose to set the
encryption attribute when saving? I have even tried setting it using
File.SetAttributes(fname, File.GetAttributes(fname) Or
FileAttributes.Encrypted)

but it did not work either.

Thank you,

Debbie
 
Debbie Carter said:
I have been trying this and it does not
work. Any other suggestions? Here is the function I have been using. This
is
in a module. It always returns a false.

Imports System.IO
Public Function CheckEncrypt(ByVal fname As String)

The return value "should be" 'As Boolean' :-).
Dim eFlag As Boolean = False

If (File.GetAttributes(fname) And FileAttributes.Encrypted) =
FileAttributes.Encrypted Then

eFlag = True

End If

Return eFlag

End Function

'Encrypted' will only work if the encryption file attribute is set. It will
/not/ be set if the file /contains/ encrypted data, but it will be set if
the file /is/ encrypted.
The file is one that I saved with cryptostream. Am I suppose to set the
encryption attribute when saving? I have even tried setting it using
File.SetAttributes(fname, File.GetAttributes(fname) Or
FileAttributes.Encrypted)

ACK, this won't work. Documentation on 'File.SetAttributes' says "The
desired 'FileAttributes', such as 'Hidden', 'ReadOnly', 'Normal', and
'Archive'". From what I know, you will have to use p/invoke to set the
'Encrypted' file attribute. See (complete thread):

<URL:http://groups.google.de/groups?threadm=B78C26BF-B451-426F-9B84-4184892D5CF4@microsoft.com>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top