FCK Editor Validation

Here is a good example for FCK editor validation.

Declare a Custom Validator;

<asp:CustomValidator runat="server" ID="cvBody" SetFocusOnError="true" Display="dynamic" Text="The Body is required" ClientValidationFunction="ValidateContentText"></asp:CustomValidator>

Add this Javascript function to your page

function ValidateContentText(source,args)
var fckBody= FCKeditorAPI.GetInstance('<%=FCKeditor1.ClientID %>');
args.IsValid = fckBody.GetXHTML(true) != "";

Ref: “fck validation

Dynamic Data-Driven User Interface

In the below link, you can see how we can implement a dynamic data-driven user interface.

That means, the administrator of a web application can determine, what all controls are to be displayed in the user-side. Very useful article to begin with.

Creating a Dynamic Data-Driven User Interface

Critical Vulnerability in ASP.Net

A major security vulnerability was discovered in ASP.net last week and Microsoft has released a workaround to fix this issue. Using this vulnerability a hacker can gain access to any files in a web server which includes web.config file which mostly contains sensitive data.

I would recommend all of those who are working on ASP.Net application to read this:



Importing XML to SQL table

This post demonstrate importing the data expressed in XML to Microsoft SQL Server using the SqlBulkCopy class.

Before importing, you should create a table to receive the data that the SqlBulkCopy class process. Here in this example we will use a table “DummyEmails” to receive the data. The XML file which we use to import is “Email.xml”.


DataSet xmlDS = new DataSet();
//Name of the XML file

//Create the connection object
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[ "LMSConnectionString"].ToString());

//Creating the SqlBulkCopy object
SqlBulkCopy sqlBC = new SqlBulkCopy(connection);

//Specify the destination database table name
sqlBC.DestinationTableName = "DummyEmails";

//If the destination database table's column names doesn't match with the XML element names,
//then we have to relate the XML elements and the table column name.
//For that you can use the below code;
//sqlBC.ColumnMappings.Add("EmailId", "Email_id");
//sqlBC.ColumnMappings.Add("EmailAddress", "Email_Address");
//1st Parameter:Source Column, 2nd Parameter:Destination Column
//You may use the Column index too


catch { }

The SqlBulkCopy class can be used to write data only to SQL Server tables. However, the data source is not limited to XML file; any data source can be used, as long as the data can be loaded to a DataTable instance or read with a IDataReader instance.

Database table to XML file

Here I give an example of how we can create a XML file from a database table.

In this example, I had populated a dropdownlist with the tables in a database. Then I choose a table from the list, which needs to be generated as a XML file.

Listing all the tables in the Database

Listing all the tables in the Database

We will generate the XML file in the ‘SelectedIndexChanged’ event of the DropDownList.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
DataSet ds = new DataSet();

//Create the connection object
SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "LMSConnectionString"].ToString());

string strQuery = "Select * from " + DropDownList1.SelectedItem.Text;

SqlCommand sqlCmd = new SqlCommand(strQuery, sqlConn);
SqlDataAdapter sqlAdptr = new SqlDataAdapter(sqlCmd);

XmlDataDocument doc = new XmlDataDocument(ds);

//The name of the XML file to be generated
catch{ }

The above code will generate an XML file with the same name of the database table selected, in the root directory.

Read Data From an Excel File in ASP.NET

The following example shows how to display data from an excel spread sheet in a GridView. We will connect to a Microsoft Excel workbook using the OLEDB.NET data provider, extract data and then display the data in a GridView.

In the aspx page;

    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">

In the aspx.cs page;

using System.Data.OleDb;

    protected void Page_Load(object sender, EventArgs e)
        string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;data source=E:/DummyProject/Excel/Contacts.xlsx;Extended Properties=Excel 12.0;";
        OleDbConnection objConn = new OleDbConnection(strConn);
        //You must use the $ after the object you refer in the spreadsheet
        string strSql = "Select * From [Sheet1$]";
        OleDbCommand objCmd = new OleDbCommand(strSql, objConn);
            GridView1.DataSource = objCmd.ExecuteReader();
        catch (Exception exc)

As you see in the connection string ‘Microsoft.ACE.OLEDB.12.0′ is the new Access database engine OLE DB driver and is also capable of reading Excel 2003. For older versions of excel files, you can use the connection string ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/DummyProject/Excel/Contacts.xls;Extended Properties=Excel 8.0’

Server Application Unavailable

Some times the ASP.net developers come across the error below:

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable. Please hit the “Refresh” button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

It might work when you try some asp/html page in the browser.

If you google with the error, you can find a lot of forums discussed this issue.

This can happen for several reasons. An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Open the Event Viewer and see the error message reported (Start -> Programs -> Administrative Tools -> Event Viewer (Application) for ASP.NET). Review this log entry to find out what caused this error.

In some cases you cannot find any error message detailing the cause of this specific request failure in the event log. Once I come across such situation and below given how I managed to resolve this issue.

The reason was there was some mixing of asp.net 1.1 and 2.0 in the same application pool.


“In IIS, right click on the domain and choose Properties, the go under the Home Directory tab. If the “Application Pool” reads anything other than the domain you are looking at (like for example “DefaultAppPool”) then you probably have another website using that application pool. You need to change it.

In IIS, expand Application Pools, and create a new one. Call it whatever you want, although I would recommend calling it the name of the domain that you want to use the pool. Then go into the properties of the domain as described above, and change the application pool to the new one you created.”