Sounds like read-only files, right? well not really.
So my goal is to make a backup of all the files from an application I have build by simply compressing them to a .zip file.
First I collect all files and put them in another folder (I don't need to backup the .exe file for example). Then I compress them using IO.compression.ZipFile
ZipFile.CreateFromDirectory(backupDirectory, ZipDirectory);
Later, when user would like to restore a backup, I first delete the existing files and directories, then extract it:
ZipFile.ExtractToDirectory(openFileDialog1.FileName, installDirectory);
Problem: Files are now read-only, One file is a .mdf file, I cannot make changes to the tables anymore, which makes the app useless. I've tried doing this:
public void Recurse(DirectoryInfo directory)
{
foreach (FileInfo fi in directory.GetFiles())
{
//fi.Attributes |= FileAttributes.ReadOnly; //this didn't work eather
fi.IsReadOnly = false;
}
foreach (DirectoryInfo subdir in directory.GetDirectories())
{
Recurse(subdir);
}
}
from this question. Didn't work. And I don't expect it to work since the 'Read-only' flag is not checked on the .mdf properties. Also when looking into the Security tab:
SYSTEM, Admin and User are the same, what I am missing is the groupname 'Everyone' with all checks set to Allowed. After manually setting this group again, I see some improvements, however still getting other errors like unable to login, login failed for the user [current user]
Edit: issue with the above security tab was because I used that Recurse
method. Made things worse. So using the file.IsReadOnly = false
for all files is not a good solution.
Question: How do I correctly Compress and decompress files without changing it's attributes / settings / permissions. **Or: ** How do I set the correct attributes for the files again, after decompressing.