Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi Everyone..
 
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?
Posted 4-Oct-12 23:39pm
Comments
aspnet_regiis at 5-Oct-12 5:41am
   
Everything is possible. But first tell me why do you need it. I smell something malicious ...
krushna chandra jena at 5-Oct-12 5:47am
   
@aspnet_regiis i need it because in my application when the user will run the program then i will check some information , and those information will be kept in that file
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can't create a file which is unopenable - any file can be opened as a stream of bytes.
 
However, it may be that you want the file unreadable, so just encrypt it: System.Security.Encryption holds many methods for doing that: http://www.c-sharpcorner.com/uploadfile/puranindia/system-security-cryptography-namespace-in-net/[^]
  Permalink  
Comments
krushna chandra jena at 5-Oct-12 6:09am
   
the point is clear to me but one more question i have that if i want to make the file non editable then what i have to do ?
OriginalGriff at 5-Oct-12 6:20am
   
Non-editable is the same problem - it depends on what programs people have. For example, I have a text editor (which replaces Notepad) called PSPad which looks the the file content I ask it to open and will open it in an appropriate manner - if it is a binary file, it uses it's Hex editor mode. If it is HTML it loads HTML syntax colouring, and so forth.
 
You can't really make any file which is readable non-editable, althouigh you can make it read-only which means that any changes can't be saved.
 
What are you trying to do? It may be that there is a better way to solve your problem than the route you are going down.
krushna chandra jena at 5-Oct-12 6:39am
   
In the application when the user will run the program i will check some information ( like Mac address) , and kept it inside the file , and make it non editable because for second time i have to check user authentication from the data of that text file . it is important to my application . if the file is editable then user can easily edit the file and my application will not work properly
OriginalGriff at 5-Oct-12 6:48am
   
AH! So stuff the user, let him change it. But detect the changes.
Just take his MAC Address and the name of your program, and any other info you want to, and generate the MD5 (or SHA) hash value from that. Store that in the file, instead of the MAC. Then when you check, generate the hash again, and compare that to the value in the file. If they match, all ok. If they don't...
 
It's just like the way you check a password - you don't store the password in clear text, you store a salted hash instead. That way, even if they access your password list, it is no use to them, because you can't work backwards from the stored value to the input password.
krushna chandra jena at 5-Oct-12 7:03am
   
ok , i got it ...
Thank You..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes Friend, it is possible . while creating the file create the extension as .xyz and for this extension any program will not be able to open the file and later you can delete the same
 
Thanks,
Ambesha
  Permalink  
Comments
krushna chandra jena at 5-Oct-12 5:53am
   
but if the file is opened by notepad then it easily opens , how can i prevent it
Ambesha at 5-Oct-12 6:07am
   
if you create the file with .xyz extension then you will not be able to open the file in notepad. because this extension is incompatible with notepad to perform any operation, create a file using notepad and save with abc.xyz or test.zzz kind of extension and then try to open it you will not be able to open the file with notepad even.
 
Thanks,
Ambesha
OriginalGriff at 5-Oct-12 6:16am
   
Um.
This turns out not to be the case.
Create a file with the extension ".xyz"
Open Windows Explorer in that folder. Right click the file name. On the list of options you will see "Open with...". You can then directly select any installed program, and if you want, make it the default for all ".xyz" files.
 
In addition, there are at least five programs I have met that use ".xyz" as a fiule extension, so if any of those are installed, they will try to open it...
krushna chandra jena at 5-Oct-12 6:14am
   
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string filepath = path + "\\myfile.xyz";
 
File.WriteAllText(filepath, "Hi..");
 
i have done this code......
here in desktop the file can be easily opened by notepad

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 350
1 Gihan Liyanage 332
2 OriginalGriff 236
3 ClimerChinna 222
4 vikinghunter 168
0 Sergey Alexandrovich Kryukov 8,298
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,005
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100