I have an issue while trying to create PDF from a newly created word file. I open a template file using the OpenXMLTemplate sdk replace the variables and save it into a new directory using ".SaveAs()" function.I also Dispose of the TemplateDocument however the error appears.
var uploadPath = _webHostEnvironment.WebRootPath + atta.AttachmentPath; using var doc = new TemplateDocument(uploadPath); var data = await CreateDictionary(reservation); var src = new VariableSource(data); var engine = new DefaultOpenXmlTemplateEngine(); engine.ReplaceAll(doc, src); var path = await SaveFile(doc, reservation, 4,attachmentName); doc.SaveAs(path); doc.Dispose(); //GeneratePDF await CreatePDF(path); private async Task CreatePDF(string path) { Document docs = new Document(); // Load a Word document docs.LoadFromFile(path); // Save the document to PDF docs.SaveToFile("reservation.pdf", FileFormat.PDF); // Dispose resources docs.Dispose(); }'The process cannot access the file 'C:\Repos\AirBnB\App\wwwroot\Upload\Reservation\1\reservation.docx' because it is being used by another process.' .
I have also tried using .Close() at the end but this wouldn't work as well.