Wednesday, June 16, 2010

DataTable To String Array in C# without using a for Loop

Many time we need need to get data from dataset\Datatable to array to pass it to some function or third API like x axis or y axis series of chart controls or to some other reporting or data binding control may be dropdown. it becomes difficult to get the data of a column(s) in array and finally we end up writing a for loop. here is a sample example by which we can simply get array of a column(s) with out a for loop
public static string DataRowToString(DataRow dr)
{
       return dr["columns"].ToString();
}
public string [] DataTableToArray(DataTable dt)
{
     DataRow[] dr = dt.Select();
     string [] strArr= Array.ConvertAll(dr, new Converter(DataRowToString));
     return strArr;
}

Array.ConvertAll() function simply converts the array of one to another so here in above example we are passing dr as an araay of datarows in first arguments. second argument is a Converter delegate type which convert one type to another so in this we will pass a link to delegate which is DataRowToString() function ,the delegate should know the input datatype and output datatype which is datatrow and string in this case respectively. function DataRowToString noe simply takes a datarow and return the string value for the column specified. which can be extended for multiple columns also.

Ref: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/46ef6ca8-7f66-489a-a0f6-b6b7c4200d16

Thursday, May 6, 2010

WSS3.0\MOSS2007 and "Integrated managed pipeline mode" of IIS7

Problem Description:
SharePoint site is on WIN2k8\IIS7\WSS3.0-SP2 and you have created a sample web app (blank site) which is running well with IIS7 "Classic managed pipeline mode" but when you change it to "Integrated managed pipeline mode", It does not work and throws an error message "500 internal server Error".
Discussion ,Action taken and Results:
As discussed, MOSS 2007 use “Classic application pool mode” in IIS 7 for the SharePoint site since MOSS 2007 use IIS 6.0/ISAPI functionality through an ISAPI module and that is part of “Classic application pool mode” .
If we will use the “ Integrated Request Pipeline” for the SharePoint 2007 site you will not be able to browse to the site.
Following is the TechNet article which talk about that SharePoint use “Classic application pool mode” for the Application pool.
1: http://msdn.microsoft.com/en-us/library/bb909693.aspx (How to: Verify or Correct the IIS Configuration for an Application Pool)
Details are:
1. On the Application Pools page, review all application pools for Team Foundation.
• Under .NET Framework Version, verify that v2.0 appears.
• Under Managed Pipeline Mode, verify that Classic appears.
2: http://technet.microsoft.com/en-us/library/cc262485.aspx (Determine hardware and software requirements (Office SharePoint Server))
Details are:
Windows components
After you have installed the operating system and applied all critical updates, you must configure the computer to be a Web server by enabling Internet Information Services (IIS) 6.0, including:
• Common files
• WWW
• Simple Mail Transfer Protocol (SMTP)
You must configure the server to use IIS 6.0 worker process isolation mode. This is the default setting in new installations. However, if you have upgraded from IIS 5.0 on Windows Server 2000, Run WWW in IIS 5.0 isolation mode is enabled, and you must change this setting to use IIS 6.0 worker process isolation mode.
To enable e-mail notifications, you need to configure incoming and outgoing e-mail settings. To configure sending e-mail alerts and notifications, you must specify an SMTP e-mail server. To configure your installation so that your SharePoint sites can accept and archive incoming e-mail, you must install the IIS SMTP service

Additional info:
Integrated Request Pipeline:
Think of the integrated request pipeline as the essential set of linear steps that must occur every time a page is served up (as seen in Figure 2). Typically, some sort of authentication must take place, followed by authorization to retrieve content, determination and execution of the handler needed for that content, performance of any necessary logging, and finally sending a response. The integrated request pipeline provides IIS 7.0 the flexibility to run different application frameworks at the same time. For example, you can run Forms authentication on top of PHP content with a custom logging module, all together in the same pipeline.

Each Web site on the server has an integrated request pipeline and can be run in one of two modes, Integrated and Classic. Integrated, the default, allows particular pieces of functionality to be plugged into the pipeline, giving you granular control over the request process. For compatibility, Classic mode reproduces IIS 6.0/ISAPI functionality through an ISAPI module into the pipeline. This is very helpful when migrating your applications to IIS 7.0.
More info : http://technet.microsoft.com/en-us/magazine/2008.03.iis7.aspx
Classic application pool mode:
When an application pool is in Classic mode, IIS 7 handles requests as in IIS 6.0 worker process isolation mode. ASP.NET requests first go through native processing steps in IIS and are then routed to Aspnet_isapi.dll for processing of managed code in the managed runtime. Finally, the request is routed back through IIS to send the response.
This separation of the IIS and ASP.NET request-processing models results in duplication of some processing steps, such as authentication and authorization. Additionally, managed code features, such as forms authentication, are only available to ASP.NET applications or applications for which you have script mapped all requests to be handled by aspnet_isapi.dll.

Tuesday, April 6, 2010

A HTML Table based Chart control in ASP.NET\MOSS 2007

Content:
  • Introduction
  • Various options to display charts on web
  • Code Walkthrough
  • Advantages
  • Limitation
Introduction:
A chart is a visual representation of data represented in various code\colors. It represents the summary of large chunk of unorganized data in an easy to understand manner which becomes very helpful in analysis, decision making and trend setting. The extensive usage of data over the web makes it very important control nowadays. Most of the modern web2.0 websites uses charts as one of the techniques to convey data to site visitors.
The article below gives a summary to create a 3d column charts in asp.net which can be modified and used in various other web supported platforms

Various options to display charts on web
Following are options to use chart on web in .net plateform
Microsoft chart controls:
Microsoft recently launched the rich functionality chart controls for asp.net to work with .net framework 3.5. It can be downloaded from the link below and used as any other controls in asp.net
http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C
These chart controls will be part of visual studio 2010 release.
GDI+ charts:
GDI+ charts are traditionally used chart controls over the web. It uses various drawing API of com\.net to draw a picture at server end first and then transfer the picture on the web. These controls are very complex and resources consuming.
Creating 3d and nice look and feel also bit cumbersome
HTML Table based Charts:
The technique used below is to generate line charts with the help of html tables and 3d images. It draws the table calibrate a 3d image to fit in the row as per the given x\y axis value. Hence become very lightweight and supported on any .net framework\ other platforms. Below is the sample screen shot.
Code Walkthrough: There are mainly two code files in this project. A chart user control and a web page to host\call chart
Chart controls expose various properties to set the different parameters of chart like width, column height, y axis values, x axis values etc. DrawGraph() is called to draw chart based on the x axis and y axis values set in the properties. It normalize the values provides for x axis and resize it as per the chart width. Below are the algorithm steps.
  • Define the color image array to denote the x axis values
  • Find out the max value in the x axis collection
  • Get the mod by dividing chart width with max value
  • Draw a table and draw a row for each value
  • For each value in the collection multiply the mod with value to expand and divide chart width with standard param to contract
  • Set this value as the length of image
  • Repeat the colors if color array is less than the value specified
  • Emit the constructed html on div\label tag
 Advantages:
  • It really simple, lightweight, 3d bar chart with nice look and feel
  • The code\logic can be modified to work on any other platform\language
  • A html table base web chart renders well on all type of browsers
  • It can be used in any .net framework\SharePoint
  • Can be customized easily based on the requirements
Limitation:
  • Can’t use similar technique to draw pie charts
code available on request