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

Free Support Forum - aspose.com

The process cannot access the file because it is used by another process

Hi,

I am getting folloing error "The process cannot access the file because it is used by another process" when saving the PDF template information in byte format to TIFF using SaveAsTIFF() method using Aspose.PDF.dll(6.4.0.0). I am getting this error, when I save it for second time.

But the same is working fine with Aspose.PDF.Kit.dll.

Thanks in advance.

Hi Kishore,

Thanks for your interest in our products.

Can you please share some details regarding the template document and code snippet that you are using with Aspose.Pdf. However during my testing, I am unable to notice any problem when using the code snippet shared over SaveAsTIFF Method

We are really sorry for your inconvenience.

Thanks & Regards,

Hi Kishore,

Thank you for considering Aspose.Pdf for .NET.

I have tried replicating your issue at my end but I am unable to reproduce the issue. Please share your template PDF file and sample code to help us reproduce the issue at our end. This will help us figure out the issue soon.

Thank You & Best Regards,

Thanks for your quick reply. Here is my sample code.

/Get Form Template
byte[] btFormtemplate = objDMRDataAccess.GetFormTemplate(objDMRBusiness);

if (btFormtemplate != null)
{
//Convert Byte to Stream
MemoryStream stream = new MemoryStream(btFormtemplate);

//Create Aspose object to convert stream to TIFF
PdfConverter converter = new PdfConverter();
converter.BindPdf(stream);
converter.DoConvert();

//Create Directory
string strImage = Server.MapPath(@"Templates");
if (!Directory.Exists(strImage))
{
Directory.CreateDirectory(strImage);
}

//Convert Image to TIF
strImage += @"\" + ddlFormType.SelectedItem.Text.ToString()+ "_" + ddlYear.SelectedItem.Text.ToString();
string strFormTemplateURL = ConfigurationManager.AppSettings["FormTemplateURL"].ToString();
converter.SaveAsTIFF(strImage + ".tif");

Thanks for your quick reply. Here is my sample code.

Note: I am getting the error when this method is called for second time.

/Get Form Template
byte[] btFormtemplate = objDMRDataAccess.GetFormTemplate(objDMRBusiness);

if (btFormtemplate != null)
{
//Convert Byte to Stream
MemoryStream stream = new MemoryStream(btFormtemplate);

//Create Aspose object to convert stream to TIFF
PdfConverter converter = new PdfConverter();
converter.BindPdf(stream);
converter.DoConvert();

//Create Directory
string strImage = Server.MapPath(@"Templates");
if (!Directory.Exists(strImage))
{
Directory.CreateDirectory(strImage);
}

//Convert Image to TIF
strImage += @"\" + ddlFormType.SelectedItem.Text.ToString()+ "_" + ddlYear.SelectedItem.Text.ToString();
string strFormTemplateURL = ConfigurationManager.AppSettings["FormTemplateURL"].ToString();
converter.SaveAsTIFF(strImage + ".tif");

Hi Kishore,

Thanks for your feedback, this happens only when resultant file is open and code is executed again, then this error comes, "The process cannot access the file because it is used by another process". Might be this was happened in your case.

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Hi Kishore,

Thank you for sharing the code segement.

The code segement you shared works fine. However, if you are using the FileStream in your GetFormTemplate(objDMRBusiness) method then please make sure that you close the stream object after reading the file data. As this may cause this issue when you will access the file (which is already open in the FileStream) second time.

In case you still face any issue, please create a sample application and share with us to reproduce the issue.

Sorry for the inconvenience,