Sunday, August 30, 2009

Create CSV file using System.IO

I found an excellent article to create an error free CSV file in a simple manner. Thanks to Lakshmi. You can get the code here.

Session State Monitor

When I walkthrough MSDN India Web site, I found this useful tool to monitor the session state values stored in Sql Server. My current application is using web farms. During deployment, we faced lot of issues wrt Sql server session mode. We forgot to serialize some of the items, which are stored on the session. After digging the MSDN, I found this tool and thought of sharing with you all. You can download the tool here.

- Chan

Tuesday, July 21, 2009

Build Tip...

Set retail="true" in your machine.config






This will kill three birds with one stone. It will force the 'debug' flag in the web.config to be false, it will disable page output tracing, and it will force the custom error page to be shown to remote users rather than the actual exception or error message. For more information you can read Scott Guthrie's post or the MSDN reference.

Tuesday, December 2, 2008

Very useful link for Sql Server - Everyone has to see

http://www.microsoft.com/sqlserver/2005/en/us/demos.aspx

Important Free tools

Here are tools I use on a regular basis. They have attributes I find essential:

They are free.
They do one thing and they do it well.

XPathBuilder: Dynamically searches XML. Bubba Soft

Expresso: Design and test regular expressions before you compile: Ultrapico

WinMerge: Compares files and directories: Winmerge

XVI32: A hex editor. With this I learned about the BOM: Christian Maas

While these tools are great, they can really add to your productivity when you integrate them into Visual Studio. When you right click a file in the solution and use "Open With…" You can add these tools to the list of applications.

I hope you find this useful.

Create an XSD Schema….without knowing a darn thing about XSD.

Back in the old days, when dinosaurs roamed the earth, developers wanting to exchange data between applications used binary formatted data, hardcoded text field lengths, or delimited text files. Much parsing and error checking was involved. It was tedious.
With XML files a lot of that work can be done automatically… with one major drawback: You have to learn yet another 'language': XSD.
Here is how to create XML Schemas using classes in the .Net framework without knowing anything about XSD:
protected void Button1_Click(object sender, EventArgs e)
{
// The DataSet name becomes the root XML element
DataSet MyDataSet = new DataSet("Golfers");

// This can be confusing, the 'DataTable' will actually
// become Elements (Rows) in the XML file.
DataTable MyDataTable = new DataTable("Golfer");

MyDataSet.Tables.Add(MyDataTable);

// Make columns attributes so we can
// link directly to a GridView
MyDataTable.Columns.Add(new DataColumn("ID",
typeof(System.Int32),
null,
MappingType.Attribute));

MyDataTable.Columns.Add(new DataColumn("Name",
typeof(String),
null,
MappingType.Attribute));

MyDataTable.Columns.Add(new DataColumn("Birthday",
typeof(DateTime),
null,
MappingType.Attribute));

// Write out the XSD
MyDataSet.WriteXmlSchema(@"C:\GolfersSchema.xsd");

// Put some data in the table
DataRow TempRow;
TempRow = MyDataTable.NewRow();
TempRow["ID"] = 1;
TempRow["Name"] = "Bobby Jones";
TempRow["Birthday"] = new DateTime(1902, 3, 17);
MyDataTable.Rows.Add(TempRow);

TempRow = MyDataTable.NewRow();
TempRow["ID"] = 2;
TempRow["Name"] = "Sam Snead";
TempRow["Birthday"] = new DateTime(1912, 5, 27);
MyDataTable.Rows.Add(TempRow);

TempRow = MyDataTable.NewRow();
TempRow["ID"] = 3;
TempRow["Name"] = "Tiger Woods";
TempRow["Birthday"] = new DateTime(1975, 12, 30);
MyDataTable.Rows.Add(TempRow);

// Write out the data
MyDataSet.WriteXml(@"C:\Golfers.xml");
}
Here is how the data is saved, not bad eh?






Here is what the Schema looks like. Note, you can always go into the schema and tweak things.
















Here is one way to validate the XML against the Schema:
protected void Button2_Click(object sender, EventArgs e)
{
// First, read in the XML schema
DataSet MyDataSet = new DataSet();
MyDataSet.ReadXmlSchema(@"C:\GolfersSchema.xsd");

// Now, read in the XML file (it is validated
// against the schema when it is read in).
MyDataSet.ReadXml(@"C:\Golfers.xml");

// See how it looks in a GridView
GridView1.DataSource = MyDataSet;
GridView1.DataBind();
}
You can test the validation by modifying the XML file and trying to read it:
set the homepage