What was the exception?
I bet the reason is
not inside this piece of code that deals with document protection:
Code:
PdfSecuritySettings securitySettings = document.SecuritySettings;
securitySettings.UserPassword = UserPassword;
securitySettings.OwnerPassword = OwnerPassword;
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotations = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = false;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = false;
Most probably the reson is that ASPNET account don't have a permission to write to that folder you specified.