May 14, 2010 at 1:55 PM
Edited May 14, 2010 at 2:47 PM
can someone give me a hint what is a good way to copy files from physical harddrive to a .vhd file? (Maybe I have missed an example.)
What I need is a file including contents (for sure), but also attributes and security settings. (Actually a clone of the file.)
I tried this so far:
DiscUtils.Ntfs.NtfsFileSystem fs =
string sFileName = @"Test.txt";
FileAttributes fileAttributes = File.GetAttributes(sFileName);
System.Security.AccessControl.FileSecurity fileSecurity = File.GetAccessControl(sFileName);
byte fileContent = File.ReadAllBytes(sFileName);
using (Stream stream = fs.OpenFile(sFileName, FileMode.Create))
stream.Write(fileContent, 0, fileContent.GetLength(0));
My idea was to Create file in VHD, copy all contents. Afterwards read all attributes/security and set them.
The right way?