| Subcribe via RSS

Display Single Post on Home Page in WordPress

December 11th, 2011 | Comments Off | Posted in PHP, WordPress

Most themes have some sort of post roll that lists out the most recent posts on the home page. In most cases this is the ideal way to get your readers up to date on your most recent information. Say you had a more traditional website that displays what your company is about on the home page and maybe your recent or most read blog posts are relegated to the sidebar. So how do we display just a single post in that home page body section? Pretty simply it turns out.

Just prior to the php while loop (look at the file located in Appearance > Editor > index.php) set the query_posts method equal to the id of your post. So you’d have something that looks like this.

Err Msg: ‘Could Not Load Type _Default’ & ‘Server Application Unavailable’

February 5th, 2010 | Comments Off | Posted in ASP.NET
I thought I’d lump these two together since they seem to be interrelated. So I’m doing development on a dev box I haven’t worked with in a while. I have a Visual Studio project that works like a champ on my box, but as soon as I load it up to the dev I get the error message ‘Could Not Load Type _Default.’ I was thinking it was a web.config issue so I tried to massage that for a while with no luck. I’d set up the application correctly in IIS so it shouldn’t have any issues accessing the dll in the local bin folder. What I hadn’t counted on was the two versions of the .NET Framework running on this box. This was a 2.0 app I’d developed and my current application was defaulting over to 1.1. Updated this under the application in IIS, and up it came. It didn’t stay up for long though as I surfed through my application and quickly hit a ‘Server Application Unavailable’ error. I threw this project into the 2.0 application pool and everything settled down.

Find All Cookie Values in a Given Application via ASP.Net and c#

January 14th, 2010 | Comments Off | Posted in ASP.NET, C#

Cookies can be especially maddening at times if you don’t know what values are being stored within them. The following simple script is written in csharp and ASP.Net and allows you to see all of the cookies currently hanging around under a given application. Pretty handy when trying to fish yourself out of a problem.

Error Message: Could not find file ‘c:\windows\system32\inetsrv\System.Xml.XmlDocument’.

January 13th, 2010 | Comments Off | Posted in XML

Someday I’ll free myself from the XML hell I seem to be mired in, but that day is not today. So I’ve got a fun new issue. The previous coder stored all the user entry values in session values without thinking about the fact that this won’t run correctly once it goes live in the web farm. So now I have to switch all those values over to be stored in the cookie and a few in the database that need to be secured. So in my haste to switch everything over, I ran across the error message “Could not find file ‘c:\windows\system32\inetsrv\System.Xml.XmlDocument’.” Huh? All I’ve done is try to store the Xml string into a XmlDocument object like so:

After pondering and tinkering with this for the better part of 30 minutes, it finally occured to me. The Load method of XmlDocument is used to access an Xml file on the server whereas the LoadXml method is used to load a previously defined Xml string. Popped that in, and it worked like a charm. Now what is my next error?

Navigating to a Sibling Node via XPath

January 4th, 2010 | Comments Off | Posted in XSL

So I’m in an XSLT stylesheet, and I’ve navigated my way down to the node level. Now I’m trying to traverse my way down to the next sibling node and get an attribute out of it. Something like the following:

Not the best XML structure in the world, but what do you do when you have inherited code? After a long time of searching and trying out about 20 different possible iterations, I found the best solution to be:

For a quick translation, we are currently at the question node from the XML sample above, looking to step down into the answer node to get the text value. The second XSLT code block’s select statement tells the routine to get the following sibling node ‘answer’ even more specifically the first answer node following the question node. From there, we just reference the text attribute within the node.

Subtracting Dates in C#

December 16th, 2009 | Comments Off | Posted in C#
I’ve got an exam application that has a fixed time limit and relays the clock winding down to the test taker via an AJAX call. So we know what time it is now (DateTime.Now), we know when we started the exam (set value in session) and we know the time limit of the exam (pulled from the database). How do we bring it all together? We have to figure out our finish time by running the AddMinutes method against our exam beginning DateTime value, adding our predefined number of minutes set in the time limit. Next, we simply subtract our begin time from our finish time, and that leaves us with a TimeSpan value. The only thing remaining is to do something with that TimeSpan value. It has a host of methods for conversion, but we are going to run the TotalMinutes method this go around to get us the countdown value. Maybe not as simple as VB’s datediff, but simple enough.

Get User Name for NT Authentication in C#

December 10th, 2009 | Comments Off | Posted in C#

Lots of systems sit behind an NT Authentication wall to keep the unwanted users out, but does it really do you any good if you don’t know which user made a given update to a system. Also this is good if you want to give a certain user administrative privledges, displaying certain functionality while hiding it from the rest of your users. The easiest way to get at that piece of information is to jump down into the System.Security.Principal.WindowsIdentity class and hit up the GetCurrent().Name method. Note this will pull back the user name preceeded by the domain they are logged onto so to ditch that you’ll just need to clean it up with a Regex statement (ex: Regex.Replace(sNTUser,”DOMAINNAME.”,”"))

SQL Server Noise Words

December 3rd, 2009 | Comments Off | Posted in SQL

If you do FULLTEXT searches in SQL Server, you are very aware of the limitations of noise words. Noise words are basically words that get dropped from the query. They are like common articles like ‘a’, ‘an’, etc. These words are contained in the file c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\FTData\noiseENU.txt (path may vary based on your directory setup). Here is the full list if you are looking to see if one of your terms is getting dropped

about
1
after
2
all
also
3
an
4
and
5
another
6
any
7
are
8
as
9
at
0
be
$
because
been
before
being
between
both
but
by
came
can
come
could
did
do
does
each
else
for
from
get
got
has
had
he
have
her
here
him
himself
his
how
if
in
into
is
it
its
just
like
make
many
me
might
more
most
much
must
my
never
no
now
of
on
only
or
other
our
out
over
re
said
same
see
should
since
so
some
still
such
take
than
that
the
their
them
then
there
these
they
this
those
through
to
too
under
up
use
very
want
was
way
we
well
were
what
when
where
which
while
who
will
with
would
you
your

Sort by Date in XSLT

November 17th, 2009 | Comments Off | Posted in XSL

Sometimes the simple things are more difficult than they should be. Take sorting XML records by date through an XSLT stylesheet. Nothing is built in to handle this basic function. So when left to our own devices, we have to break up the date into substrings and compare each piece of the puzzle. In the code below, we are sifting through a date formatted like ’11/17/2009′. To get the year, we start with the 7th character then take the next 4. We evaluate our year, our month then the day and this sorts the dates in ascending order. If we wanted to have these in descending, we’d add the order=”descending” parameter to the xsl:sort.

Keep DOS Window from Closing on Console Applications

November 3rd, 2009 | Comments Off | Posted in C#
For those of you who develop console apps for automating day-to-day activities, it can be annoying when you are trying to see what happened in your execution block. One solution is to pull up a DOS prompt, navigate to the given folder, then trigger it to run. A second option is to add the line Console.WriteLine(); to the end of your code processing block. This basically tells your program that it can’t close up shop until you give the ok.