Saturday, February 14, 2009

Play sound from Window Form in C#

Playing a sound from window forms in C# is simple because of SoundPlayer class from System.Media namespace.

SoundPlayer objSoundPlayer = new SoundPlayer("sound1.wav");
objSoundPlayer .Play();

Saturday, January 31, 2009

Single line If Statement.

string name = Session["UserName"];

if(string.isNullOrEmpty(name))
Response.Write("welcome guest");
else
Response.Write("welcome "+name);

You can write it in single line as below.

Response.Write((string.isNullOrEmpty(name)) ? "Welcome guest" : "Welcome "+name);

The HTML Label Tag Benifits

Make your forms accessible to screen readers
Make your forms easy to click on
Give your CSS more to hold on to


To see more detail, check this Link

Use generics with drop down list

You can use generice to bind with drop down list. Suppose you have a class Country.

public class Country
{
int id;
string countryName;

public int ID
{
get { return id; }
}


public string CountryName
{
get { return countryName; }
set { countryName = value; }
}
}

List objCountry = new List();
objCountry = objCountry.FetchCountries();
ddlCountryList.DataSource = objCountry;
ddlCountryList.DataTextField = "CountryName";
ddlCountryList.DataValueField = "ID";
ddlCountryList.DataBind();

The ddlCountryList is an asp.net drop down list control.

Wednesday, January 21, 2009

Designing a GUI

A tip for designing a GUI(Graphical user interface) is that the items in the menu is in the range of 5 to 9. The reason is the famous rule of George A. Miller Seven plus or minus two. it states that the human minds at a time remember seven plus or minus two items. so it is a good practice to not make more than seven items in a menu.

Wednesday, December 3, 2008

Compiling C# and VB code together in asp.net

Yesterday i was working on a web application which uses vb classes. I have added a c# class added but asp.net compiler does not compile it as app_code folder becomes a single assembly so it allows only vb or C#.

Tip:
To compile both C# and VB, add this in web.config.

<compilation debug="false">
<codesubdirectories>
<add directoryname="VBCode">
<add directoryname="CSCode">
</add>
</add></codesubdirectories></compilation>


For more information, see this post.

Monday, December 1, 2008

The Eight Commandments of Source Code Control

Yesterday I read source code control tips which are helpful for developers working in a team environment. Link was sent by my friend Awais. I am posting here to share this.

1. You shall check in early and check in often. You anger your coworkers when you check out a file and insist on keeping it checked out until some future point in time that is measured using variables that exist solely in your brain.

2. You shall never check in code that breaks the build. If you code does not compile, it does not belong in the source control repository.

3. You shall not go home for the day with files checked out, nor shall you depart for the weekend or for a vacation, with files checked out.

4. You shall leave a descriptive comment when checking in your code. You need not include your name or the date in the comment as that information is already tracked.

5. You shall use the 'Undo Checkout' option if you check out a file and do not make any changes. It displeases your coworkers when you check in code that has not changed at all from the original.

6. You shall not use comments to 'save' defunct code. Fear not, for the code you delete still exists in the source control code history and can be retrieved if needed.

7. You shall use source control for more than archiving just code. The source code control repository makes an excellent storage for technical docs, SQL scripts, and other documents and files related to the project.

8. You shall religiously backup your source code control database on a regular basis and store a copy in an off-site location.

Source: http://scottonwriting.net/sowblog/posts/13581.aspx