I been trying to fix this problem for the whole day, but no matter what I do I keep on getting the same exception: UnauthorizedAccessException was unhandled at line
using (Package package = Package.Open(d.FullName, FileMode.Create, FileAccess.ReadWrite))
The full code is:
NTAccount act = new NTAccount("c9lu-PC","c9lu");
DirectoryInfo d = System.IO.Directory.CreateDirectory(path);
DirectorySecurity security = d.GetAccessControl();
security.AddAccessRule(new FileSystemAccessRule(act,FileSystemRights.FullControl,InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
d.SetAccessControl(security);
using (Package package = Package.Open(d.FullName, FileMode.Create, FileAccess.ReadWrite)) // where the exception occurs
{
PackageHelper.createPart(package, "/pages.zip" , MediaTypeNames.Application.Zip,
(stream) =>
{
using (var parts = ZipPackage.Open(stream, FileMode.Create))
{
}
}
);
}
I really don’t know what the problem is, please help me out.
Could it have something to do with the fact that you’re passing in a directory into the first parameter of Package.Open instead of a file name? Should be more like this: