Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

OpenXMLTemplates problem accessing the files as it's used by another process

$
0
0

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.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>