System.IO.IOException

Hello All,


I am facing with …
System.IO.IOException: The process cannot access the file ‘D:\Temp\istock_201602-00230.pdf’ because it is being used by another process.
at System.IO.Error.WinIOError(Int32 errorCode, String maybeFullPath)

Pdf pdf1 = new Pdf();

Section sec1 = pdf1.Sections.Add();
sec1.IsLandscape = true;
Aspose.Pdf.Generator.Image imagestnk = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image2 = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image3 = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image4 = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image5 = new Aspose.Pdf.Generator.Image(sec1);
Aspose.Pdf.Generator.Image image6 = new Aspose.Pdf.Generator.Image(sec1);

bool savepdf = false;

string temp = (tempFolder().Trim() != “” && isFolderExists(ClsMain.tempFolder()) ? tempFolder() : Path.GetTempPath());
string pdfimages = temp + (temp.Right(1) == “\” ? “” : “\”) + "images_CoverNote" + covernote_no.Trim() + “.pdf”;

string imgStnkName = getRandomFileName("imgstnk", “jpg”);
if (isFileExists(@imgStnkName)) fileDelete(@imgStnkName);
if (imgstnk != null)
{
File.WriteAllBytes(@imgStnkName, imgstnk);
imagestnk.ImageInfo.File = @imgStnkName;
sec1.Paragraphs.Add(imagestnk);
savepdf = true;
}

string imgName1 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName1)) fileDelete(@imgName1);
if (img1 != null)
{
File.WriteAllBytes(@imgName1, img1);
image1.ImageInfo.File = @imgName1;
sec1.Paragraphs.Add(image1);
savepdf = true;
}

string imgName2 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName2)) fileDelete(@imgName2);
if (img2 != null)
{
File.WriteAllBytes(@imgName2, img2);
image2.ImageInfo.File = @imgName2;
sec1.Paragraphs.Add(image2);
savepdf = true;
}

string imgName3 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName3)) fileDelete(@imgName3);
if (img3 != null)
{
File.WriteAllBytes(@imgName3, img3);
image3.ImageInfo.File = @imgName3;
sec1.Paragraphs.Add(image3);
savepdf = true;
}

string imgName4 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName4)) fileDelete(@imgName4);
if (img4 != null)
{
File.WriteAllBytes(@imgName4, img4);
image4.ImageInfo.File = @imgName4;
sec1.Paragraphs.Add(image4);
savepdf = true;
}

string imgName5 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName5)) fileDelete(@imgName5);
if (img5 != null)
{
File.WriteAllBytes(@imgName5, img5);
image5.ImageInfo.File = @imgName5;
sec1.Paragraphs.Add(image5);
savepdf = true;
}
string imgName6 = getRandomFileName(“img_”, “jpg”);
if (isFileExists(@imgName6)) fileDelete(@imgName6);
if (img6 != null)
{
File.WriteAllBytes(@imgName6, img6);
image6.ImageInfo.File = @imgName6;
sec1.Paragraphs.Add(image6);
savepdf = true;
}

pdf1.Save(@pdfimages);
using (Document imagesPdf = new Document(@pdfimages) → ERROR HERE
{
}

anybody please help?

thanks a lot

REgards
Win

Hi Win,


Thanks for your inquriy. Please note it is recommended to use use new generator(com.aspose.pdf) instead old generator(aspose.pdf), as it is more improved and efficient. Please check following documentation to convert an image to PDF using new generator, it will resolve the issue. However if the issue persist then please share your sample images here, we will look into the scenario and will provide you information accordingly.


Please feel free to contact us for any further assistance.

Best Regards,