By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Try Catch not working

P: n/a
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

Nov 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
-------------------------------------------------------
<j.***@juno.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
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

Nov 9 '06 #2

P: n/a
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.***@juno.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
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

Nov 9 '06 #3

P: n/a
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


Alvin Bruney [MVP] wrote:
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
-------------------------------------------------------
<j.***@juno.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
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
Nov 10 '06 #4

P: n/a
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
-------------------------------------------------------
"bruce barker (sqlwork.com)" <b_*************************@sqlwork.comwrote
in message news:uJ**************@TK2MSFTNGP03.phx.gbl...
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.***@juno.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>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


Nov 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.