Friday, January 28, 2011

Open a Parent window from Child window


window.opener.location.href="default.aspx";

// To make it on top
window.opener.focus();

Everything you would want to know about manipulating windows can usually be found here

Following link has good examples on various operations that can be done on window open in asp.net

http://www.irt.org/script/window.htm

Thursday, January 20, 2011

Steps for Resource File in Windows application

Get the Executing assembly
Assembly executingAssembly = Assembly.GetExecutingAssembly()

Path of executing assembly

string assemblyLocation = executingAssembly.Location;
string dirName = Path.GetDirectoryName(assemblyLocation);

Get the path of UI assembly
Assembly UIassembly = Assembly.LoadFile(Path.Combine(dirName, "dllname"));

Initialize the Resource Manager
ResourceManager = new ResourceManager(@"resourcename", UIassembly);

Thursday, January 6, 2011

Regular Expression for Date in dd/mm/yyyy

^(((((0[1-9])|(1\d)|(2[0-8]))/((0[1-9])|(1[0-2])))|((31/((0[13578])|(1[02])))|((29|30)/((0[1,3-9])|(1[0-2])))))/((20[0-9][0-9]))|((((0[1-9])|(1\d)|(2[0-8]))/((0[1-9])|(1[0-2])))|((31/((0[13578])|(1[02])))|((29|30)/((0[1,3-9])|(1[0-2])))))/((19[0-9][0-9]))|(29/02/20(([02468][048])|([13579][26])))|(29/02/19(([02468][048])|([13579][26]))))$

Wednesday, December 16, 2009

How to Export data from Excel to SQL using C#

The current example will show you how to export data from Excel to SQL database using C#. It requires OLEDB drivers need to be installed on your system(OLEDB drivers comes by default with office 2007 products) or you can download explicitly from http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en.

string strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0\"";

//OLEDB connection for Excel

OleDbConnection olConn = new OleDbConnection(strconn);
OleDbDataReader orr = default(OleDbDataReader);
olConn.Open();

DataTable dt = olConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);


OleDbCommand od = new OleDbCommand("SELECT * FROM ['" + ConfigurationManager.AppSettings["ExcelSheetName"].ToString() + "$']", olConn);
if (od != null)
{
orr = od.ExecuteReader();
//If Data Exists
if (orr.HasRows)
{
string strconn1 = null;
strconn1 = /* Provide connection string */
SqlBulkCopy sqCopy = new SqlBulkCopy(strconn1);
//Give the Destination table name
sqCopy.DestinationTableName = "SampleTable";
//Here the only condition is it takes the first character of first column of first row and creates column with it.
Eg: if there is a word like "Finance" in the first column of first row it takes the column names as Finance and the second column as F2 and 3rd as F3 .....

//So we need to create the destination table with the same column names and then do mapping
sqCopy.ColumnMappings.Add("F2", "F2");
sqCopy.ColumnMappings.Add("F3", "F3");
sqCopy.ColumnMappings.Add("F4", "F4");
sqCopy.ColumnMappings.Add("F5", "F5");
sqCopy.ColumnMappings.Add("F6", "F6");
sqCopy.ColumnMappings.Add("F7", "F7");
sqCopy.ColumnMappings.Add("F8", "F8");
sqCopy.ColumnMappings.Add("F9", "F9");
sqCopy.ColumnMappings.Add("F10", "F10");
//Then write to the server
sqCopy.WriteToServer(orr);

Sunday, December 6, 2009

XMPP Gateway Works with OpenFire

Now the XMPPGateway works with Openfire.All you need to do is to install the latest patch available for XMPP Gateway at
http://support.microsoft.com/?kbid=977187
and configure openfire to support only TCPDIALBACK

Tuesday, July 14, 2009

Differences between Idictionary and Hashtable

Both Idictionary and Hashtable are use to store data in a (Key,Value) format.
Here " Key " is any unique token which is used to identify its corresponding data or value uniquely, "Value" is the data which you want to store it can be any thing string, integer, float etc..
Both(Idictionary and Hashtable) are derived from System.Collections Class. are used for

1) Inserting Data
2) Deleting data
3) Modifying Data
4) Searching for a particluar value

Idictionary:

In Idictionary we need to clearly define what type of value we want to store. let say we want to store both key and value as strings, here is the syntax


IDictionary < string,string > Name;
Name= new Dictionary < string,string >

So in the above we have created Name as Idictionary where Key and value both takes strings.

Hashtable:

In hashtable no need to define any signature i.e you can store any kind of values. Hashtable take every key and value as an object but not as the value you have entered means eventhough we have entered Key and value as strings Hashtable internally treats them as objects but not as strings.

In the same hashtable you can store different values let say we have store Ist entry as (string, int) 2nd entry can be any thing let say (int, float). Since Hashtable treat every key or Value as an object .

Hashtable namelist;
nameList= new Hashtable();

Differences between Hashtable and Idictionary:
  • In Idictionary we need to explicitly define signature i.e what type of Key and value we want to store. Hashtable no need to define any structure or signature.

  • In Idictionary once we have defined signature there is no chance of entering values other than the signature we have specified. where as within the same hashtable we can enter any type of key,value pair.

  • In Hashtable we required Boxing and Unboxing to do any kind of manipulation with values. where as for Idictionary we don't require any kind of boxing and unboxing as we are already defined the signature.

  • Hashtable is useful if you don't know what all kind of values you might be storing in it. Idictionary is used if you know exactly what kind of (key , value) pair you will be using.Let say if you know that both Key and value are always strings then use Idictionary.

  • Hashtable is costly as every operation(inserting, modifying, deleting..) requires either Boxing or UnBoxing but where as Idictionary doesn't require any such things since we know the signature before hand.