Dotnet Tutorials ,Codings & Examples: 2009 <h1 class='display-2'> 2009 ~ Dotnet Tutorials ,Codings & Examples</h1>

download crystal reports 2005 merge modules

Crystal Reports uses merge modules to verify the correct crystal report components and assemblies are installed with your deployment project.

A merge module is a set of components that are merged with a Windows installer for applications that need them. The components may include a .dll file, resources, registry entries, setup logic, and related files. With all related components stored in a single container, the installer eliminates version conflicts and other common installation problems.

        Crystal reports merge modules for deployment

  • CrystalReportsRedist2005_x86.msm
  • Microsoft_VC80_ATL_x86.msm
  • policy_8_0_Microsoft_VC80_ATL_x86.msm

Tags: crystal reports merge modules,deployment crystal report project problem,crystal report deployment issues,download merge modules for crystal report,crystall report dll files for deployment

Detect all ip addresses on the lan network

This sample application detects the all ip address and domain name on the
LAN network system.

Free UI controls

MetaBuilders WebControls Server Control Library

Here's the list of controls available 
  • AdSense Ads - Controls to show your Google AdSense ads.
  • CheckedListBox - A Listbox with checkboxes for selection
  • ComboBox - The classic type-or-choose control.
  • DataControlFields - Three fields for the GridView, BooleanField for boolean values (better than the CheckBoxField), LookupField for ID/Key data to a child datasource, and SelectorField for row selection using checkboxes or radiobuttons.
  • DialogWindow - A set of controls which make creating dialog windows a lot easier
  • DualList - move items back and forth between two listboxes to select the items
  • DynamicListBox - a base control which stores changes to its list of items
  • ExpandingButtons - hide and show a target control
  • ExpandingPanel - hide and show the content of the panel
  • FileUpload - A nicer wrapper than the builtin for basic file uploading
  • GlobalRadioButton - A radiobutton which has a page-wide, cross-namingcontainer Group property
  • Grouped Lists aka GroupedListBox and GroupedDropDownList enabled support of the html option grouping in extensions of the standard data controls.
  • ListLink - A non-visual control which helps you create parent/child relationships between list controls
  • MultiFileUpload is a nice compact UI that lets the user select more than one file to upload to the server.
  • MultiViewBar is now free and included in the library, source and all.
  • OneClick - non-visual control that helps the page developer avoid the dreaded double-button-click
  • Polling - controls and framework for showing users simple web polls. Uses a provider framework, with built-in providers for Access and Sql Server.
  • ParsingContainer - control which parses a string of server control markup at runtime
  • QueryCall - Component which maps querystring parameters to methods in the codebehind
  • RemoteWindow - Easy popup windows
  • ResizeMonitor - causes a postback on browser-resize, if you need to keep track of dimensions in your app
  • RollOverLink - the old mouse-over-out effect on images, made dead-easy
  • RuntimeTemplate - Makes it easier to create templates for controls at runtime in code
  • UpDown - the classic Windows Up/Down control for numeric entry.

Programmatically Download File from Remote Location to User Through Server

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Net;
using System.IO;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string url = string.Empty;// Request.QueryString["DownloadUrl"];
if (url == null || url.Length == 0)
url = "";

//Initialize the input stream
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
int bufferSize = 1;

//Initialize the output stream
Response.AppendHeader("Content-Disposition:", "attachment; filename=download.jpg");
Response.AppendHeader("Content-Length", resp.ContentLength.ToString());
Response.ContentType = "application/download";

//Populate the output stream
byte[] ByteBuffer = new byte[bufferSize + 1];
MemoryStream ms = new MemoryStream(ByteBuffer, true);
Stream rs = req.GetResponse().GetResponseStream();
byte[] bytes = new byte[bufferSize + 1];
while (rs.Read(ByteBuffer, 0, ByteBuffer.Length) > 0)

ByteBuffer = null;

Get the index of the SelectedRow in a DataGridView

The below codes show how to do that

private void dataGridView1_SelectionChanged(object sender, EventArgs e)

if (dataGridView1.SelectedRows.Count == 1)
txtCustcode.Text = dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells["CustomerCode"].Value.ToString();

Data grid view multiple checkbox selection

this shows how to use datagrid view and check boxes , and find which check box was checked

for (int i = 0; i < dgGrid.Rows.Count; i++) { GridViewRow row = dgGrid.Rows[i]; bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked) { xSideID = dgGrid.Rows[i].Cells[1].Text; } }

How to read the comma seperated values from a string C#?

string myString = "A, B, C, D";
string delimStr = " ,";
char[] delimiter = delimStr.ToCharArray();
foreach (string s in myString.Split(delimiter))
Response.Write (s.ToString ()+ "
} tips tips for improving the development performance

click here to download

Excel Data Reader - Read Excel files in .NET

Lightweight and fast library written in C# for reading Microsoft Excel files ('97-2007).
- Windows with .Net Framework 2
- Windows Mobile with Compact Framework
- Linux, OS X, BSD with Mono 2+

cllick here to download

How do I prevent a user from moving a form at run time?

The following code snippet shows how you can prevent a user from moving a form at run time:

protected override void WndProc(ref Message m)
const int WM_NCLBUTTONDOWN = 161;
const int WM_SYSCOMMAND = 274;
const int HTCAPTION = 2;
const int SC_MOVE = 61456;

if((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))

if((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))

base.WndProc (ref m);

Protected Overrides Sub WndProc(ByRef m As Message)
const Integer WM_NCLBUTTONDOWN = 161
const Integer WM_SYSCOMMAND = 274
const Integer HTCAPTION = 2
const Integer SC_MOVE = 61456

If (m.Msg = WM_SYSCOMMAND) &&(m.WParam.ToInt32() = SC_MOVE) Then
End If

If (m.Msg = WM_NCLBUTTONDOWN) &&(m.WParam.ToInt32() = HTCAPTION) Then
End If

MyBase.WndProc( m)
End Sub

How do I make my child Form fill the entire mdi client without being maximized?

Here is how it can be done. This takes into account all docked controls (including menus) in the mdi parent form.

private void FillActiveChildFormToClient()
Form child = this.ActiveMdiChild;
Rectangle mdiClientArea = Rectangle.Empty;
foreach(Control c in this.Controls)
if(c is MdiClient)
mdiClientArea = c.ClientRectangle;
child.Bounds = mdiClientArea;

Private Sub FillActiveChildFormToClient()
Dim child As Form = Me.ActiveMdiChild
Dim mdiClientArea As Rectangle = Rectangle.Empty
Dim c As Control
For Each c In Me.Controls
If TypeOf c Is MdiClient Then
mdiClientArea = c.ClientRectangle
End If
child.Bounds = mdiClientArea
End Sub

Avoid duplicate child form in MDI

How do I check to see if a child form is already displayed so I don't have two instances showing?

// MyChildForm is the one I'm looking for

MyChildForm childForm = null;
foreach(Form f in this.MdiChildren)
if(f is MyChildForm)
// found it
childForm = (MyChildForm) f;

if( childForm != null)
childForm = new MyChildForm();
childForm.MdiParent = this;

Read Pdf file using c#

So you’ll have to download the PDFBox package. In this package you’ll find a bin directory. To read your PDF file, you’ll need the following files:

* IKVM.GNU.Classpath.dll
* PDFBox-0.7.3.dll
* FontBox-0.1.0-dev.dll
* IKVM.Runtime.dll

PDF Box Package is free distribution tool

You’ll have to add a reference to the first two in your project. You’ll also have to copy the last two on your project’s bin directory.

The program will look something like this (if you’re working with a Console application):

using System;
using org.pdfbox.pdmodel;
using org.pdfbox.util;
namespace PDFReader

class Program
static void Main(string[] args)
PDDocument doc = PDDocument.load("lopreacamasa.pdf");

PDFTextStripper pdfStripper = new PDFTextStripper();




read Excel file using c#

How to read an Excel file with OleDb and a simple SQL query?

This approach is extremely useful when you need to read the
data from an Excel file fast and store the data in a DataTable
for further usage.

using System.Data;
using System.Data.OleDb;


String sConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + [Your Excel File Name Here] + ";" +
"Extended Properties=Excel 8.0;";

OleDbConnection objConn = new OleDbConnection(sConnectionString);


OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);

OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();



unicode character in C# names

You can use any unicode character in C# names, for example:

public class MyClass
public string Hårføner()
return "Yes, it works!";

Using @ for variable names that are keywords.

var @object = new object();
var @string = "";
var @if = IpsoFacto();

shortcut for creating properties

Has anybody used "props"?

You type "prop" and then press [TAB] twice, it generates useful code for your properties and can speed your typing.

I know this works in VS 2005 (I use it) but I don´t know in previous versions.

Bind countries from CultureInfo class in C#

Some people have asked me how BlogEngine.NET displays a dropdown list of countries when no source XML file is present. The simple answer is that you don’t need any external list to bind to from C#, you can instead use the CultureInfo class.

Consider that you have the following dropdown list declared in an ASP.NET page:

Then from code-behind, call this method which binds the countries alphabetically to the dropdown:

public void BindCountries()
System.Collections.Specialized.StringDictionary dic = new System.Collections.Specialized.StringDictionary();
System.Collections.Generic.List col = new System.Collections.Generic.List();

foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
RegionInfo ri = new RegionInfo(ci.LCID);
if (!dic.ContainsKey(ri.EnglishName))
dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());

if (!col.Contains(ri.EnglishName))


ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
foreach (string key in col)
ddlCountry.Items.Add(new ListItem(key, dic[key]));

if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);

The method first adds all the countries from the CultureInfo class to a dictionary and then sorts it alphabetically. Last, it tries to retrieve the country of the browser so it can auto-select the visitors country. There might be a prettier way to sort a dictionary, but this one works.

C# coding Standards

csharp coding style

Tabbed MDI Dock panel

It's free one

Validating ASP.NET CheckBox

html 5 cheat sheet

HTML cheat for your reference with more options

css3 cheat sheet

css3 style sheet reference for enhance web development

Difference between two dates

This snippet calculates the difference between two dates.

DateTime d1 = new DateTime( 2000, 7, 13 );
DateTime d2 = new DateTime( 2003, 12, 5 );
TimeSpan s = d2 - d1;
int numberofdays = s.TotalDays

Ajax chat Application

This application shows how to develop a simple AJAX chat application. It uses the ScriptManager and UpdatePanel Class to get messages stored in a SQL Server database.

Visual C# 2005 Keyboard Shortcut

keyboard shorctut reference poster from Microsoft

click here

Dot net keyboard shortcuts

Key board shortcut keys always help to increase your speed. So i am giving below some of the Keyboard Shortcuts which will be very useful.

Ctrl + N :- Opens the New Project Dialogue Box
Ctrl + Shift + O :- Opens the Open File Dialog Box
Ctrl + Shift + A :- Opens Add New Item window
Ctrl + D :- Opens Add Existing Item window
Ctrl + F :- Opens Find window
Ctrl + H :- Opens Find and Replace window
Ctrl + Shift + H :- Opens Replace in Files window
Ctrl + Alt + Shift + F12 :- Opens Find Symbol window
F7 :- Opens Code Designer window
Shift + F7 :- Gets you back to Design View
Ctrl + R :- Opens the Solution Explorer window
Ctrl + Alt + S :- Opens the Server Explorer window
Ctrl + Shift + C :- Opens the Class View window
F4 :- Opens the Properties window
Ctrl + Shift + E :- Opens the Resource view window
Ctrl + Alt + X :- Opens the Toolbar window
Shift + Alt + Enter :- Takes you to Full Screen View
Alt+F8 :- Opens Macro Explorer window
F2 :- Opens Object Browser window
Ctrl + Alt + T :- Opens Document Outline window
Ctrl + Alt + K :- Opens Task List window
Ctrl + Alt + A :- Opens Command window
Ctrl + Alt + O :- Opens Output window
Ctrl + Alt + Y :- Opens Find Symbol Results window
Ctrl + Alt + F :- Lists Items under the Favorites Menu in your
Ctrl + Shift + B :- Builds your project
Ctrl + Shift + F9 :- Clears All Breakpoints
Ctrl + Alt + P :- Opens the Processes Dialog box
Ctrl + T :- Opens Customize Toolbox window
Ctrl + Shift + P :- Runs Temporary Macro
Ctrl + Shift + R :- Records Temporary Macro
Alt + F11 :- Opens Macros IDE
F5 :- Runs your Application
Ctrl + F5 :- Runs your Application without Debugging
Ctrl + Alt + E :- Opens the Exceptions Dialog Box
F8 :- Used while Debugging Applications
Shift + F8 :- Used While Debugging Applications
Ctrl + B :- Inserts a New Breakpoint
F10:-Line By Line execution
Ctrl+Tab:-To Shift B/W .net Editor Pages

c# 2005 cheat sheet

Store Images in Database

Sample application for storing and getting images from sql server.....

click here to download

Clear all TextBox values

protected void ClearControl(Control Ctrl)//passing the control
foreach (Control eachCtrl in Ctrl.Controls)//loop taking each controls
if (eachCtrl.Controls.Count > 0)
else if (eachCtrl is TextBox)
((TextBox)eachCtrl).Text = null;

To call the method like this:


oops concept

Why use interface ?

The following 2 examples will give bit more insight into use of interfaces. The first example explains how interface can be ploymorphically used. The second one explains how it can be used for multiple-implementation. Both the examples combined also describe a ISP or Interface Segrigation Principle.

Example 1: [Polymorphism] Suppose you have an application that writes data into different devices say HDD, FDD and CDW, in a buffered mode. Any number and any media may be used. It should also be possible plug-in/out any device any time. Each device has its own implementations. How do you ensure that this can be done without knowing the specific implementation of the device?

Solution: Lat them all implement an interface that defines common operations. The application can use the interface to make polymorphic calls.

public interface IMedia
void FlushData();
void OpenMedia();
void WriteData(Stream dataStream);

public class CDW : IMedia { ... }
public class HDD : IMedia { ... }
public class FDD : IMedia { ... }

public class DataApplication
CDW _cdw = new CDW(...);
HDD _hdd = new HDD(...);
FDD _fdd = new FDD(...);

IMedia _mediaDevices[] = new IMedia[] ({_cdw, _hdd, _fdd });

private void SomeDataWriteTask()

private void Close()
foreach(IMedia mediaItem in _mediaDevices)
// Ploymorphic call to flush the buffered
// data into correct implementations.

Example 2:
[Multiple Implementation] Continuing the above example now suppose you have another diagnosis application that needs to check few common performance factors of these devices. The dignostic application need not know the details of these implementations. However the DataApplication (application above) should not have any knowledge of these tasks. How to do this?

Solution: Let each media implement an interface that the diagnostic application can use to operate upon. So the modified design looks like:

public interface IMedia
void FlushData();
void OpenMedia();
void WriteData(Stream dataStream);

public interface IMediaMonitor
long GetSeekSpeed();
long GetSizeInBytes();
void MoveToOffset(long offsetPosition);

public class CDW : IMedia, IMediaMonitor { ... }
public class HDD : IMedia, IMediaMonitor { ... }
public class FDD : IMedia, IMediaMonitor { ... }

public class DiagnosisApplication
private void DoHealthCheck(IMediaMonitor someMedia)
IMediaMonitor mediaDevice = someMedia;

long l1 = mediaDevice.GetSeekSpeed();
long l2 = mediaDevice.GetSizeInBytes();

Source : from other site..