导出为PDF(XTRAReport DevExpress)错误:正由另一个进程使用

时间:2014-02-12 09:03:26

标签: vb.net devexpress xtrareport

我这里有这个代码,它将创建的XtraReport导出为PDF文件。但是我收到一条错误消息“正在被另一个进程使用。”

我有办法避免这个错误吗?我尝试使用System.IO.File.Delete删除该文件,但它不断收到错误消息。另外,考虑到我确实需要使用相同的文件名。

这是代码:

 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")

感谢您提前帮助。

1 个答案:

答案 0 :(得分:1)

在这种情况下,简单的解决方案是使用try catch处理代码中的异常,如果文件被锁定,则向用户提示解锁文件的消息。

按照以下链接检查文件是否正在使用

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

Checking if a file is in use without try catch?