Queens Dev
Some more ASP.NET

Sticky Footer - Web Design

April 5, 2009 at 12:09 PM by BrandonSetegn

I was working on the html design of a new website that needed to have the footer stick to the bottom of the page.  After much searching I found one solution for a css sticky footer here that I would not recommend.  This used the following css trick:

Warning Improper CSS...

.wrapper {
	min-height: 100%;
	height: auto !important;
	height: 100%;
	margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */ }
.footer, .push {
	height: 142px; /* .push must be the same height as .footer */}
... 



Well it turns out this hack doesn't work quite as well as described. For starters the "height: auto !important;" caused the footer to get stuck in inappropriate places in IE7. However, thanks to the wonderful forums over at SitePoint, I was able to find a proper solution that was easier to implement.  I have also tested this CSS in IE7 and FF and both render it flawlessly.

The proper css and html and be find here. Here is the better CSS from the proper solution:

Proper CSS...

*{margin:0;padding:0}
html,body{height:100%}
body{position:absolute;width:100%}/*opera 9.5 fix*/

#outer{
    width:760px;
    background:#ffffcc;
    margin:auto;
    min-height:100%;
    margin-top:-40px;/*footer height*/}

* html #outer{height:100%}

#header{
    border-top:40px solid #fff;/* soak up negative margin*/
    background:red;}

#footer{
    background:red;
    width:760px;
    margin:auto;
    height:40px;/* must match negative margin and header soak up*/}...

Links

http://www.pmob.co.uk/temp/sticky-footer.htm - The HTML and CSS example of a proper sticky footer.

http://www.pmob.co.uk/#nolink -The rest of Paul's blog contains many helpful CSS examples, including the HTML and CSS for the Sticky Footer example above.

SitePoint CSS Forums: Sticky Footer Div - The answer to my question on sitepoint.

Upcoming Blog Posts

March 17, 2009 at 1:24 AM by bjsetegn

Continuing the theme of lists, here is a list of some upcoming blog posts:

  • Regex.Unescape - Why is it useful?
  • Dynamic BlackBerry Optimized Grid - Ever wondered how to make a very dynamic grid?  How about one optimized for the BlackBerry browser?

Useful Websites

March 17, 2009 at 12:40 AM by bjsetegn

Much like the list of useful applications here is a list of interesting and sometimes useful websites.

Less Everything - A couple of very simple online applications such as a time tracker and agile project management tool.
Blellow - A freelancers social network with groups, jobs, and project postings.
Elance - A decent site for finding freelance work.

Useful Applications

March 17, 2009 at 12:28 AM by bjsetegn

Here is a list of some random applications I found usefull now and then.  Some of them are open source and most of them are free.

Time Edition - Time tracking application, useful if you are doing freelance work. 
CopySourceAsHtml - A code syntax highlighting tool that integrates with Visual Studio, which was also mentioned before here.

System.Net.Mail - Command Not Implemented

September 19, 2008 at 5:20 AM by bjsetegn

While setting up the e-mailing features int log4net for an ASP.NET 2.0 project I kept receiving the following exception:

System.Net.Mail.SmtpException: Command not implemented. 
 The server response was: Command not implemented
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at log4net.Appender.SmtpAppender.SendEmail(String messageBody)
   at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)

I found this troubling because I had used this feature before and had no problem sending e-mails from other applications.  Also another developer was able to use the same exact log4net code on their machine and it worked.  It turned out that the host I was using wasn't setup for relaying e-mails through their e-mail server.  When I used the .NET 1.1 System.Web.Mail classes with the same e-mail server and configuration I would not receive the exception.  It uses a slightly different communication protocol (HELO vs EHLO) that doesn't require relaying to be setup on the e-mail server. So if all else fails and you get the Command Not Implemented exception you could always use the .NET 1.1 System.Web.Mail class.

More Info

http://msexchangeteam.com/archive/2004/02/19/76432.aspx - For setting up an email server for relaying.

http://code.msdn.microsoft.com/KB913616 - For a possible hotfix.

Convert Code Syntax Highlighting to HTML for Posting Online

September 18, 2008 at 5:11 AM by bjsetegn

I come across many websites and blogs these days that still don't format their code well when posting it online.  Whenever I see a site with poorly styled code I wonder how good of a programmer they actually are and how little effort they put into their site.  For those of us with Visual Studio this task has been made pretty simple thanks to a tool called CopySourceAsHtml.  This simple tool integrates with Visual Studio to allow you to copy out its syntax highlighting to html exactly as you see it.  Since Visual Studio adds syntax highlighting to many common file types it makes its easy to generate html from almost any of your source code.

I found this tool to be the easiest to use because it doesn't require you to install or change anything on your website.  It also creates html that displays well in most browsers.  Some browsers like Internet Explorer will ignore tags like <pre> which is used to mark text as preformatted.  CopySourceAsHtml doesn't use <pre> tags it mostly uses <p> paragraphs and <span> spans.  It also lets you add specific styling to certain sections making it more dynamic.  A link to the author's website for more details and a download are below.  Also included is a link to convert the add-on to run in Visual Studio 2008.

Links

http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/- Copy Source As HTML

http://developers.de/blogs/andreas_erben/archive/2007/08/01/using-copysourceashtml-with-visual-studio-2008-beta-2.aspx- Visual Studio 2008 Fix

Open Source Icon Sets

July 2, 2008 at 5:08 AM by bjsetegn

I am not an artist in any way, shape, or form.  Pretty much all of the graphics and most of the styles you see here are from outside sources.  But I always like to give credit where credit is due.  For someone who isn't an expert at Photoshop these sets can really save time.

Crystal

A few of the recent images l have added here are from an open source icon set called Crystal.    It is available under the GNU General Public License and was created by a Brazilian by the name of Everaldo Coelho.  It is a pretty extensive and high quality set which is very appropriate for Web 2.0 sites.

Silk

I also want to mention the Silk icon set.  I have used those images on projects in the past .  While not as high quality as the Crystal set these images have proven to be very usefull.

 

SQL Server Function - Remove Leading Characters

June 29, 2008 at 6:48 AM by bjsetegn

Here is a simple piece of code that will remove a specified character from the beginning of a string.  I don't know who the orginal author of this function is, I believe it has been around for quite awhile.  I made some changes to it so that if the first character is a minus sign '-' then it will trim leading characters around that minus sign.  This was to take care of changing '-0.57' to '-.57'.  There could be some extra logic thrown in there to trim around a user defined variable and not just '-' and to turn the feature on and off.  I didn't need it so I'll leave that up to somebody else.

This function works by replacing the character we want to trim with a space ' ' and then calling LTRIM on the string.  This will remove all spaces on the left and then the remaing spaces are replaced with the defined character.  NOTE: Because this replaces all spaces with the defined character this function should only be used on string without spaces in them.

Code 

/* ---------------------------------------------------------------------------------

PURPOSE

    The purpose of this function is to remove all leading characters from a string.

    This will also trim leading zeros around a minus sign

    Ex. Trim '0.57%' down to '.57%'

    Ex. Trim '-0.57%' down to '-.57%'

    Ex. Trim 'CCFFDDCCEE' remove C down to 'FFDDCCEE'

 

select dbo.ufn_TrimLeadingCharacters('-0001235005500', '0')

*/----------------------------------------------------------------------------------

 

ALTER FUNCTION dbo.ufn_TrimLeadingCharacters ( @Input VARCHAR(50), @LeadingCharacter CHAR(1) )

 

    RETURNS VARCHAR(50)

 

AS

BEGIN

 

Declare @returnValue as Varchar(50)

 

If SUBSTRING(@Input, 1, 1) = '-'

Begin

    Set @returnValue = Right(@Input, Len(@Input) - 1 )

    Set @returnValue = REPLACE(LTRIM(REPLACE(@returnValue, ISNULL(@LeadingCharacter, '0'), ' ')),

                   ' ', ISNULL(@LeadingCharacter, '0'))

    Set @returnValue = '-' + @returnValue

End

 

Else

Begin

    Set @returnValue = REPLACE(LTRIM(REPLACE(@Input, ISNULL(@LeadingCharacter, '0'), ' ')),

                   ' ', ISNULL(@LeadingCharacter, '0'))

END

 

 

RETURN @returnValue

 

End

Handle DB Null and Return Default in C#

May 9, 2008 at 2:21 AM by bjsetegn

 When retrieving data from a database you must handle null values.  The getDefaultIfDBNull method below will check if the value returned from the database is null.  If it is null then it will return the default value for that type of object.  For example if retrieving an int field from the database and passed a null value and TypeCode of Int32 it will return the default value of 0.  This helps streamline the checking for null proccess and ensures that all nulls are handled in a simliar way.

The Code:

        /// <summary>

        /// Checks if an object coming back from the database is dbnull.  If it is this returns the default

        /// value for that type of object.

        /// </summary>

        /// <param name="obj">Object to check for null.</param>

        /// <param name="typeCode">Type of object, used to determine what the default value is.</param>

        /// <returns>Either the object passed in or the default value.</returns>

        public static object getDefaultIfDBNull(object obj, TypeCode typeCode)

        {

            //If object is dbnull then return the default for that type.

            //Otherwise just return the orginal value.

            if (obj == DBNull.Value)

            {

                switch (typeCode)

                {

                    case TypeCode.Int32:

                        obj = 0;

                        break;

 

                    case TypeCode.Double:

                        obj = 0;

                        break;

 

                    case TypeCode.String:

                        obj = "";

                        break;

 

                    case TypeCode.Boolean:

                        obj = false;

                        break;

 

                    case TypeCode.DateTime:

                        obj = new DateTime();

                        break;

 

                    default:

                        break;

                }

            }

 

            return obj;

        }

 

This is a sample of a method that calls a stored procedure and needs to check for null.

 

        private void FillDetailInfo(int intDetailsId)

        {

            string conString = "";

            SqlDataReader dr;

 

            try

            {

                conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

                SqlConnection con = new SqlConnection(conString);

 

                SqlCommand cmd = new SqlCommand("uspGetDetails", con);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.CommandTimeout = 100000;

                cmd.Parameters.AddWithValue("@intDetailsId", intDetailsId);

 

                con.Open();

                dr = cmd.ExecuteReader();

 

                //Get details

                if (dr.Read())

                {

                    _id = (int)dr["Id"];

                    _desc = (string)SecurityTools.getDefaultIfDBNull(dr["desc"], TypeCode.String);

                    _isActive = (bool)SecurityTools.getDefaultIfDBNull(dr["ACTIVE"], TypeCode.Boolean);

                }

 

                con.Close();

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

End Code 

VBScript to Change AutoText in Word 2003 Normal.dot

March 20, 2008 at 1:17 AM by bjsetegn

My client recently changed there name for branding reasons, making it more concise.  They have around 100 employees using Word with an Autotext (auto complete) entry for their old company name.  For anyone who doesn't already know what the Autotext feature is in Word it is a special feature that will complete a phrase for you after you type the first couple of letters for it.  This actual text for the Autotext is stored in the Normal.Dot file located deep within your file systems  which is the default Word template.  This template is loaded every time you open a new document.  Outlook also uses Word as its editor and thus uses the Normal.dot.  

Anyway, they wanted to change the Autotext entry for their company name on all 100 computers.  This would have been quite a hassle for each user to do themselves or taken a lot of time for one person to run around to each computer and change it.  So they had me write a script that would change the entry and could be set to run the next time the user logged in.  At first I tried to edit the Normal.dot file manually through a filestream but I ran into problems when writing the changes back.  Special characters and other items in the file header were either erased or changed and the file would be corrupted.  So I reached out for some help and an IT guy sent me a link to some code that looked a lot like what I have below (I can't find the link or I would post it, only half of what's below I will claim as my own work, the easy half).  I modified it to work for my situation and added some error checking in case it was run more than once and the old record wasn't found.  It worked pretty well and for once I was assured I had saved the client some money.  Oh how powerful vbscript can be.

To run the code save the text below to a text file such as RenameAutotext.vbs.  Then from the command prompt run: cscript RenameAutotext.vbs.  Run using cscript not wscript because if run using wscript will send the Echo command to the program running, Word, instead of writing it to the command line.  This script is also test to work only for Windows XP and Microsoft Word 2003.  Word 2007 uses a different type of template file so and this script will need to be modified to work with that.

There may be some extraneous parts that aren't 100% necessary below but with vbscript I am happy when I get it to do exactly what I want and leave it at that.  If anyone has some suggestions for improvement leave a comment. 

The Code: 

    'Rename an

    'Get Application Data Path

    Set oShell = CreateObject("WScript.Shell")

    appdata = oShell.ExpandEnvironmentStrings("%APPDATA%")

 

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = True

 

    Set objDoc = objWord.Documents.Open(appdata & "\Microsoft\Templates\Normal.dot", False)

 

    'Add new autotext entries

    Set objTxtEntry = objWord.NormalTemplate.AutoTextEntries.Add("New Company Name", objWord.Selection.Range)

    objWord.NormalTemplate.AutoTextEntries("New Company Name").Value = "New Company Name"

 

    'Enable error handling

    On Error Resume Next

    'Delete old autotext entries

    objWord.NormalTemplate.AutoTextEntries("Old Company Name").Delete

 

    If Err.Number <> 0 Then

        WScript.Echo "No Old Company Name record found, new entry inserted."

    Else

        WScript.Echo "Completed Successfully."

    End If

 

    'Print all autotext entires to make sure it was changed properly

    'Wscript.Echo

    Dim i

    For Each i In objWord.NormalTemplate.AutoTextEntries

       Wscript.Echo i.Name

    Next

 

    objWord.Quit