PowerBuilder Classic Webform - Generate XPS file - Mail as SMTP attachment
I have a PowerBuilder 12.5 Classic Webform that generates online receipts and emails them as PDF files via SMTP.
Now I want to have the same application generate the receipts and email them as XPS files via SMTP.
Current methodology is to populate a data window and use dw_1.SaveAs(filename,PDF!,false). But the PowerBuilder 12.5 SaveAs command does not support XPS! as a file type.
So somehow, we have to print to the Microsoft XPS Printer Driver on the IIS Server (I think).
I do NOT know if this can be done.
I am open to any workaround that works and results in the user immediately getting their receipt as an email attachment.
I tried to create a PB 12.5 .NET Assembly but my code complained roundly when I tried to use. I think PB 12.5 .NET Print may use SaveAs(filename,XPS!,false) in the background. If it is not PB 12.5, then maybe it is PB 12.5 WCF (not that I have used it.)
1) Server is IIS 7.5 - I may need some help configuring it via GoToMeeting
2) The functionality for sending the files as PDF stopped working. I don't know if I screwed up the code or if I screwed up the server.
Here is the code that I am currently using and it does NOT work.
company = dw_1.getitemstring(1,'company')
email = trim(sle_1.text)
If email = '' then
mle_1.text = 'ERROR: YOU MUST ENTER A VALID EMAIL ADDRESS IN THE FIRST EMAIL FIELD'
If email <> '' then
if match(email,'^[a-zA-Z0-9][a-zA-Z\0-9\-_\.]*[^.]\@[^.][a-zA-Z\0-9\-_\.]+\.[a-zA-Z\0-9\-_\.]*[a-zA-Z\0-9]+$') then
mle_1.text = 'EMAIL IS NOT FORMATTED CORRECTLY'
bodytext = 'Dear Valued Client, ' + '~r~n' + '~r~n' + 'Please find attached the requested receipt in XPS format.' + '~r~n' + '~r~n' + 'Thank you,' + '~r~n' + '~r~n' + 'Billing Department' + '~r~n' + '1-999-999-9999'
sTripDate = string(tripdate)
sTripDate = left(sTripdate,2) + '-' + mid(sTripdate,4,2) + '-' + right(sTripdate,4)
//create the path to use LATER for the attachment
#if defined PBWEBFORM then
filepathname = MapVirtualPath('c:\Receipt For-' + lname + '-Confo-' + voucherconfo + '.xps')
//create the path and filename to use NOW to distill and save the file in the virtual directory
filename = 'c:\Receipt For-' + lname + '-Confo-' + voucherconfo + '.xps'
dw_1.object.DataWindow.Print.PrinterName = 'Microsoft XPS Document Writer'
dw_1.Object.DataWindow.Print.Filename = filename
dw_1.Print( FALSE, FALSE)
subject = 'Receipt for ' + lname + ' for Trip: ' + voucherconfo
fromaddresstext = 'firstname.lastname@example.org'
#if defined PBWEBFORM then
message = create System.Net.mail.MailMessage
message.subject = subject
message.body = bodytext
fromaddress = create System.Net.Mail.MailAddress('email@example.com', 'Billing Department')
message.From = fromAddress
attach = create System.Net.Mail.Attachment(filepathname,'application/xps');
smtpclient = create System.Net.Mail.SmtpClient
smtpclient.host = 'webapp.xxx.com'
smtpclient.port = 25
CATCH (System.Net.Mail.SmtpException ex2 )
MessageBox( 'SMTP Error', 'Sorry. There is a problem sending the receipt email. ' + ex2.Message )
mle_1.text = 'Your receipt has been emailed to the requested recipient at ' + email