Create and delete an unreadable file in c#

  • Thread starter Thread starter elgdav
  • Start date Start date
E

elgdav

Hello, is it possible in C# to create a file which is unreadable (i.e.
no program can open it at all) and also at a later point to delete it?
Thanks in advance.
 
Hello, elgdav!

e> Hello, is it possible in C# to create a file which is unreadable (i.e.
e> no program can open it at all) and also at a later point to delete it?
e> Thanks in advance.

create file, set access control to deny access for all users, before deleting the file set required access control
to delete the file. Only admin will be able to delete the file.

Why do you need such functionality?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
elgdav said:
Hello, is it possible in C# to create a file which is unreadable (i.e.
no program can open it at all)

Even garbage can be read by something, even if it has to be a hex editor.
So, no, you cannot create a file that cannot be read by anything. Can you
create random garbage? Yes. Can you create encrypted files that a person
cannot steal information from? Yes. Can you make it absoluletely impossible
for anyone to read it no matter what effort they put into it? No, esp. if
you put it on their machine.
and also at a later point to delete it?

Yes, you can delete files that you create, garbage or otherwise.

Hope this helps!


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
Thanks for the reply Vadym,

I'll use File.Create(string path) to create the file but what method
should I use to set the access control?

I am going to use the functionality to test a program I am developing
which is a bit like Windows Explorer. I need to check its capability to
handle an unreadable file.
 
Thanks for your reply cowboy, we might have our wires crossed here, I
don't want to encrypt the file i just want to set it so it is not read
accessable, in the same way as you can make a file not writeable, if
that makes sense.
 
Hello, elgdav!

e> I'll use File.Create(string path) to create the file but what method
e> should I use to set the access control?

File.SetAccessControl(...).
Take a look at ( http://msdn2.microsoft.com/en-us/library/system.io.file.setaccesscontrol.aspx )
for method docs. And here ( http://west-wind.com/weblog/posts/4072.aspx )
for the example howto set ACL ( access control lists ) on files.

e> I am going to use the functionality to test a program I am developing
e> which is a bit like Windows Explorer. I need to check its capability to
e> handle an unreadable file.

You can create such a file with the help of ordinary explorer and then manually set ACL on it.
Test your application and then modify ACL and delete the file...

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
I've noticed that File.SetAccessControl exists in .Net 2.0 but i need
this to be in Version 1.1

Thanks for any help
 
Thanks for your reply Vadym,
You can create such a file with the help of ordinary explorer and then manually set ACL on it.
Test your application and then modify ACL and delete the file...

This test needs to be automated and repeatable so has to be done by
software.
Take a look at ( http://msdn2.microsoft.com/en-us/library/system.io.file.setaccesscontrol.aspx )
for method docs. And here ( http://west-wind.com/weblog/posts/4072.aspx )
for the example howto set ACL ( access control lists ) on files.

These are .Net version 2 solutions, I am using version 1.1 (sorry I was
late telling you that)
Thanks for all your help, do you know of any way to accomplish this in
version 11 of the framework?

cheers

elgdav
 
Vadym Stetsyak said:
Hello, elgdav!

Then you will have to use native API and P/Invoke to set ACLs.

Take a look at ( http://www.codeproject.com/dotnet/SecureRegistryKey.asp )

Although this articles talks about registry keys, the same is valid for
files ( in the ACL context )

Actually you should create the file with the ACL in one step by p/invoke
CreateFile API and supply the security descriptor.

Use a permission of:
CREATOR/OWNER => Delete
 
Back
Top