diff --git a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md index 0668a0a1b..1ffb4039c 100644 --- a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md +++ b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md @@ -851,4 +851,61 @@ Blink binaries (Version 109.0.5414.75), + + + +## There was an error opening this document. This file is already open or in use by another application. + +
| Issue | +There was an error opening this document. This file is already open or in use by another application. + | +
|---|---|
| Reason + | +The reported issue occurs due to the document or file not being properly disposed or closed, leading to conflicts when attempting to access it again. + | +
| Solution | ++ +We can resolve the reported issue by using the FileStream within the "using" block. +{% tabs %} +{% highlight C# %} + + using (FileStream fs = new FileStream("path_to_file", FileMode.Open)) + { + // Use the file here + } // File stream is automatically closed and disposed + +{% endhighlight %} +{% endtabs %} + +Or + +Dispose of the FileStream at the end of the process and ensure that the file or document is not already open in another application. +{% tabs %} +{% highlight C# %} + + + PdfDocument document = htmlConverter.Convert("); + + FileStream fileStream = new FileStream(baseUrl+ "Bill_PDF_04_16_24.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + + //Save and close the PDF document. + + document.Save(fileStream); + + document.Close(true); + + document.Dispose(); + + fileStream.Dispose(); + +{% endhighlight %} +{% endtabs %} + | +