<%----%>
Parks and Trails New York About Us Join/Renew Donate Publications By Cycling Guide News Room E-News Contact Canalway Trail Greenways and Trails Parks and Trails Advocacy Find a Trail Bike Tours Donate Keep Informed -Sign up for Free E-News
 Search Results

- Show/Hide Parking Areas
(Visible when zoomed in)
 Bicyclists Welcome! B&Bs  
- Show/Hide B&Bs

 Directions   
Directions available from trail parking areas and B&B's
 Find a Trail

Trail Name

Select Allowable Use*
Select Surface Type*
Length
Distance
Within    Miles
Of Zipcode: 
* You may also enter a city and state instead of a zipcode.
   
 
* To choose multiple use types or multiple surface types hold down the control key while selecting your choices.
 Map Search
* Search the map for any of the following categories.
Map Legend
 
- Trail
 
 
- On Road Segment
 
 
- Proposed Trail
 
 
- Trail Center Point
 
 
- Selected Trail
 
 
- Bed & Breakfasts
 
 
- Parking Areas
 
Imports System.Data.OleDb Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Implements System.Web.UI.ICallbackEventHandler Private _callbackArg As String Public TrailResults As StringBuilder Public TrailBounds As StringBuilder Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not Page.IsPostBack) And (Not Page.IsCallback) Then If Session("TRAIL_RESULTS") IsNot Nothing Then TrailResults = Session("TRAIL_RESULTS") End If Dim cm As ClientScriptManager = Page.ClientScript Dim cbReference As String cbReference = cm.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "") Dim callbackScript As String = "" callbackScript &= "function CallServer(arg, context)" & "{" & cbReference & "; }" cm.RegisterClientScriptBlock(Me.GetType(), "CallServer", callbackScript, True) Dim cbReference2 As String cbReference2 = cm.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "") Dim callbackScript2 As String = "" callbackScript2 &= "function CallServer2(arg, context)" & "{" & cbReference2 & "; }" cm.RegisterClientScriptBlock(Me.GetType(), "CallServer2", callbackScript2, True) Dim cbReference3 As String cbReference3 = cm.GetCallbackEventReference(Me, "arg", "ReceiveServerData2", "") Dim callbackScript3 As String = "" callbackScript3 &= "function CallServer3(arg, context)" & "{" & cbReference3 & "; }" cm.RegisterClientScriptBlock(Me.GetType(), "CallServer3", callbackScript3, True) Dim cbReference4 As String cbReference4 = cm.GetCallbackEventReference(Me, "arg", "ReceiveServerData2", "") Dim callbackScript4 As String = "" callbackScript4 &= "function CallServer4(arg, context)" & "{" & cbReference4 & "; }" cm.RegisterClientScriptBlock(Me.GetType(), "CallServer4", callbackScript4, True) End If End Sub 'Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult 'End Function 'Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent 'End Sub Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _ Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent TrailBounds = Nothing TrailResults = Nothing ' break out the responseString into a querystring Dim keyValuePairs As Array = eventArgument.Split("&".ToCharArray()) Dim m_queryString As New NameValueCollection() Dim keyValue() As String Dim response As String = "" If keyValuePairs.Length > 0 Then Dim i As Integer For i = 0 To keyValuePairs.Length - 1 keyValue = keyValuePairs.GetValue(i).ToString().Split("=".ToCharArray()) Dim sMyVal As String = keyValue(1) If (sMyVal.IndexOf("x99x") <> -1) Then sMyVal = sMyVal.Replace("x99x", "&") End If If (keyValue.Contains("zoomNow")) Then GetBounds(keyValue(1)) Exit Sub ElseIf (keyValue.Contains("zoomNow2")) Then GetBounds2(keyValue(1)) Exit Sub End If m_queryString.Add(keyValue(0), sMyVal) Next i Else keyValue = eventArgument.Split("=".ToCharArray()) If keyValue.Length > 0 Then Dim sMyVal As String = keyValue(1) If (sMyVal.IndexOf("x99x") <> -1) Then sMyVal = sMyVal.Replace("x99x", "&") End If m_queryString.Add(keyValue(0), sMyVal) End If End If ' isolate control type and mode Dim sSQLBasic As String = "SELECT TRAILS.NAME, TRAILS.TRAILID FROM TRAILS " Dim sOrderBy As String = "ORDER BY TRAILS.NAME;" Dim sSQLBody As String = "SELECT TRAILS.NAME, TRAILS.TRAILID FROM " Dim sWhereClauseStart As String = "WHERE (" Dim sWhereClause As String = "" Dim sWhereClauseEnd As String = ") " 'Dim sRegion As String = "" Dim sRegionSQL As String = "" 'Dim sUse As String = "" Dim sUseSQL As String = "" 'Dim sSurface As String = "" Dim sSurfaceSQL As String = "" 'Dim sLengthType As String = "" Dim sLengthTypeSQL As String = "" 'Dim sMiles As String = "" 'Dim sMilesSQL As String = "" Dim sNameSQL As String = "" Dim sUseType As String = "" Dim sSurfaceType As String = "" Dim sLengthType As String = "" 'Dim sMiles As String = "" Dim sMaxLat As String = "" Dim sMinLat As String = "" Dim sMaxLng As String = "" Dim sMinLng As String = "" Dim sTrailName As String = "" sUseType = m_queryString("useType") sSurfaceType = m_queryString("surfaceType") sLengthType = m_queryString("lengthType") 'sMiles = m_queryString("miles") sMaxLat = m_queryString("maxLat") sMinLat = m_queryString("minLat") sMaxLng = m_queryString("maxLng") sMinLng = m_queryString("minLng") sTrailName = m_queryString("trailName") 'Create a connection string Dim connString As String Dim servPath As String = Server.MapPath(".") connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _ servPath & "\App_Data\Trails.mdb;" 'Open a connection Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() ''Specify the SQL string 'Dim strSQL As String = "SELECT TRAILS.NAME, TRAILS.TRAILID FROM TRAILS WHERE (((TRAILS.X > " & sMinLng & ") AND (TRAILS.X < " & sMaxLng & ")) AND ((TRAILS.Y > " & sMinLat & ") AND (TRAILS.Y < " & sMaxLat & "))) ORDER BY TRAILS.NAME;" Dim lookupCode As Integer = 0 Dim iLevel As Integer = 0 If sTrailName <> "" Then sWhereClause = "TRAILS.NAME='" & sTrailName.Replace("'", "''") & "' " GoTo SKIPTO Else If sUseType Is Nothing Then sUseSQL = "" ElseIf String.IsNullOrEmpty(sUseType) Then sUseSQL = "" Else sUseSQL = "INNER JOIN TRAIL_USE ON TRAILS.TRAILID = TRAIL_USE.TRAILID) " & _ "INNER JOIN USE ON TRAIL_USE.USEID = USE.USEID " If (lookupCode = 1) Then sWhereClause = sWhereClause & "AND " End If sWhereClause = sWhereClause & "((USE.USEID) IN (" & sUseType & ")) " lookupCode = 2 End If If sSurfaceType Is Nothing Then sSurfaceSQL = "" ElseIf String.IsNullOrEmpty(sSurfaceType) Then sSurfaceSQL = "" Else sSurfaceSQL = "INNER JOIN TRAIL_SURFACE ON TRAILS.TRAILID = TRAIL_SURFACE.TRAILID) " & _ "INNER JOIN SURFACE ON TRAIL_SURFACE.SURFACEID = SURFACE.SURFACEID " If (lookupCode = 1) Or (lookupCode = 2) Then sWhereClause = sWhereClause & "AND " End If sWhereClause = sWhereClause & "((SURFACE.SURFACEID) IN (" & sSurfaceType & ")) " lookupCode = 3 End If If sLengthType Is Nothing Then sLengthTypeSQL = "" ElseIf String.IsNullOrEmpty(sLengthType) Then sLengthTypeSQL = "" ' ElseIf sMiles Is Nothing Then ' sLengthTypeSQL = "" ' ElseIf String.IsNullOrEmpty(sMiles) Then ' sLengthTypeSQL = "" Else If (lookupCode = 1) Or (lookupCode = 2) Or (lookupCode = 3) Then sWhereClause = sWhereClause & "AND " End If If Math.Sign(CInt(sLengthType)) > 0 Then sWhereClause = sWhereClause & "((TRAILS.LENGTH)>=" & CInt(sLengthType) & ") " ElseIf Math.Sign(CInt(sLengthType)) < 0 Then sWhereClause = sWhereClause & "((TRAILS.LENGTH)<" & CInt(sLengthType) * -1 & ") " End If End If ' '' '' ''If (sMinLat <> "") Then ' '' '' '' If (sWhereClause <> "") Then ' '' '' '' sWhereClause = sWhereClause & " AND" ' '' '' '' End If ' '' '' '' sWhereClause = sWhereClause & " (((TRAILS.X > " & sMinLng & ") AND (TRAILS.X < " & sMaxLng & ")) AND ((TRAILS.Y > " & sMinLat & ") AND (TRAILS.Y < " & sMaxLat & ")))" ' '' '' ''End If End If If (sWhereClause = "") And (sMinLat = "") Then Session("TRAIL_RESULTS") = Nothing Dim sScript2 As String = "" If (Not ClientScript.IsStartupScriptRegistered("myscript3")) Then ClientScript.RegisterStartupScript(Me.GetType, "myscript3", sScript2) End If Exit Sub End If 'Specify the SQL string Dim strSQL As String = "" If (lookupCode = 1) Or (lookupCode = 2) Or (lookupCode = 3) Then strSQL = sSQLBody If ((sRegionSQL <> "") And (sUseSQL = "") And (sSurfaceSQL = "") Or _ (sRegionSQL = "") And (sUseSQL <> "") And (sSurfaceSQL = "") Or _ (sRegionSQL = "") And (sUseSQL = "") And (sSurfaceSQL <> "")) Then iLevel = 1 strSQL = strSQL & "(TRAILS " strSQL = strSQL & sRegionSQL strSQL = strSQL & sUseSQL strSQL = strSQL & sSurfaceSQL ElseIf ((sRegionSQL <> "") And (sUseSQL <> "") And (sSurfaceSQL = "")) Then iLevel = 2 strSQL = strSQL & "(((TRAILS " strSQL = strSQL & sRegionSQL strSQL = strSQL & ") " strSQL = strSQL & sUseSQL ElseIf ((sRegionSQL <> "") And (sUseSQL = "") And (sSurfaceSQL <> "")) Then iLevel = 2 strSQL = strSQL & "(((TRAILS " strSQL = strSQL & sRegionSQL strSQL = strSQL & ") " strSQL = strSQL & sSurfaceSQL ElseIf ((sRegionSQL = "") And (sUseSQL <> "") And (sSurfaceSQL <> "")) Then iLevel = 2 strSQL = strSQL & "(((TRAILS " strSQL = strSQL & sUseSQL strSQL = strSQL & ") " strSQL = strSQL & sSurfaceSQL ElseIf ((sRegionSQL <> "") And (sUseSQL <> "") And (sSurfaceSQL <> "")) Then iLevel = 3 strSQL = strSQL & "(((((TRAILS " strSQL = strSQL & sRegionSQL strSQL = strSQL & ") " strSQL = strSQL & sUseSQL strSQL = strSQL & ") " strSQL = strSQL & sSurfaceSQL End If Else strSQL = sSQLBasic End If SKIPTO: If strSQL = "" Then strSQL = sSQLBasic End If If (sWhereClause <> "") Then strSQL = strSQL & sWhereClauseStart strSQL = strSQL & sWhereClause strSQL = strSQL & sWhereClauseEnd End If strSQL = strSQL & " ORDER BY TRAILS.NAME;" 'Create a command object Dim objCommand As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader As OleDbDataReader objDataReader = objCommand.ExecuteReader() Dim coll As New Collection If (sMinLat <> "") Then '**************************************************************** ' now check if distance from is entered and check location trail Dim myInString As String = "" While objDataReader.Read myInString = myInString & objDataReader("TRAILID") & "," If Not (coll.Contains(CStr(objDataReader("TRAILID")))) Then coll.Add(objDataReader("NAME"), CStr(objDataReader("TRAILID"))) End If End While myInString = myInString & "-1" Dim strSQL3 As String = "SELECT LOCATION.TRAILID FROM LOCATION WHERE LOCATION.TRAILID IN(" & myInString & ") and (((LOCATION.X > " & sMinLng & ") AND (LOCATION.X < " & sMaxLng & ")) AND ((LOCATION.Y > " & sMinLat & ") AND (LOCATION.Y < " & sMaxLat & ")));" objDataReader.Close() objCommand.CommandText = strSQL3 objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) '**************************************************************** End If Dim sTrails As String = "" TrailResults = New StringBuilder("") TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("") Dim collTrails As New Collection Dim bHasResults As Boolean = False While objDataReader.Read If collTrails.Contains(objDataReader("TRAILID")) Then Continue While End If Dim trailname As String = "" If (coll.Count > 0) Then trailname = coll(CStr(objDataReader("TRAILID"))) Else trailname = objDataReader("NAME") End If collTrails.Add(objDataReader("TRAILID"), objDataReader("TRAILID")) TrailResults.AppendLine("") TrailResults.AppendLine(" ") TrailResults.AppendLine(" ") TrailResults.AppendLine("") bHasResults = True If sTrails = "" Then sTrails = "" & objDataReader("TRAILID") Else sTrails = sTrails & "," & objDataReader("TRAILID") End If End While TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("") TrailResults.AppendLine("
 ") TrailResults.AppendLine(" " & trailname & "") TrailResults.AppendLine("
  
") TrailResults.AppendLine("") 'Close the datareader/db connection objDataReader.Close() Session("TRAIL_RESULTS") = TrailResults End Sub Private Sub GetBounds(ByVal id As Integer) Dim connString As String Dim servPath As String = Server.MapPath(".") connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _ servPath & "\App_Data\Trails.mdb;" 'Open a connection Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() Dim strSQL As String = "SELECT MINX, MINY, MAXX, MAXY FROM TRAILS WHERE TRAILS.TRAILID=" & id Dim objCommand As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader As OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) TrailBounds = New StringBuilder("") While objDataReader.Read TrailBounds.Append(objDataReader("MINX") & ",") TrailBounds.Append(objDataReader("MINY") & ",") TrailBounds.Append(objDataReader("MAXX") & ",") TrailBounds.Append(objDataReader("MAXY") & ",") TrailBounds.Append(id) End While End Sub Private Sub GetBounds2(ByVal name As String) Dim connString As String Dim servPath As String = Server.MapPath(".") connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _ servPath & "\App_Data\Trails.mdb;" 'Open a connection Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() Dim strSQL As String = "SELECT MINX, MINY, MAXX, MAXY, TRAILID FROM TRAILS WHERE TRAILS.NAME='" & name & "'" Dim objCommand As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) 'Get a datareader Dim objDataReader As OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) TrailBounds = New StringBuilder("") While objDataReader.Read TrailBounds.Append(objDataReader("MINX") & ",") TrailBounds.Append(objDataReader("MINY") & ",") TrailBounds.Append(objDataReader("MAXX") & ",") TrailBounds.Append(objDataReader("MAXY") & ",") TrailBounds.Append(objDataReader("TRAILID")) End While End Sub Public Function GetCallbackResult() As String Implements _ System.Web.UI.ICallbackEventHandler.GetCallbackResult Dim sResults As String = "" If (Not IsNothing(TrailResults)) Then sResults = TrailResults.ToString ElseIf (Not IsNothing(TrailBounds)) Then sResults = TrailBounds.ToString End If Return sResults End Function End Class