Archive

Archive for the ‘Code Snippets’ Category

Quick Tip: Centering A Website Using CSS

May 15th, 2011 No comments

It's very easy to centre your website using CSS. All you have to do is apply the following CSS to your website's outermost container, even if it is a table or div element. Also, remember that the container must have a defined width!

HTML
<div class="container">...website markup here...</div>
CSS
div.container {margin-left: auto; margin-right: auto; width: 1024px;}
Categories: Code Snippets, CSS, Quick Tip Tags:

Reading Text Files in .NET – The Easy Way

November 21st, 2010 No comments

I don't know about you fellow .NET programmers, but I don't often come across a need to read from text files often when I am programing in .NET. As such, I find that every time I need to do this, I have to use Google to refresh myself on how to do it. Recently, i found a much easier  way of reading text files that I felt compelled to share.

VB.NET
Dim s as String
Dim file_path as String = "C:\test.txt"

'Storing the text from the test.txt file in a string variable
s = System.IO.File.ReadAllText(file_path)
C#
string s;
string file_path = "C:\test.txt";

//Storing the text from the test.txt file in a string variable
s = System.IO.File.ReadAllText(file_path);

I hope this is as useful to you as it was for me.

Categories: C#, Code Snippets, VB.NET Tags: ,