We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Free file handle on some methods

I just get a quite simple problem, but really annoying to debug in a Asp.Net implementation on network share (UNC) files paths.

I’m using Aspose.Pdf.Facades.PdfFileInfo to get page number of a pdf file, to show a asp.net wizard before merging documents.
this method don’t free the file handle between two asp.net page life cycle :

public static int GetPDFInfosAspose(string strFile)
PdfFileInfo info = new PdfFileInfo(strFile);
return info.NumberOfPages;

I have a workaround, using the “using” statement and a Stream :
public static int GetPDFInfosAspose(string strFile)
using (Stream fstr = File.OpenRead(strFile))
PdfFileInfo info = new PdfFileInfo(fstr);
return info.NumberOfPages;

But really :
Can you close your handles, or provide a IDisposable implementation for this class capable to free it ?

That’s not the first time I’ve problems with file handle in your products. Please take care about that.

Network share path are very more problematic with handles than local disk paths, as the SMB2 optlock function don’t release locks because the garbage collector don’t Close/Dispose the Stream explicitly before a while.
In this case, the wizard display the information, and after validation the file can well be overwritten, because the optlock is the same between your the PdfFileInfo stream and my File.Write stream. But on the next merge, my new File.Write will fail because the optlock identifier will be different (another asp.net page life cycle) than yours which stayed open from the previous page life cycle.


Hi Delarue,

Thanks for contacting support.

Did you try using info.Close(); method which deinitializes the instance and resources. I have also tried testing the scenario using following simple code and as per my observations, the PDF file is being deleted. I have tested the scenario with Aspose.Pdf for .NET 7.6.0.


PdfFileInfo info = new

  • Copy.pdf");<o:p></o:p>


File.Delete("c:/pdftest/template - Copy.pdf");


We are sorry for your inconvenience.

The Close() method don’t exist in the Aspose.Pdf 6.8 version I’m working on. This is a good news that you implement it.

As I note in my initial post, the problem is mainly reproducible in a asp.net environment with unc path, across 2/3 page life cycle. I agree this is not easily reproducible.

This post was mainly for a general warning about handle/resource freeing in some of your developments.

Hi Delarue,

Please try using the latest release version of Aspose.Pdf for .NET 7.6.0 and in case you still face the same problem or you have any further query, please feel free to contact. We are sorry for this inconvenience.

PS, I am afraid we might not be able to fix the issues in older release versions.