manared
Well-known member
- Joined
- Jun 1, 2006
- Messages
- 84
- Programming Experience
- 1-3
I'm getting this error:
The process cannot access the file 'C:\Inetpub\Programs\TestQSservice\Reports\Quote.pdf' because it is being used by another process.
I'm not sure how to fix it right now. It's erroring on this line:
Rep.Export(opt)
Here's my code (VS 2008, .NET 3.5)
Doing the Rep.Close() and Rep.Dispose(), I thought it would've gotten rid of this error, but I'm still getting it. Does anyone know why or how I can fix it? Thank you very much!!!
The process cannot access the file 'C:\Inetpub\Programs\TestQSservice\Reports\Quote.pdf' because it is being used by another process.
I'm not sure how to fix it right now. It's erroring on this line:
Rep.Export(opt)
Here's my code (VS 2008, .NET 3.5)
VB.NET:
Imports DWITools
Imports System.Data.SqlClient
Imports JobMastModel.DBClasses
Imports DWIBussinessObject
Partial Class _Default
Inherits System.Web.UI.Page
Dim strsql As String
Private dbTools As New DBTools
Dim DBObj As New JobMastModel.DBClasses.DBTools
Dim msg, number As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim exportDT As Data.DataTable
Dim ready, pending As String
ready = "ready"
pending = "pending"
exportDT = DBObj.CreateDT("Select * from tblQSOrders WHERE (ExportStatus = '" & ready & "')", JobMastModel.DBClasses.DBTools.DB.DW)
Dim x As Integer = exportDT.Rows.Count - 1
Dim y As Integer
Dim ObjOrder As DWIBussinessObject.QuikShipOrder = New QuikShipOrder
For y = 0 To x
Dim path, fileplace As String
path = ""
fileplace = ""
If exportDT.Rows(y).Item("IsQuote") = True Then
'Export Quote
Dim orderID As Integer = exportDT.Rows(y).Item("OrderID")
Dim quoteNo As String = 2
'update tblQSOrders table
Dim exportStatus, open As String
exportStatus = "QuoteExported"
open = "Open"
'strsql = "Update tblQSOrders set ExportStatus = '" & exportStatus & "', QuoteNo = '" & quoteNo & "', Status = '" & open & "', ExportDate = '" & DateTime.Now & "' WHERE (OrderID = '" & orderID & "')"
'Session("DBTools").ExecuteNonQuery(strsql, JobMastModel.DBClasses.DBTools.DB.DW)
DBObj.DBConnMain.JMConnection.Close()
'export file
path = Request.PhysicalApplicationPath & "\Reports\QuoteDetail.rpt"
fileplace = Request.PhysicalApplicationPath & "Reports\Quote.pdf"
Dim dt2 As Data.DataTable = New Data.DataTable
Dim v As String = "009368"
dt2 = dbTools.CreateDT("select * from vDWCustomerQuotes where QuoteNo = '" & v & "'", DBLayer.DBTools.DB.M2M)
ExportReport_PDF(path, dt2, fileplace)
'send email (create pdf of acknowledgement form)
Dim custEmail As String = exportDT.Rows(y).Item("CustomerEmail")
CreateMsg(custEmail, fileplace, quoteNo, "Quote")
Else
'Export Order
Dim orderID As Integer = exportDT.Rows(y).Item("OrderID")
Dim SONo As String = 1
'update tblQSOrders table
Dim exportStatus, open As String
exportStatus = "OrderExported"
open = "Open"
'strsql = "Update tblQSOrders set ExportStatus = '" & exportStatus & "', SONo = '" & SONo & "', Status = '" & open & "', ExportDate = '" & DateTime.Now & "' WHERE (OrderID = '" & orderID & "')"
'Session("DBTools").ExecuteNonQuery(strsql, JobMastModel.DBClasses.DBTools.DB.DW)
DBObj.DBConnMain.JMConnection.Close()
'eport file
path = Request.PhysicalApplicationPath & "Reports\OrderDetail.rpt"
fileplace = Request.PhysicalApplicationPath & "Reports\Order.pdf"
Dim dt2 As Data.DataTable = New Data.DataTable
Dim v As String = "020303"
dt2 = dbTools.CreateDT("select * from vDWCustomerOrders where SONo = '" & v & "'", DBLayer.DBTools.DB.M2M)
ExportReport_PDF(path, dt2, fileplace)
'send email (create pdf of acknowledgement form)
Dim custEmail As String = exportDT.Rows(y).Item("CustomerEmail")
CreateMsg(custEmail, fileplace, SONo, "Order")
End If
Next
End Sub
Public Shared Sub ExportReport_PDF(ByVal ReportPath_Name As String, ByVal DT As Data.DataTable, ByVal FilePath_Name As String)
'load and create the report
Dim Rep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Rep.Load(ReportPath_Name)
Rep.SetDataSource(DT)
'create the destination option
Dim optdes As New CrystalDecisions.Shared.DiskFileDestinationOptions
optdes.DiskFileName = FilePath_Name
'create the export option
Dim opt As New CrystalDecisions.Shared.ExportOptions
opt.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
opt.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
opt.ExportDestinationOptions = optdes
'export
[B] Rep.Export(opt)[/B]
Rep.Close()
Rep.Dispose()
End Sub
Sub CreateMsg(ByVal custEmail As String, ByVal attachment As String, ByVal number As String, ByVal type As String)
msg = "A summary of your order is attached in a pdf file. "
If type = "Order" Then
msg += "<br />Your Sales Order Number is " & number
msg += "<br />Please keep this document for your records."
Else
msg += "<br />Your Quote Number is " & number
msg += "<br />Please keep this document for your records."
End If
msg += "<BR><BR>"
msg += "Thank you!"
msg += "<BR /><BR />"
msg += "<br /><br />"
msg += "<font size='2'>*This is an automated email. Please do not reply to this email address. For any questions, call or email Diversified. directly. Thank you.</font>"
Dim MailMsg As New Net.Mail.MailMessage
MailMsg.IsBodyHtml = True
MailMsg.Subject = "Quick Ship Acknowledgement Form"
MailMsg.From = New Net.Mail.MailAddress("sales@labsst.com")
MailMsg.Attachments.Add(New System.Net.Mail.Attachment(attachment))
MailMsg.To.Clear()
'MailMsg.To.Add(custEmail)
'create dt for admin that need to receive an email that a quote/order has been exported
Dim dtAdmin As Data.DataTable = New Data.DataTable
dtAdmin = DBObj.CreateDT("SELECT * FROM tblQSadmin", JobMastModel.DBClasses.DBTools.DB.DW)
Dim i As Integer = dtAdmin.Rows.Count - 1
Dim t As Integer
For t = 0 To i
'MailMsg.To.Add(dtAdmin.Rows(t).Item("email").ToString.Trim)
Next
MailMsg.To.Add("athorson@diversifiedwoodcrafts.com")
MailMsg.Body = msg
'Tools.SendEmail(MailMsg)
End Sub
End Class
Doing the Rep.Close() and Rep.Dispose(), I thought it would've gotten rid of this error, but I'm still getting it. Does anyone know why or how I can fix it? Thank you very much!!!