473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Try Catch not working

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
4 1819
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roger Redford | last post by:
Dear experts, I'm trying to learn java on my own. I picked up a sample online, but it is not compiling right: ------------------------------------------------ import java.io.*;
11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
12
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
7
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
4
by: garyusenet | last post by:
Hi I'm using the following code which is finally working. Public Class Form1 Shared ActElement As Object Shared ActFields As DataSet Public Sub SetActElement() Dim objApp As New Object
13
by: Bit byte | last post by:
Is there any way of retrievieng error information (say, from a 'global' or system wide) error object - when you are in a catch all statement block? Sometimes it cannot be helped, when something...
3
by: Michael C | last post by:
I'm writing an app on the PDA using C# with .net 1.1. It is all working well except in some cases a try catch is simply ignored and a totally different error is returned. I've got code like below...
4
by: cj | last post by:
my old code Try Dim sw As New System.io.StreamWriter(fileName, True) sw.WriteLine(strToWrite) sw.Close() Catch End Try my new code
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.