Try Catch not working

J

j.t.w

Hi everyone,

I am trying to error trap for an invalid file name. When an invalid
file name is given, a message box saying "Cannot find
'file:///F:/Invoice/111.tif'. Make sure the path of Internet address is
correct.".

How can I go about redirecting to another page should an invalid file
name be given? Or can I run some other code to go look up in a database
the location of the file?

Here is the code I am working with...

Protected Sub SearchButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles SearchButton.Click
Dim ImageString As String

Select Case ImageTypeRadioButtonList.SelectedItem.ToString
Case "AWB"
ImageString = "<script>window.open('F:/AWB/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
Case "Invoice"
'ImageString = "<script>window.open('F:/Invoice/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
Case "Voucher"
ImageString = "<script>window.open('F:/Voucher/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
End Select
ImageTextBox.Text = ""
ImageTextBox.Focus()

Try
Response.Write(ImageString)
Response.Write("<script
language='javascript'>history.back()</script>")
Catch ex As Exception
Response.Redirect("http://www.google.com")
Finally

End Try
End Sub

Thanks for your help in this matter.
j.t.w
 
A

Alvin Bruney [MVP]

You won't be able to catch it on the code behind because it is trying to
open a file on the client. You'd need to wrap the code in a try/catch script
block. The basic syntax is the same but the exception code would need to be
placed inside the script tags.

You do realize that according to your code, you are trying to open a file on
the user's desktop and not on the server right?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
B

bruce barker \(sqlwork.com\)

you are doing the catch on the server, when the error in on the client. as
its a page not found error, there is no way to catch it.

-- bruce (sqlwork.com)
 
J

j.t.w

Thanks for your reply.

This page is running on our Intranet, so I guess that's why it was
running. I've changed it so that the page retrieves the file from the
server. Thanks for the heads up.

Now it reads...
ImageString = "<script>window.open('file://MyServer/AWB/" +
ImageTextBox.Text + ".tif', '_blank');</script>"

Can you show me how to place the code between script tags? I've tried a
couple of different ways but it doesn't seem to work.

Thanks,
j.t.w



You won't be able to catch it on the code behind because it is trying to
open a file on the client. You'd need to wrap the code in a try/catch script
block. The basic syntax is the same but the exception code would need to be
placed inside the script tags.

You do realize that according to your code, you are trying to open a file on
the user's desktop and not on the server right?

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


Hi everyone,

I am trying to error trap for an invalid file name. When an invalid
file name is given, a message box saying "Cannot find
'file:///F:/Invoice/111.tif'. Make sure the path of Internet address is
correct.".

How can I go about redirecting to another page should an invalid file
name be given? Or can I run some other code to go look up in a database
the location of the file?

Here is the code I am working with...

Protected Sub SearchButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles SearchButton.Click
Dim ImageString As String

Select Case ImageTypeRadioButtonList.SelectedItem.ToString
Case "AWB"
ImageString = "<script>window.open('F:/AWB/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
Case "Invoice"
'ImageString = "<script>window.open('F:/Invoice/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
Case "Voucher"
ImageString = "<script>window.open('F:/Voucher/" +
ImageTextBox.Text + ".tif', '_blank');</script>"
End Select
ImageTextBox.Text = ""
ImageTextBox.Focus()

Try
Response.Write(ImageString)
Response.Write("<script
language='javascript'>history.back()</script>")
Catch ex As Exception
Response.Redirect("http://www.google.com")
Finally

End Try
End Sub

Thanks for your help in this matter.
j.t.w
 
A

Alvin Bruney [MVP]

If the file is on the server, use the code behind and the file exist method
to determine if the file is available. I think that's what you want.
Construct your script appropriately.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top