Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 15th, 2010, 07:03 PM
Fed Fed is offline
Authorized User
 
Join Date: Oct 2009
Posts: 55
Thanks: 26
Thanked 0 Times in 0 Posts
Default Exception Handling

Imar,

I'm stuck again...

I wanted to handle the exception generated if/when there is a problem with the mail server as depicted in your 3.5 book to the file share app but ran into a problem.

The file share uses a VB standalone program not an aspx code behind.

File share uses this method for diplaying a successful mail sent;

ASPX VB
Code:
 'send an email to the recipient...
            Utilities.SendEmail(txtRecipientEmail.Text, _
                txtSenderEmail.Text, Config.EmailSubject, emailBody)
            Server.Transfer("UploadComplete.aspx", True)
The above UploadComplete.aspx is a page that says 'message sent' and notice how he uses the Server.Transfer to display the page.

So in the interest of not rewriting the file share I figured I could use the same system and mad an UploadIncomplete.aspx that says 'message not sent', but when I created the Try, Catch in the standalone VB I discovered that Server.Transfer does not work.

VB
Code:
''' <summary>
    ''' SendEmail is used to send an email with the established settings and parameters
    ''' </summary>
    Public Shared Sub SendEmail(ByVal MsgTo As String, ByVal MsgFrom As String, ByVal MsgSubject As String, ByVal MsgText As String)
        Dim SmtpSettings As MailSettings
        SmtpSettings = GetSmtpSettings()
        Dim SmtpCl As New SmtpClient(SmtpSettings.MailServer, SmtpSettings.MailPort)
        SmtpCl.Credentials = GetCredentials(SmtpSettings)
        Dim MailMsg As New MailMessage(MsgFrom, MsgTo)
        MailMsg.Subject = MsgSubject
        MailMsg.Body = MsgText
        Try
            SmtpCl.Send(MailMsg)
        Catch ex As Exception
            Server.Transfer("UploadIncomplete.aspx", True)
        End Try

    End Sub
My question, is there a quick and dirty way for me to accomplish this?

Thanks,

Fed
  #2 (permalink)  
Old February 15th, 2010, 07:11 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yeah, Server is an object that only exists in ASP.NET. "Server" means the web server, usually IIS.

For standalone apps, you just have to invoke a method in your catch handler.

But, really, you probably didn't need to create a completely separate class if all you wanted to do was display an "oops, it didn't work" message. Could have done something as simple as
Code:
     Catch ex As Exception
        MsgBox( "Unable to send email to " & MsgTo & ", reason: " & ex.toString() )
But you could make any call you wished there in place of MsgBox.
The Following User Says Thank You to Old Pedant For This Useful Post:
Fed (February 16th, 2010)
  #3 (permalink)  
Old February 16th, 2010, 12:25 PM
Fed Fed is offline
Authorized User
 
Join Date: Oct 2009
Posts: 55
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Thanks, I thought it was something like that. Is there a corresponding object that does the same thing in VB?
  #4 (permalink)  
Old February 16th, 2010, 04:24 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Short answer: No.

In a normal executable program, you don't have the concept of "pages" that you do with an internet system.

You could, of course, simply wipe out all content on the user's screen and replace it with a message. Essentially, that's what loading a new page into a browser does: All prior window content simply goes away and is replaced by the new content. Surely you can do something more elegant in a standalone app.
The Following User Says Thank You to Old Pedant For This Useful Post:
Fed (February 16th, 2010)
  #5 (permalink)  
Old February 16th, 2010, 05:49 PM
Fed Fed is offline
Authorized User
 
Join Date: Oct 2009
Posts: 55
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Thanks at least I know what direction to go in. Just started learning so a lot of stuff has yet to sink in... :)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception handling codehelp C# 2008 aka C# 3.0 4 August 27th, 2009 07:46 AM
Exception Handling NewTitle2007 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 August 8th, 2007 04:03 AM
Exception handling aldwinenriquez General .NET 0 August 17th, 2005 06:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.