0

I have this code here that exports the XtraReport created to PDF File. But I get an error message that says "It is being used by another process."

Is there a way for me to avoid this error? I tried deleting the file by using System.IO.File.Delete but it keeps getting the error message. Also, considering that I really need to use the same file name.

here's the code:

 Dim ReturnText As String = ""

    Dim dtReport As DataTable = Nothing

    Dim dtRows() As DataRow = Nothing

    Dim XRPath As String = "reports/travel.repx"

    Dim XRSubPath As String = "reports/travel_costallocation.repx"

    Dim SQL As String = String.Empty

    Dim xrBandTag As String = String.Empty

    Dim xrGroupField As GroupField = Nothing

    Dim xrProtectBands As String = "[BottomMargin][PageFooter][PageHeader][ReportHeader]"

    Dim xrFilename As String = String.Empty

    Dim xParams As Integer = 0

    Dim dAccessTo As DataTable = Nothing

    Dim bUpdate As Boolean = False

    Dim ReportID As Integer = 0

    Dim ReportData() As Object = Nothing

    Dim Value() As String = Nothing

    Dim xrReport As XtraReport = Nothing

   'manipulate report here

 xrReport.ExportToPdf(ServerPath & "\documents\travelpdf\eTravelNo_" & PathID & ".pdf")

Thank you for the advance help.

bluejaded
  • 71
  • 6

1 Answers1

1

In this case simple solution is you handle exception in code with try catch and if file is locked then prompt message to user that unlock file.

Follow below links to check if file is in use or not

Is there a way to check if a file is in use?

Checking if a file is in use without try catch?

Community
  • 1
  • 1
Jaynesh Shah
  • 158
  • 1
  • 1
  • 14