The process cannot access the file because it is being used by another
process when replacing a pdf file
I am trying to use the code to replace a file if it exists and I am
getting the error that The process cannot access the file because it is
being used by another process. I am not sure what has a lock on it? Is
there something in my code below I need to clear?
Dim Doc1 As New Document
Dim path As String = "\\server\pdfs\"
Dim myUniqueFileName = String.Format("{0}.pdf", Session("FileName"))
If (Not System.IO.Directory.Exists(path & myUniqueFileName)) Then
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(Doc1, New
FileStream(path & myUniqueFileName, FileMode.Create))
Doc1.Open()
Dim test As String
test = Session("PDF")
Dim PDFHeader As String
PDFHeader = Session("Header")
Dim imagepath As String = Server.MapPath(".") & "/images/Header.png"
Dim image As iTextSharp.text.Image =
iTextSharp.text.Image.GetInstance(imagepath)
image.ScalePercent(70.0F)
Dim line1 As New iTextSharp.text.pdf.draw.LineSeparator(0.0F,
100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)
Doc1.Add(image)
Doc1.Add(New Paragraph(PDFHeader))
Doc1.Add(New Chunk(line1))
Doc1.Add(New Paragraph(test))
Doc1.Close()
End If
No comments:
Post a Comment