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:

http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx

_

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”.

try
{

DataSet xmlDS = new DataSet();
xmlDS.ReadXml(Server.MapPath("Email.xml"));
//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


connection.Open();
sqlBC.WriteToServer(xmlDS.Tables[0]);

connection.Close();
}
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)
{
try
{
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);
sqlAdptr.Fill(ds);


XmlDataDocument doc = new XmlDataDocument(ds);


doc.Save(MapPath(DropDownList1.SelectedItem.Text+".xml"));
//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.

Microsoft’s WebsiteSpark Program

Microsoft announced a new program which is designed for independent web developers and web development companies that build web applications and web sites on behalf of others. This program offers software licence that we can use for three years at no cost.

Here is a list of software which can be downloaded once you enrolled in to this program:

  • 3 licenses of Visual Studio 2008 Professional Edition
  • 1 license of Expression Studio 3 (which includes Expression Blend, Sketchflow, and Web)
  • 2 licenses of Expression Web 3
  • 4 processor licenses of Windows Web Server 2008 R2
  • 4 processor licenses of SQL Server 2008 Web Edition
  • DotNetPanel control panel (enabling easy remote/hosted management of your servers)

The only two requirements to join the program are:

  • Your company builds web sites and web application on behalf of others.
  • Your company currently has less than 10 employees.

For more information check:

ScottGu’s Blog or Microsoft’s site.

Ajax Loading Images

Here is a site from where you can generate your-own ajax loading images.

http://www.ajaxload.info

Easy as 1-2-3

1. Select type of indicator, background color and foreground color.
2. Generate the image.
3. Download the generated image.

Microsoft’s Bing

Microsoft’s new search engine ‘Bing‘ unveiled by Microsoft CEO Steve Ballmer on May 28, 2009. Bing went fully online on June 3, 2009. It is a replacement for Live Search(Windows Live Search, MSN Search).

The homepage is crisp and clear and the image will change daily. The Bing interface is refreshingly clean and results are displayed by helpful categories. For example, I type books and results are grouped by History, Electronic, Best Sellers, Publishing and Writing. “Simple Organized System, thats Bing”

The Indian version currently doesn’t have the full functionality.

The Indian version doesn’t Have Search History And The Image On The Bing Home Page Here Is Not Interactive As In The Us Version To Explore The Full Version Of Bing. You can change the Indian version to the US version by clicking on the ‘India’ link at the top right of the page and selecting the United States from the country list.

Some of the interesting features that you will notice at first glance:

When you hover on a search result, you will see the orange icon – which gives you a quick preview of the site (text preview). Very useful, if you are still not sure of clicking.

Just search for any video on Bing Videos and hover the mouse over any of the video thumbnail to watch a short clip.(WOW!)

Bing is such a decision engine. It provides an easy way to make more informed choices. It organizes popular results by category to help you get the answers you’re looking for without having to guess at the right way to formulate your query.

Now is Bing a real competitor for Google? Check the here to get a comparision of Bing with Google

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;


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

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);
        try
        {
            objConn.Open();
            GridView1.DataSource = objCmd.ExecuteReader();
            GridView1.DataBind();
        }
        catch (Exception exc)
        {
            Response.Write(exc.ToString());
        }
        finally
        {
            objConn.Dispose();
        }
    }

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’


FLV video not streaming

In one of my web application, there was one FLV file that has to be shown when the home page is viewed in a browser. During the development time it was working fine. However when I put the files in the server and tried to access the home page, then the flv file didn’t show up. Instead it showed the space for .flv file with black color.

After some googling I found the reason: ‘With IIS 6.0, Microsoft changed the way streaming media is handled. Previous versions of IIS did not require any modification to stream Flash Video. Microsoft IIS 6.0, the default web server that ships with Windows 2003, requires a MIME type to recognize that FLV files are streamed media.’
To overcome the above difficulties just follow the blow steps;


1. On the Windows 2003 server, open the Internet Information Services Manager.
2. Expand the Local Computer Server.
3. Right-click the local computer server and select Properties.
4. Select the MIME Types tab.
5. Click New and enter the following information:
    o Associated Extension box: .FLV
    o MIME Type box:flv-application/octet-stream
6. Click OK.
7. Restart the World Wide Web Publishing service.

Note: These files work correctly if tested on other operating systems. The issue affects all FLV files played via Windows 2003 server, including files made with the Flash Video Kit for Dreamweaver MX 2004.