// I am creating file using file byte array, bind password to it and attached this file to email, i got below error
private string GetFilePath(string FileName,Byte[] fileBytes, string fileExtension)
{
string cfgTempDirectory = @“C:\temp”;
bool cfgEnablePasswordProtectedAttachment = false; //config
string tempSourceFile = “”;
string tempDestinationFile = “”;
string strcfgEnablePasswordProtectedAttachment = “”;
string AsposeLicenseFilePath = “”;
string UserPassword=“somepassword”;
fileExtension = fileExtension.Replace(".", "");
tempSourceFile = cfgTempDirectory + "\\PN" + Guid.NewGuid().ToString().Replace("-", "") + DateTime.Now.ToString("ddmmyyyHHmmssfff") + "." + fileExtension;
tempDestinationFile = cfgTempDirectory + "\\" + Path.GetFileNameWithoutExtension(FileName) + "_" + RandomNumber() + Path.GetExtension(FileName);
File.WriteAllBytes(tempSourceFile, fileBytes);
using (PdfFileSecurity fileSecurity = new PdfFileSecurity())
{
fileSecurity.BindPdf(tempSourceFile);
fileSecurity.EncryptFile(UserPassword, "somekey", DocumentPrivilege.Print, KeySize.x256, Algorithm.AES);
fileSecurity.Save(tempDestinationFile); /// error in this line, System.IO.IOException: The process cannot access the file 'F:\somefolder\Attachment\77830_PMS_Order_CONFIRMATION_20211102172649293.pdf' because it is being used by another process.
}
}