How to code a search page for my website - asp-classic

We have a search page on our website that we made using ASP Classic on Windows Server 2003. Now we have migrated over to Windows Server 2012 and we need to make a new search page as the code will not work on Windows Server 2012 Search Service.
Has anyone come across this yet. I have been struggling trying to find good information on how to do this. If possible can someone show some coding examples on how this is done?
Thank you in advance.

<%
'Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
Set adoCommand.ActiveConnection = adoConnection
strQuery = "SELECT Top 1000 System.ItemPathDisplay FROM SYSTEMINDEX"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 10
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
adoRecordset.MoveFirst
Do Until adoRecordset.EOF
response.write(adoRecordset.Fields.Item("System.ItemPathDisplay")& "<br />")
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
%>

Related

VB.Net Outlook email creation works locally, fails on server

When I run my project on my local machine it generates the Outlook email as expected, but if I upload all my code to our development server, it fails with this error message when run: [Exception: Cannot create ActiveX component.]
Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) +509721
etc...
I know it's the Outlook that's failing because if I comment the sendmail() function, the rest of the page works fine. (it just doesn't create the email).
Local machine is Windows 7 with Outlook installed, Server is 2008R2 with no Office installed. I have other pages that can write to Excel files, but they're using CrystalReports to handle it so I'm not sure if the server needs an Outlook dll registered, or if something else needs to happen.
Aspx page with a VB.Net codebehind. My create email looks like:
Dim OApp2 As Object, OMail2 As Object, signature2 As String
OApp2 = CreateObject("Outlook.Application")
OMail2 = OApp2.CreateItem(0)
Dim alAttachList As New ArrayList(2)
Dim iCounter As Integer
alAttachList.Insert(0, "E:\Test\DEBUG CODE.txt")
alAttachList.Insert(1, "\\RemoteServer\z\Test\Hello.bmp")
sBody += "<br />" + "Attached are some files." + "<br />" + "They can also be found in: X:\Test\Test\Name "
With OMail2
.Display()
End With
signature2 = OMail2.HTMLBody
With OMail2
.Subject = sSubject
.To = sTo
.CC = sCC
.HTMLbody = sBody & "<br /><br />" & signature2
End With
Dim sBodyLen As Integer = Int(sBody.Length)
Dim oAttachs2 As Interop.Outlook.Attachments = OMail2.Attachments
Dim oAttach2 As Interop.Outlook.Attachment
For iCounter = 0 To alAttachList.Count - 1
oAttach2 = oAttachs2.Add(Source:=alAttachList(iCounter), DisplayName:=alAttachList(iCounter))
Next
OMail2.Display(True)
OApp2 = Nothing
OMail2 = Nothing
When you do something like:
OApp2 = CreateObject("Outlook.Application")
You are using the Office.Interop libraries which are installed with MS Office (or the individual applications if you go that route)
You MUST install MS Office, or at least Outlook, on the server to use Office.Interop. You might look into using MAPI instead of interop to send your emails. MAPI is part of .Net and does NOT require additional programs be installed on your server.
Firstly, Outlook must be installed. Secondly, is your code running in a service (such as IIS)? No Office app (Outlook included) can be used from a service.

Is it possible to sort items in FSO with classic asp?

Im using the following code on an old IIS machine to generate XML for a mobile app I have built for android and ios devices... it works, but I am now wanting to figure out how I would go about SORTING by date last modified so the list has the NEWEST files at top... my question is, based on how I have my code structured below,
is this possible with my existing code ( sorting 'x' somehow? )?
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.ContentType = "text/xml"%>
<%Response.AddHeader "Content-Type","text/xml"%>
<songlist>
<%
dim fs,fo,x
dim i
set fs=Server.CreateObject("Scripting.FileSystemObject")
'point to a specific folder on the server to get files listing from...
set fo=fs.GetFolder(Server.MapPath("./songs"))
i = -1
for each x in fo.files
'loop through all the files found, use var 'i' as a counter for each...
i = i + 1
'only get files where the extension is 'mp3' -- we only want the mp3 files to show in list...
if right(x,3) = "mp3" then
%>
<song>
<songid><%=i%></songid>
<name><%= replace(replace(x.Name, "-", " "), ".mp3", "")%></name>
<filename><%=x.Name%></filename>
<datemodified><%=x.DateLastModified%></datemodified>
</song>
<%
end if
next
set fo=nothing
set fs=nothing
%>
</songlist>
You can easily sort anything in VBScript using an old time trick known as Recordset Sorting. Code below is fully working and idea is taken from good old asp101 site, R.I.P (archive link)
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<%Response.ContentType = "text/xml"%>
<%Response.AddHeader "Content-Type","text/xml"%>
<songlist>
<%
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
Dim objFSO, oFolder, oFile
Dim fileCounter, objRS
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'point to a specific folder on the server to get files listing from...
Set oFolder = objFSO.GetFolder(Server.MapPath("."))
Set objFSO = Nothing
'create a disconnected recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
'append proper fields
objRS.Fields.Append "Name", adVarChar, 255
objRS.Fields.Append "DateLastModified", adDate
objRS.Open
'loop through all the files found, add to the recordset
For Each oFile in oFolder.Files
objRS.AddNew
objRS.Fields("Name").Value = oFile.Name
objRS.Fields("DateLastModified").Value = oFile.DateLastModified
Next
Set oFolder=nothing
'sort and apply:
objRS.Sort = "DateLastModified DESC"
objRS.MoveFirst
fileCounter = 0
'loop through all the records:
Do Until objRS.EOF %>
<song>
<songid><%=fileCounter%></songid>
<filename><%=objRS("Name")%></filename>
<datemodified><%=objRS("DateLastModified")%></datemodified>
</song><%
fileCounter = fileCounter + 1
objRS.MoveNext()
Loop
objRS.Close
Set objRS = Nothing
%>
</songlist>
(I removed some bits when testing locally, you can of course add them back)
Worth to mention that Recordset sorting is very efficient, when I did custom benchmarks years ago it proved to work fast even with thousands of items.
Not without introducing alternative technologies for the sorting - the FileSystemObject.Files property doesn't support any sorting semantics.
A JScript solution seems like it could do an insertion sort fairly painlessly, though.

Change ASP .mdb access to DSN Less Connection?

I have an old ASP site (written a long time ago by a former employee) that connects to a 2003 ODBC database using DSN. The servers have been updated by our hosts to 2008, and we can no longer use ODBC so I have to make the connections DSN-Less.
Unfortunately I have very little knowledge of ASP, and database connections through ASP. I wonder if anybody can help me change the code to connect to the Access database without ODBC?
I think it connects using this code:
<%
' Get current name of region and intro text
Dim objRec, sql, introtext
sql="SELECT * FROM hometext WHERE home_id = 1"
set objRec=Server.CreateObject("ADODB.Recordset")
objRec.Open sql, "dsn=databasename"
introtext = Replace(objRec("home_introtext"), vbCrLf, "<br />")
' Get the 5 newest news items
Dim objRec2, sql2, newstext
sql2="SELECT TOP 5 news_date, news_text FROM news ORDER BY news_date DESC"
set objRec2=Server.CreateObject("ADODB.Recordset")
objRec2.Open sql2, "dsn=databasename"
' Get all images to appear to page
Dim objRec3, sql3
sql3="SELECT * FROM homeimages ORDER BY homeimage_date DESC"
set objRec3=Server.CreateObject("ADODB.Recordset")
objRec3.Open sql3, "dsn=databasename"
' Get the next 5 events from the current date
Dim objRec4, sql4
sql4="SELECT TOP 5 event_date, event_name FROM events WHERE event_date >= " & niceDateAccess(Date()) & " ORDER BY event_date"
set objRec4=Server.CreateObject("ADODB.Recordset")
objRec4.Open sql4, "dsn=databasename"
%>
I'm not sure how it all connects, I'm not much of a scripter.
Any (dumbed down) help would be appreciated!
Thanks
EDIT: The database is sat in the 'private' folder in the root folder on the server.
Here is a sample code. Change your database name and tablefield name
set conob = Server.CreateObject("ADODB.Connection")
conob.Provider="Microsoft.Jet.OLEDB.4.0"
conob.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("YourDatabaseName.mdb")
Set rsuni = Server.CreateObject("ADODB.Recordset")
sqlStr="select * from Student_Entry"
rsuni.open sqlStr,conob
You must give full access to your database by which user you are logged on.

Asp classic on iis7 dns less connection issue

I cant get dns less connection to Ms Access db to work here the code.
In the dbconnection.asp file is this
Dim MM_IMT_STRING
''MM_IMT_STRING = "dsn=EDA;"
MM_IMT_STRING =("Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\inetpub\wwwroot\essel\Connections\EDA.mdb")
and in the default.asp is this
<!--#include file="Connections/dbconnection.asp" -->
Dim CHANNEL
Dim CHANNEL_numRows
Set CHANNEL = Server.CreateObject("ADODB.Recordset")
CHANNEL.ActiveConnection = MM_IMT_STRING
I have been struggling with this issue for days now, if someone know why its not linking up please tell me thanks.
Where is your Connection object created?
I'm missing something like
Set objConnMDB = Server.CreateObject("ADODB.Connection")
objConnMDB.ConnectionString = MM_IMT_STRING
objConnMDB.Open
CHANNEL.ActiveConnection = objConnMDB
' // do your stuff here '
objConnMDB.Close
Set objConnMDB = Nothing

Script to select, update, insert and delete from MySQL with asp.net (VB)?

I've just switched from classic ASP to .net and I always used the following to SELECT, INSERT, UPDATE and DELETE from my MySQL databases:
' Create db connection
Function dbConn()
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "driver=x;Server=x;Port=x;Option=x;Database=x;Uid=x;Pwd=x"
Set dbConn = objConn
End Function
' Store data in array
Function SQL(myCommand,strSQL)
Set objConn = dbConn()
If myCommand = 0 Then
Set objRS = objConn.Execute(strSQL)
If NOT objRS.EOF Then arrRS = objRS.GetRows Else arrRS = Null
Else
Set objRS = objConn.Execute(strSQL,,128)
End If
Set objRS = Nothing : Set objConn = Nothing
End Function
For example, to use SELECT I'd just go:
Call SQL(0,"SELECT * FROM Users")
And to display the data:
If IsArray(arrRS) Then
For i = 0 to UBound(arrRS,2)
Response.Write(arrRS(0,i) & ", " & arrRS(1,i))
Next
End If
And to insert, update or delete I'd use:
Call SQL(1,"DELETE FROM Users WHERE UserID = 1")
Does anyone know if this is possible with ASP.Net - VB?
Or is there an even handier solution?
Cheers.
Yes, you can certainly do that with VB.NET. VB.NET supports almost everything ASP classic and vbscript could do. ADO.NET supports almost everything ADO did.
... not that you'd want to do it.
I strongly suggest that you look into the pattern and practices that ASP.NET allows. The newer methods are much better than the old ones.

Resources