Missing libXm.so in Red Hat (RHEL5)

Author: Victor Chen | Date: 9.5.2008 | Category: Linux

After a clean installation of Red Hat Enterprise Linux 5 (RHEL5) with an active subscription, I came across an immediate problem when attempting to run an application. I get the following error:

libXm.so.3: cannot open shared object file: No such file or directory

The first step is to insure that the files are actually missing. The easiest way to confirm if the file exists on the system is to run the locate command. Try the below linux command below which will return a list of similar files.

locate libXm.so

The number after libXm.so is merely the version number. If you are missing libXm.so.3, but you have libXm.so.4, you can create a symbolic link (-s) from file libXm.so version 4 to version 3 with the below linux command.

ln -s libXm.so.4 libXm.so.3

It turns out that I was missing a motif package, and that by installing openmotif (a perfect motif alternative) will quickly resolve the issue. Try the following below:

yum install openmotif22.i386 openmotif22.x86_64

Say yes to both prompts to complete the openmotif installation.

Set a Browser Cookie in C#

Author: Victor Chen | Date: 6.5.2008 | Category: C#

Storing an arbitrary value into a cookie on the client’s machine is something that most site will require at one point or another. It allows for retrieving data across page loads. Below is code snippet of the simple input form in our example.

<form id=”form1″ runat=”server”>
<div>
Cookie Name:
<asp:TextBox ID=”txtCookieName” runat=”server”></asp:TextBox>
<asp:Button ID=”btnSetCookie” runat=”server” Text=”Set Cookie” onclick=”btnSetCookie_Click” />
</div>
</form>

Our next step is to define Button (btnSetCookie) event. Here, we create a HttpCookie. Next, create the cookie’s name and assign the value (as defined in the TextBox txtCookieName). Additionally, we will set the cookie to expire in one minute.

protected void btnSetCookie_Click(object sender, EventArgs e)
{
HttpCookie myCookie = new HttpCookie(”TestCookie”, txtCookieName.Text);
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 0, 1, 0);
myCookie.Expires = dtNow + tsMinute;
}

In this situation, whenever a user clicks the Set button, a cookie (defined as myCookie) will be set that will expire in one minute.

Find GridView Column Index With AccessibleHeaderText

Author: Victor Chen | Date: 24.4.2008 | Category: C#

Trying to access a specific GridView’s column is especially easy, but only if you know the column index. One way to handle accessing the column is to hard code the column index into the code:

GridView gv = new GridView();
DataControlField dcf = gv.Columns[5];

The main problem with the above solution is if you add a new column at index 1, you will need to manually change all hardcoded indexes. Therefore, another way to handle this is to set a constant integer for each column containing the index.

const int _MYCOLUMN = 5;
GridView gv = new GridView();
DataControlField dcf = gv.Columns[5];

Using this would only require you to change the _MYCOLUMN constant integer in one location, which would reflect in the rest of your code. However, an even better way to handle this is to access the column by a defined name. The method below involves setting the AccessibleHeaderText of a column on the aspx page when the gridview column is defined.

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”>
<Columns>
<asp:BoundField AccessibleHeaderText=”date” DataField=”date” HeaderText=”Date” SortExpression=”date” />
<asp:BoundField AccessibleHeaderText=”article” DataField=”article” HeaderText=”Article” SortExpression=”article” />
</Columns>
</asp:GridView>

By setting the AccessibleHeaderText, we can now access the column through this header name. The function below requires the gridview and a string containing the AccessibleHeaderText. The function will return the index of the column, if found . Otherwise, negative one (-1).

private int findColumnIndex(GridView gridView, string accessibleHeaderText)
{
for (int index = 0; index < gridView.Columns.Count; index++)
{
if (String.Compare(gridView.Columns[index].AccessibleHeaderText, accessibleHeaderText, true) == 0)
return index;
}
return -1;
}

By using this method, adding a new column in index one will not affect the rest of the code. The method checks the AccessibleHeaderText of each column to verify that it matches your specified string. If it matches, it returns the index.

int dateIndex = findColumnIndex(GridView1, “date”);
int authorIndex = findColumnIndex(GridView1, “author”);
int articleIndex = findColumnIndex(GridView1, “article”);

In the above example, dateIndex will return 0, authorIndex will return -1, and articleIndex will return 1. It’s as simple as that!