Looking for Microsoft Index Server ASP.NET samples - asp.net

i am not a programmer, but i can frankenstein code snippets with sufficient proficiency that if, by the grace of a few good souls, i could come across some sample ASP code that acts as a GUI to the ms index server, i could certainly make it work and look good.
if anyone can offer any help, i would do a backflip. but i won't put it on youtube. there's enough faceplant videos out there.
summary: does anyone know where i can find index server asp pages? the more complete, the better. snippets are more than welcome.
btw: io tagged this as sharepoint since this is so similar. some moss admins will certainly be able to lend me a hand!

How about some samples from CodeProject? Would that suit your needs? I'm sorry I can't offer any more specific help without knowing more details and what you are trying to do.
Microsoft Index Server class for ASP (classic ASP)
Your free search engine – Microsoft Indexing Server

To talk to an index server catalogue from asp.net you can use an ole db connection object.
OleDbConnection conn = new OleDbConnection("Provider=MSIDXS;Integrated Security .=;Data Source=" + catalogName);
cmdQuery = new OleDbCommand(query, conn);
Where catalogName is the name of the catalog on your machine you are querying. And query is a string containing the index query you are using.
//Get reader
rQuery = cmdQuery.ExecuteReader(CommandBehavior.CloseConnection);
//Create dataset and load values from reader into it
dataQuery = new DataSet("IndexResults");
dataQuery.Load(rQuery, LoadOption.OverwriteChanges, new string[] { "" });
//Return the first table which will be the results from the query
results = dataQuery.Tables[0].Copy();
Don't forget to dispose of the connection and reader in a finally statement :)
Index query itself is very similar to SQL - you can also set properties in the query to be used as aliases so it is easier to read.

Related

Getting the session data from ASP classic isn't working

I am currently tasked with moving one of our older bits of software to a new server. The old server is running 2008 and the new server is on 2019. The code is a mixture of ASP and ASP.NET, both using VB. Unfortunately, I'm a C# developer and my VB knowledge is slight.
The main bit of the code is the older and is all in ASP and works fine on the new server. For a particular set of customers there is an add-on that is more recent and uses ASP.NET. For the new section of code to get the details of the logged in user it uses the code given in this answer. Unfortunately it seems like it is this bit of code that is failing.
We have this bit of code in our site.master.vb
ctx1 = ctx.Request.Url.Scheme
ctx2 = ctx.Request.Url.Host
dom = ctx1 + "://" + ctx2
Dim ASPRequest As HttpWebRequest = WebRequest.Create(New Uri(dom + "/arc/asp2netbridge.asp?sessVar=" + sessionValue))
ASPRequest.ContentType = "text/html"
ASPRequest.Credentials = CredentialCache.DefaultCredentials
If (ASPRequest.CookieContainer Is Nothing) Then
ASPRequest.CookieContainer = New CookieContainer()
End If
The asp2netbridge.asp file is stored in the directory one up from the directory that contains the code and the directory structure looks the same on both servers. The contents of the as2netbridge file are the the same as in the example code linked above with the addition of some extra comments.
It then calls a Stored Procedure on our database with the customer ID from session that should return the customer details as XML, but instead we get a 'Root Element is missing' Error. If I change the Stored Procedure to hard code the customer ID in it, rather than as a parameter then it works as expected.
Is there anything that I need to install on our server to get the system working correctly? Or is there anything else I need to do to get it to work?

Finding Client Printer ASP.Net

From what I have read its not possible to find a clients local printer using modern browsers for security reasons. I have a few conditions that might make that answer different.
I am trying to get clients local printers from within a company network. So this isnt published 'outside'
I thought several years ago Microsoft released a small version of .Net that could be run from the clients browser. If so and its still around I wonder if that could inspect clients local printer.
Thanks
One way to give the appearance of retrieving the clients printers is to run a server side application in the same network with the same access permissions. Silverlight may be able to do it. I have no experience with it unfortunately.
Check here: Get list of network printers silverlight
This ended up being a lot of work with little information because nearly all my searches on the internet for a solution assumed we want to get the printers of the client from the browser. We want to find such information it via the Network.
The solution ended up being with DirectorySearch and the like. here is the code with some privacy stuff removed. Its in a POF state so it might have some not so great syntax
Dim list As New List(Of String)
Dim listtemp As New List(Of String)
Dim resultCollection As SearchResultCollection
Dim computer_name As String = System.Net.Dns.GetHostEntry(Request.ServerVariables("remote_addr")).HostName.Replace(".ourcompany.com", "").ToLower 'clients machine name
Dim dirEntry As New DirectoryEntry("LDAP://DC=OURCOMPANY, DC=com")
Dim dirSearcher As New DirectorySearcher(dirEntry)
dirSearcher.Filter = "objectCategory=printQueue"
dirSearcher.PropertyNamesOnly = True
dirSearcher.PropertiesToLoad.Add("Name")
dirSearcher.SearchScope = SearchScope.Subtree
resultCollection = dirSearcher.FindAll()
For Each sresult As SearchResult In resultCollection
If sresult.GetDirectoryEntry.Name.ToLower.Contains(computer_name) Then
list.Add(sresult.GetDirectoryEntry.Name.ToLower.Substring(3).Replace(computer_name + "-", ""))
End If
Next

SQLite Search in Chinese is not working in Windows RT

I am writing a Windows RT app (Windows 8.1) in which I have used SQLite for the database. When I change the language setting of the machine to Chinese and I try to search a entity with a Chinese name, its returning me null even though the file exists. When the same query is used in SQLite manager, it returns back the respective entity.
Code used :
var q = string.Format("SELECT Entity.* from Entity where upper(Name) like '%{0}%' or upper(Keywords) like '%{1}%' ", queryString, queryString);
return db.Query<Entity>(q);
The letter could be "啊"
The search is working fine in English. So, do we have to enable something while installing to allow multilingual operation? or any extra parameter need to be sent to indicate that the language is different while sending a query?
You probably need to format the string as UTF-8/Unicode. Suggested reading re internationalization
I don't know what language you're using (C# I'm guessing), but using parameterized queries might help get around encoding issues, and it looks pretty simple to change to. Bonus points for avoiding SQL Injection (See How do parameterized queries help against SQL injection?) It's a local app, so not too serious... but still, bad practice.

Is using DirectoryServices.NativeObject slow/bad?

In an ASP.NET 4 application, I have existing code to access a user's Active Directory information (potentially under Windows Authentication or FBA) like this:
// authType taken from run-time config file, default below
AuthenticationTypes authType = AuthenticationTypes.Secure;
string path = "LDAP://" + domain;
DirectoryEntry entry = new DirectoryEntry(path);
entry.AuthenticationType = authType;
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
// set search Filter/Properties etc. ..., nice and correctly
SearchResult result = search.FindOne();
It has always worked fine for me, on my LAN. But I get no feedback from customer sites (other than it works). I now note a post like http://www.justskins.com/forums/directoryentry-nativeobject-slow-with-203410.html, implying this COM way of going via DirectoryEntry.NativeObject might be inefficient or ill-advised? On the other hand, I see here LDAP search using DirectoryServices.Protocols slow, implying it is OK?
This code probably dates from .NET 1/2, when perhaps System.DirectoryServices had less in it; it came from some MS example for using ADSI somewhere.
In a word: I don't want to change the code just for the sake of it, but will if faster. Is there actually nowadays any superior method(s) in DirectoryServices which I should be using?

What's the best way to display an image from a sql server database in asp.net?

I have a sql server database that returns byte for the image. If I use the tableadapter wizard and set it to my stored procedure and preview data, it pulls back an image. It automatically turns it into an image in the preview data. I don't see it as a string of Ints or anything.
How can I display it on my asp.net webpage with a gridview and objectdatasource?
I have searched and foudn where the imagefield can point to a url on another page that does the byte transformation but I'm not sure it's the best. I found another way that creates a temp file.
Just trying to see the best way to do it.
edit - I am trying not to use a temp file. If I cannot use a gridview a regular image field is ok.
asp.net 2.0, c#.
Thank you for any help.
edit
ended up with:
protected void Page_Load(object sender, EventArgs e)
{
string id = Request["id"];
string connstr = "DSN=myserver";
OdbcConnection conn = new OdbcConnection(connstr);
OdbcCommand cmd = new OdbcCommand("{call mySP (?)}", conn);
cmd.CommandType = CommandType.StoredProcedure;
// Add the input parameter and set its properties.
OdbcParameter parameter = new OdbcParameter();
parameter.ParameterName = "#MyParam";
parameter.OdbcType = OdbcType.VarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = id;
// Add the parameter to the Parameters collection.
cmd.Parameters.Add(parameter);
conn.Open();
OdbcDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
byte[] buffer = (byte[])dr[0];
Response.ContentType = "image/jpg";
Response.BinaryWrite(buffer);
Response.Flush();
}
}
and this on the calling page:
<asp:Image ID="Image1" ImageAlign="Middle" ImageUrl="show.aspx?id=123" Runat="server" />
Two options:
Create a temp file - The problem with this approach is that you have to create the file, which means your web must have write access to a directory which is not a great thing. You also need to have a way to clean up the images.
Serve it from another URL - This is my preferred method, as you have no disk access required. A simple http handler (ashx) is a great method to serve up the image.
Edit
If you need session state in the ashx, check out: Asp.net System.Web.HttpContext.Current.Session null in global.asax.
Edit
Couple more thoughts. There are some cases where using a temp file might be better. For example if your images are requested frequently by a lot of users. Then storing the images on the disk would make sense, since you could write the file once, this does increase the maintance complexity but depending on traffic it might be worth it since this would let you avoid calling back into the .net stack and leverage IIS caching of static content.
I wrote the SqlReader plugin for open-source ImageResizing.Net library to allow you to serve and display images from a SQL database in the most performance-optimal way.
Even if you don't need to do any image processing whatsoever, it's still (a) the easiest, and (b) the most efficient way to do it. You can combine it with disk caching (which provides automatic cleanup) to get the best performance that is possible.
Installation is easy - 2 nuget commands, or copy & paste into Web.Config, your pick.
If you need help, support is free and fast.
The sample code you added is good but you should move it to a .ashx file which is meant for such things.
Here is some example code on how to do this.

Resources