Tech Insight !

Technical blog on ASP.Net, PHP, Web Development, Web hosting , Database Programming
Home » Archive by category '.Net 2.0'

Combine/Compress/Minify JavaScript, CSS in Asp.net

Introduction:

When we design and develop the website, the performance is in the core of development. The system you are developing must produce the result with high speed. For the web development perspective, website load performance is very essential thing to take care of. You need good working layout, easy layout and easy navigation.

Here with this article I m not going to talk about of all the aspects of web application performance improvements. But I am specifically targeting the topic when it comes to the CSS and JavaScript faster loading in the client browser. In fact Google is also counting the speed of your website site when indexing to your website.

The goal was to improve overall performance on the client side. At the same time, it will show how we can force a client side script to be coached at the browser, so that in subsequent visit, it will take those scripts from the cache. This becomes increasingly important when using AJAX techniques within an application that introduce new features and functionality.

First of all I will outline the requirements and essential steps that this project is made of. So that if you want to implement the same in your development, it become easy for you to set up project.

To download complete project, click here

Setup:

To begin with, we will have following list of files to be created in the development studio.

  1. 2 XML files, first one to hold source of JS files for each page and second to hold CSS files for each page.
  2. A generic class that implement IHttpHandler, that will be used to delivery combined and compressed JavaScript/CSS at the client.
  3. And at last your .ASPX file that will be used to serve combined and compressed Javascript/CSS at client side.

Step by Step Implementation:

Now let’s get dig into the actual development. To summarize, let’s say we have a page default.aspx that has following no. of JavaScript files and CSS files. Think of these file that we wanted to combine them and deliver at one go at the client browser.

  1. jquery.js
  2. script-file-1.js
  3. style-1.css
  4. style-2.css

As you can see, we have 2 different JavaScript file & 2 CSS files. So what basically we will do in the next is to create a utility which can combine given JavaScript and compress it, then send it to client browser. Next the same process will be done for the CSS. Both the CSS files will be combined and compressed and send to client browser.

Now it’s time to take a look at into actual stuff that does this underlying work.

First of all we will create a CS class file that will hold the programming stuffs.

So perform the following steps to create & configure that CS class file.

  1. Create CS class file with the name ScriptCombiner.cs and put the following code in that.

public class
ScriptCombiner : IHttpHandler{

private readonly static TimeSpan CACHE_DURATION = TimeSpan.FromDays(1);

private HttpContext context;

public void ProcessRequest(HttpContext context){

}

public bool IsReusable{

get { return true; }

}

}

As you can see, we are implementing the IHttpHandler interface.

You can write custom HTTP handlers to process specific, predefined types of HTTP requests in any Common Language Specification (CLS) compliant language. Executable code defined in the HttpHandler classes, rather than conventional ASP or ASP.NET Web pages, responds to these specific requests. HTTP handlers give you a means of interacting with the low-level request and response services of the IIS Web server and provide functionality much like ISAPI extensions but with a simpler programming model.

We are also implementing IsReusable properly as it is compulsory to implement as a part of inheritance of IHttpHandler interface.

Now, let’s put the nuts & bolts inside the ProcessRequest function. I will also explain you the step by step each execution that is inside this function.

  1. We will also create another CS class file that is used to compress JavaScript. That file is named as “JavaScriptMinifier.cs”. Please take a look at the attached project solution file. As it is contain long lines of code, I can’t put it here.
  2. Complete your class file with following functions.

public void ProcessRequest(HttpContext context)

{

string xStrType, xStrSet, xStrVer, xStrpagecode;

Boolean xBlnCanCompress;

this.context = context;

HttpRequest request = context.Request;

xStrType = (!String.IsNullOrEmpty(request["type"])) ? request["type"] : null;

xStrSet = (!String.IsNullOrEmpty(request["s"])) ? request["s"] : null;

xStrVer = (!String.IsNullOrEmpty(request["v"])) ? request["v"] : null;

xStrpagecode = (!String.IsNullOrEmpty(request["pcode"])) ? request["pcode"] : null;

//first check if client browser can support compressions

xBlnCanCompress = CanClientGZip(request);

using (MemoryStream memStream = new MemoryStream(8092))

{

Stream writer;

//if browser is supporing GZip compression then create a new object using ICSharpCode.SharpZipLib.GZip

//library which allow the compressed respose to send to client

if (xBlnCanCompress)

writer = (new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memStream));

else

writer = memStream;

using (writer){

//now its time to read all the script/css files into a StringBuilder object.

StringBuilder combinedSource = new StringBuilder();

foreach (string file in GetFileNames(xStrSet, xStrpagecode, xStrType))

combinedSource.Append(System.IO.File.ReadAllText(context.Server.MapPath(file), Encoding.UTF8));

//Upto now we have combined all css/javascript based on request.

//its now time to remove extra white spaces and other unwanted characters from respose.

//compression will take place now.

string minified;

//use the YUI Javascript/CSS minifier to compress all js files

if (xStrType == “js”)

minified = combinedSource.ToString();

else

minified = CompressCSS(combinedSource.ToString());

// Send minfied string to output stream

byte[] bt = Encoding.UTF8.GetBytes(minified);

writer.Write(bt, 0, bt.Length);

}

//cache the respose so that in next request it can be reused

byte[] responseBytes = memStream.ToArray();

//context.Cache.Insert(GetCacheKey(xStrSet, xStrType, xStrVer, xBlnCanCompress), responseBytes, null, System.Web.Caching.Cache.NoAbsoluteExpiration, CACHE_DURATION);

// Generate the response

this.WriteBytes(responseBytes, xBlnCanCompress, xStrType);

}

}

private bool CanClientGZip(HttpRequest request){

string acceptEncoding = request.Headers["Accept-Encoding"];

if (!string.IsNullOrEmpty(acceptEncoding) &&

(acceptEncoding.Contains(“gzip”) || acceptEncoding.Contains(“deflate”)))

return true;

return false;

}

// helper method that return an array of file names inside the text file stored in App_Data folder

private static string[] GetFileNames(string setName, string pagecode, string type)

{System.Xml.XPath.XPathDocument doc2;

System.Xml.XPath.XPathNavigator navigator;

System.Xml.XPath.XPathNodeIterator iterator;

System.Collections.Generic.List<string> scripts = new System.Collections.Generic.List<string>();

string key;

if (type == “js”)

key = “scriptfile”;

else

key = “cssfile”;

if (System.Web.HttpContext.Current.Cache[key] != null)

{doc2 = (System.Xml.XPath.XPathDocument)System.Web.HttpContext.Current.Cache[key];

}

else

{

string filename;

filename = System.Web.HttpContext.Current.Server.MapPath(String.Format(“~/App_Data/{0}.xml”, setName));

doc2 = new System.Xml.XPath.XPathDocument(filename);

System.Web.HttpContext.Current.Cache.Insert(key, doc2, new System.Web.Caching.CacheDependency(filename), DateTime.Now.AddMinutes(60), TimeSpan.Zero);

}

navigator = doc2.CreateNavigator();

if (type == “js”)

iterator = navigator.Select(“/scripts/page[@pagecode='" + pagecode + "']/script”);

else

iterator = navigator.Select(“/styles/page[@pagecode='" + pagecode + "']/style”);

while (iterator.MoveNext())

scripts.Add(iterator.Current.InnerXml);

return scripts.ToArray();

}

private string GetCacheKey(string type, string setName, string version, bool cancompress)

{

return “HttpCombiner.” + setName + “.” + type + “.” + version + “.” + cancompress;

}

private void WriteBytes(byte[] bytes, bool isCompressed, string type)

{

HttpResponse response = context.Response;

response.AppendHeader(“Content-Length”, bytes.Length.ToString());

if (type == “js”)

response.ContentType = “application/x-javascript”;

else

response.ContentType = “text/css”;

if (isCompressed)

response.AppendHeader(“Content-Encoding”, “gzip”);

else

response.AppendHeader(“Content-Encoding”, “utf-8″);

context.Response.Cache.SetCacheability(HttpCacheability.Public);

context.Response.Cache.SetExpires(DateTime.Now.Add(CACHE_DURATION));

context.Response.Cache.SetMaxAge(CACHE_DURATION);

response.ContentEncoding = Encoding.Unicode;

response.OutputStream.Write(bytes, 0, bytes.Length);

response.Flush();

}

public static
string GetScriptTag(string setname, string pageid, string type, string ver)

{

string result = “”;

if (type == “js”)

result += String.Format(“<script type=\”text/javascript\” src=\”/” + Web.Utility.Functions.GetURLPrefix() + “ScriptCombiner.axd?s={0}&v={1}&type=js&pcode={2}\”></script>”, setname, ver, pageid);

else

result += String.Format(“<link link href=\”ScriptCombiner.axd?s={0}&v={1}&type=css&pcode={2}\” rel=\”stylesheet\” type=\”text/css\”/>”, setname, ver, pageid);

return result;

}

public static string CompressCSS(string body)

{

body = Regex.Replace(body, “/\\*.+?\\*/”, “”, RegexOptions.Singleline);

body = body.Replace(” “, string.Empty);

body = body.Replace(Environment.NewLine + Environment.NewLine + Environment.NewLine, string.Empty);

body = body.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

body = body.Replace(Environment.NewLine, string.Empty);

body = body.Replace(“\\t”, string.Empty);

body = body.Replace(” {“, “{“);

body = body.Replace(” :”, “:”);

body = body.Replace(“: “, “:”);

body = body.Replace(“, “, “,”);

body = body.Replace(“; “, “;”);

body = body.Replace(“;}”, “}”);

body = Regex.Replace(body, “/\\*[^\\*]*\\*+([^/\\*]*\\*+)*/”, “$1″);

body = Regex.Replace(body, “(?<=[>])\\s{2,}(?=[<])|(?<=[>])\\s{2,}(?=&nbsp;)|(?<=&ndsp;)\\s{2,}(?=[<])”, string.Empty);

return body;

}

You are now almost done with 50% of work for your project.

Now let’s take a look at the few of important execution steps that are in this function.

First of all we are declaring four different string variables:

string xStrType, xStrSet, xStrVer, xStrpagecode;

They will be used to get the Querystring passed in to this handler. This is utilized later on the code.

Moving next, you will find these function call:

//first check if client browser can support compressions

xBlnCanCompress = CanClientGZip(request);

This is basically to check does client browser support GZip compression.

Gzip compression, otherwise known as content encoding, is a publicly defined way to compress textual content transferred from web servers to browsers. HTTP compression uses public domain compression algorithms, like gzip and compress, to compress XHTML, JavaScript, CSS, and other text files at the server. This standards-based method of delivering compressed content is built into HTTP 1.1, and most modern browsers that support HTTP 1.1 support ZLIB inflation of deflated documents. In other words, they can decompress compressed files automatically, which saves time and bandwidth.

In the next step it is preparing the stream object used to hold the response output. We will not take dipper look into that code. As I expect that the a beginning developer even must be able know about next few line of code. J

Let’s move to the line of code:

//now its time to read all the script/css files into a StringBuilder object.


StringBuilder combinedSource = new
StringBuilder();

foreach (string file in GetFileNames(xStrSet, xStrpagecode, xStrType))

combinedSource.Append(System.IO.File.ReadAllText(context.Server.MapPath(file), Encoding.UTF8));

As you can see in the foreach loop, it is calling to method GetFileNames, by passing 3 different parameters. Here this is also core and important part of this project. Let me outline you first what this function basically do. This function will read to the “script.xml” file that hold content of script file that we want to load. Please look inside the attached project solution to understand it better. The function will read xml file and return array of string object containing JavaScript files to read.

In the subsequent line of code, it iterate through each file name and read it. Each content of read file is placed inside a StringBuilder object.

Please take look at the code inside the GetFileNames function to understand what is actually happening inside it. It fetches the JavaScript/CSS based on the parameter passed. And return either the JavaScript file name array or CSS file name array.

So now we have a combined script/CSS with us. It’s a time to minify JavaScript/CSS now.

Following line of code will minify respective JavaScript/CSS based on type of client script requested.

//use the YUI Javascript/CSS minifier to compress all js files


if (xStrType == “js”)

{

JavaScriptMinifier minifier = new
JavaScriptMinifier();

minified = minifier.Minify(combinedSource.ToString());

}

else

{

minified = CompressCSS(combinedSource.ToString());

}

The JavaScriptMinifier has been created in the 2nd step. Please refer to the attached solution project for more detail regarding this class file. I have adopted this class file from one of the article

You will also see function CompressCSS that is used to compress CSS file. The compressor of CSS file is done through just few regular expression. JavaScript compression has different algorithm.

After that it is calling to WriteBytes function that will prepare the combined & compressed JavaScript & CSS response and send it to the client.

Hurray… as part of implementation we are done.

Now it’s time to check that in action. You can run the project attached here with and check it In live action.

To download complete project, click here

Let’s compare the result of two different pages. The first one is with the compressed JavaScript & CSS. The second one is with the normal JavaScript & CSS. We will also see the difference in load time and size of content received.

Response time with compressed JavaScript & CSS.

Response time without compressed JavaScript & CSS.

As you can see from given statistics

With Combined & Compressed JavaScript and CSS ..

Total request: 3

Response size: 16.3 KB

Without Combined & Compressed JavaScript and CSS ..

Total request: 5

Response size: 96 KB

You can clearly see the difference between these two request.

To get more idea open and run the project yourself. That will give you better idea.

Hope you will find it very useful.

Happy coding…. J

NOTE :

If you are in need of any Web Development feel free to Inquire us . Dhanashree Inc. Expertise in Asp.net Development, Php Development, Website designing, Open Source customisation. Dhanashree Inc can be our offshore development company / outsourcing web development company, hire dedicated web programmers.

Above information is for knowledge sharing if you have problem / issue / suggestion please intimate us with details for proper and prompt action.

Custom error tracking library in asp.net using XML & C#

Being an asp.net developers we develop a web project and get it completed in a months of time as there are many organizations which works on very tight bound timeline for developing web sites Or web application projects. And delivers the project to client in months of time

While after project delivery if client come up saying that they are facing problems or application is giving errors, that time it always becomes a headache for a developer to test each things even whole project sometimes to find a smaller errors (by means of error here we are not talking about logical errors, we talking about exceptions which mostly responsible for errors in the application), there are many exceptions .net framework fires which we never come to find out while debugging or developing the application. Those exceptions never affect directly to the application but each small exception puts the unnecessary load on the server.

Here is the solution to track each and every smallest things happening inside your asp.net web application. Which I named as “Custom error tracking library

Custom error tracking library

Very first question will come is that, what is the core concept for this.

Concept is like we will be maintaining an XML file with a predefined structure which I have built which will contain all the required fields as nodes and subs. Which we call as errorlog.xml

There will be a CS library file which will track each and every minor errors/exceptions happens inside the application or .net framework and will put the error details inside the XML file.

Once we got CS library ready with us we just have to a simple function with 2 overload methods as per requirement in each try/catch blocks of the code and also in Application_Error event of Global.asax file.

XML File (errorlog.xml)

<?xml version=”1.0″ encoding=”utf-8″?>

<errorlog>

<error>

<datetime>datetime</datetime>

<filename>filename</filename>

<classname>classname</classname>

<methodname>methodname</methodname>

<errormethod>errormethod</errormethod>

<messsage>ErrorMessage</messsage>

<errordetails>Details goes here</errordetails>

<IP>IP adress</IP>

<url>URL</url>

</error>

<error>

</errorlog>

Root node of XLM file will be <errorlog></errorlog> inside root node there will be a sub node <error></error> which will get duplicated for each error. For each error, library will generate a node will all the below listed details in XML file. Next to last error node. So for each error there will be a seaprate ERROR node.

Each fields of the above XML file is descibed beloe :

  1. 1. Datetime : date and time of the error/exception
  2. 2. File name : file name where exception or error happens
  3. 3. Class name : classname in which error occurred
  4. 4. Methodname : function name where errored
  5. 5. Errormethod : name of the function which contains error code.
  6. 6. Message : error message/exception message
  7. 7. Error details: detailed error description which will show wholestack trace of the functional execution.
  8. 8. IP : client IP address
  9. 9. URL : absolute error ULR

CS library

There will be a CS library file where we will write all functionality for error handling and writing errors into XML file.

errorHamdler.cs file will have 2 statis methods named WriteError(), there will be 2 overloaded methods for same functions with diff. parameters.

CS file will look as given below. We name it as errorHamdler.cs

errorHandler.cs

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Reflection;

using System.Diagnostics;

namespace code_center

{

public class errorHandler

{

string _strErrorMessage, _strDetails, _strClassName, _strMethodName;

DateTime _dtOccuranceTime = new DateTime();

public errorHandler()

{

}

public errorHandler(DateTime time, string className, string methodName, string errorMessage, string details)

{

_dtOccuranceTime = time;

_strClassName = className;

_strDetails = details;

_strErrorMessage = errorMessage;

_strMethodName = methodName;

}

public static void WriteError(Exception ex)

{

WriteError(ex, “”);

}

public static void WriteError(Exception ex, string fileName)

{

XmlDocument doc = new XmlDocument();

string strRootPath = System.Configuration.ConfigurationManager.AppSettings["logfilepath"].ToString();

string xmlPath = System.Web.HttpContext.Current.Server.MapPath(strRootPath);

doc.Load(@xmlPath);

XmlNode newXMLNode, oldXMLNode;

oldXMLNode = doc.ChildNodes[1].ChildNodes[0];

newXMLNode = oldXMLNode.CloneNode(true);

StackTrace stackTrace = new StackTrace();

StackFrame stackFrame = stackTrace.GetFrame(1);

MethodBase methodBase = stackFrame.GetMethod();

newXMLNode.ChildNodes[0].InnerText = DateTime.Now.ToString();

newXMLNode.ChildNodes[1].InnerText = fileName;

newXMLNode.ChildNodes[2].InnerText = methodBase.DeclaringType.FullName;

newXMLNode.ChildNodes[3].InnerText = methodBase.Name;

newXMLNode.ChildNodes[4].InnerText = ex.TargetSite.Name;

newXMLNode.ChildNodes[5].InnerText = ex.Message;

newXMLNode.ChildNodes[6].InnerText = ex.StackTrace;

newXMLNode.ChildNodes[7].InnerText = System.Web.HttpContext.Current.Request.UserHostAddress;

newXMLNode.ChildNodes[8].InnerText = System.Web.HttpContext.Current.Request.Url.OriginalString;

doc.ChildNodes[1].AppendChild(newXMLNode);

doc.Save(@xmlPath);

doc.RemoveAll();

}

}

}

In above code there is a line “string strRootPath = System.Configuration.ConfigurationManager.AppSettings["logfilepath"].ToString();”

We need to give XML file path also where we have placed XML file in the project, so just have to add 1 line in web.config file as given below to store actual XML file path, which will be used in abiove functon.

Code inside web.config

<appSettings>

<add key=”logfilepath” value=”~/errorHandling/errorlog.xml”/>

</appSettings>

How to use error handler in application

Now everything is ready to be used in real time application. In each try/catchblock we have to call

Writeerror() function as described below .

Code inside Default.aspx.vb

protected void Page_Load(object sender, EventArgs e)

{

try

{

throw new Exception(“Custom error”);

}

catch (Exception ex)

{

Response.Write(ex.Message);

code_center.errorHandler.WriteError(ex, “Default.aspx.vb”);

}

}

Apart from each try/catch blocks we will put some code in Global.asax file also, as given below.

void Application_Error(object sender, EventArgs e)

{

code_center.errorHandler.WriteError(Server.GetLastError().GetBaseException(), “Global.asax”);

}

The reason behind putting code in Global.asax file is very important and necessory as there might be many exceptions which occurs at application level and canot be tracable in any try/catch blocks in any function or events. So anyerror except try/catch blocks will come in this event (Application_Error) and will get inserted intoXML file.

That’s it, we have done with the error handling, and all errors will be tractable from the XML file which is being generated via the error handler.



NOTE :

If you are in need of any Web Development feel free to Inquire us . Dhanashree Inc. Expertise in Asp.net Development, Php Development, Website designing, Open Source customisation. Dhanashree Inc can be our offshore development company / outsourcing web development company, hire dedicated web programmers.

Above information is for knowledge sharing if you have problem / issue / suggestion please intimate us with details for proper and prompt action.

List of technology which can be adopted into development

Business Intelligence Application Development

Companies are investing millions of dollars in ERP solutions or have invested till date to improve the way they conduct their business. While ERP provides significant benefits organizations are finding that, in order to achieve critical decision making business goals, they often need to supplement it with additional external reporting capabilities for it end users. With the wealth of data entered and stored in ERP databases the ability to analyze and interpret the data is significant for management reporting. With Business Intelligence tool, it has greatly alleviated the backlog of report requests and has provided users with decision making information in a timely manner.

Business Intelligence is a method of storing and presenting key enterprise data so that anyone in your company can quickly and easily ask questions of accurate and timely data. Effective BI allows end users to use data to understand why your business got the particular results that it did, to decide on courses of action based on past data, and to accurately forecast future results.

BI data is displayed in a fashion that is appropriate to each type of user, i.e. analysts will be able to drill into detailed data, executives will see timely summaries, and middle managers will see data presented at the level of detail that they need to make good business decisions. Microsoft’s BI uses cubes, rather than tables, to store information and presents information via reports. The reports can be presented to end users in a variety of formats:Windows applications,Web Applications, and Microsoft BI client tools, such

as Excel or SQL Reporting Services.

Need for the BI application:

Check out following article where it is explain what is the important of BI application

http://www.cio.com/article/153500/Need_for_Business_Intelligence_Grows_Too_Much_Information_Not_Enough_Insight

Microsoft products involved in BI application development:

SQL Server 2005: This is the preferred staging and, possibly, source location for BI solutions. Data can actually be retrieved from a variety of data stores (Oracle, DB2, and so on), so a SQL Server installation is not strictly required to build a Microsoft BI solution. However, due to the integration of some key toolsets that are part of nearly all BI solutions—for example, SSIS or SQL Server Integration Services, which is usually used to perform the ETL of source data into the data warehouse—most BI solutions will include at least one SQL Server 2005 installation. Another key component in many BI solutions is SQL Server Reporting Services (SSRS). When working with SQL Server to perform OLAP administrative tasks, you will use the management interface, which is called SQL Server Management Studio (SSMS).

SQL Server Analysis Service: This is the core server in Microsoft’s BI solution. SSAS provides storage for the data used in cubes for your data warehouse.

SQL Server 2005 Integration Service: This toolset is a key component in most BI solutions that is used to import, cleanse, and validate data prior to making the data available to the analysis Services for reporting purposes. It is typical to use data from many disparate sources (relational, flat file, XML, and so on) as source data to a data warehouse. For this reason, a sophisticated toolset, such as SSIS is used to facilitate the complex data loads that are often common to BI solutions. As stated earlier, this functionality is often called ETL (Extract, Transform, and Load) in a BI solution.

SQL Server 2005 Reporting Service: This is an optional component for your BI solution.

Excel 2003 and 2007: This is another optional component for your BI solution. Many companies already own Office 2003, so use of Excel as a BI client is often attractive for its low cost and (relatively) low training curve.

Apart from Microsoft BI solution, there are number of other solution provider are there in market.

Following are the list of BI solution & tools provider

Cognos: http://www.cognos.com/products/cognos8businessintelligence/index.html

SAP: http://www.sap.com/solutions/netweaver/components/bi/index.epx

Business Object: http://www.uk.businessobjects.com/products/platform/enterprise.asp

Oracle: http://www.oracle.com/solutions/business_intelligence/index.html


SharePoint Portal Service/Server

Microsoft Windows SharePoint Services 3.0 is a versatile technology that organizations and business units of all sizes can use to increase the efficiency of business processes and improve team productivity. With tools for collaboration that help people stay connected across organizational and geographic boundaries, Windows SharePoint Services gives people access to information they need.

Built on Microsoft Windows Server 2003, Windows SharePoint Services also provides a foundation platform for building Web-based business applications that can flex and scale easily to meet the changing and growing needs of your business. Robust administrative controls for managing storage and Web infrastructure give IT departments a cost-effective way to implement and manage a high-performance collaboration environment. With a familiar, Web-based interface and close integration with everyday tools including the Microsoft Office system, Windows SharePoint Services is easy to use and can be deployed rapidly

Need of SharePoint?

• As companies grow so does the amount of their files. It soon becomes difficult to keep track of the multiplying documents and their locations. SharePoint overcomes this by allowing you to store and share your files in a central site.

• Sharing work files through email is a cumbersome process. SharePoint eliminates this by allowing files to be stored in one location, allowing easy access to all team members.

• Business Intelligence has traditionally remained in the hands of a few key decision makers within organizations. For years, it has been the goal of BI providers to “democratize business intelligence” by making it available to all levels of workers throughout companies. With the addition of PerformancePoint to the SharePoint Enterprise version of SharePoint, this vision is realized, finally taking business intelligence out of the hands of the few and into the hands of many.

• Today’s work occurs over multiple locations, whether it is in different countries, office locations, separate departments or at your home office. SharePoint enables teams and individuals to connect and collaborate together regardless of where they are located.

• Surveys have shown that employees can spend up to 20 – 30 % of their day searching for data and information. SharePoint eliminates this drag on productivity by providing the robust search functionality needed to find the information and expertise buried in the thousands, or hundreds of thousands of files a company generates in the course of business.

• It’s difficult and time consuming to create and maintain sites. SharePoint allows anyone to create sites for use within their company’s Intranet, as they are needed, whether they are departmental sites, document libraries, meetings sites, survey sites, or discussion boards.

Ref: http://office.microsoft.com/en-us/sharepointserver/FX100492001033.aspx


iPhone Application Development

iPhone is Revolutionary device which is designed and marketed by Apple Inc. iPhone provides downgraded version of OS framework to Mac OS X framework. iPhone has Cocoa Touch Framework.

Development tools involved in IPhone application development:

XCode: Complete development environment provides project management, a powerful source editor, and a graphical debugger

iPhone Simulator: Run, test, and debug your application locally on your Mac using a simulated iPhone

Instruments: Collect, display, and compare performance data graphically in real-time to optimize your application.

Interface Builder: Interface Builder makes designing a user interface as easy as drag and drop.

The more detail on the iPhone application development, check out the official “iPhone Developer Program” website.

http://developer.apple.com/iphone/program/

Development Related

ORM

Object-relational mapping is used to map object-oriented programming objects to relational databases managed by Oracle, DB2, Sybase, and other relational database managers (RDBMSs). This site provides facts about object-relational mapping products, architecture problem-solving, and direction in product comparison and selection.

Object-relational mapping products are designed to work well with object programming languages such as C#, C++, and Java. Database objects appear as programming language objects. Often, the interface for object-relational mapping products is the same as the interface for object-oriented databases.

ORM tools for .Net

ADO.NET Entity Framework is an object-relational mapping (ORM) framework for the .NET Framework. This framework is an ORM offering from Microsoft for the .NET Framework

ADO.NET Entity Framework is included with .NET Framework 3.5 Service Pack 1 and Visual Studio 2008 Service Pack 1, released on 11 Aug 2008. It also includes the capability of executing LINQ against ADO.NET Entity Framework entities.

ORM for PHP

There are several tools available right now for implementing ORM technique in PHP.

Following are the list of few ORM tools which can be used with PHP.

Check out following articles which demonstrate you in detail ORM implementation in PHP.

http://www.developertutorials.com/blog/php/getting-started-with-orm-in-php-331/
Microsoft .Net 3.5

There are several .NET language enhancements to be introduced with Visual Studio 2008 including implicitly typed variables, extension methods, anonymous types, object initializers, collection initializers and automatic properties. These language enhancements, along with features like generics, are critical to the use of some of the new features, such as LINQ with the ADO.NET Entity Framework.

These are the such enhancements in .net framework which really can bust development as well as productivity of developers.

Following are the few of articles which demonstrate the practical usage of new .net framework 3.5 enhancement.

http://www.simple-talk.com/dotnet/.net-framework/.net-3.5-language-enhancements/

MVC framework

MVC is a framework methodology that divides an application’s implementation into three component roles: models, views, and controllers.

  • “Models” in a MVC based application are the components of the application that are responsible for maintaining state. Often this state is persisted inside a database (for example: we might have a Product class that is used to represent order data from the Products table inside SQL).
  • “Views” in a MVC based application are the components responsible for displaying the application’s user interface. Typically this UI is created off of the model data (for example: we might create an Product “Edit” view that surfaces textboxes, dropdowns and checkboxes based on the current state of a Product object).
  • “Controllers” in a MVC based application are the components responsible for handling end user interaction, manipulating the model, and ultimately choosing a view to render to display UI. In a MVC application the view is only about displaying information – it is the controller that handles and responds to user input and interaction.

One of the benefits of using a MVC methodology is that it helps enforce a clean separation of concerns between the models, views and controllers within an application. Maintaining a clean separation of concerns makes the testing of applications much easier, since the contract between different application components are more clearly defined and articulated.

The MVC pattern can also help enable red/green test driven development (TDD) – where you implement automated unit tests, which define and verify the requirements of new code, first before you actually write the code itself.

MVC Framework for .NET

The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating MVC-based Web applications

Check out following articles for the overview of ASP.NET MVC framework

http://www.asp.net/learn/mvc/tutorial-01-cs.aspx

MVC Framework for PHP

php.MVC implements the Model-View-Controller (MVC) design pattern, and encourages application design based on the Model 2 paradigm. This design model allows the Web page or other contents (View) to be mostly separated from the internal application code (Controller/Model), making it easier for designers and programmers to focus on their respective areas of expertise.

Reference: http://www.phpmvc.net/
IIS Search Engine Optimization Toolkit

The IIS Search Engine Optimization (SEO) Toolkit helps Web developers, hosting providers, and Web server administrators to improve their Web site’s relevance in search results by recommending how to make the site content more search engine-friendly. The IIS SEO Toolkit includes the Site Analysis module, the Robots Exclusion module, and the Sitemaps and Site Indexes module, which let you perform detailed analysis and offer recommendations and editing tools for managing your Robots and Sitemaps files.

The components of IIS Search Engine Optimization Toolkit include the following features:

  1. Site Analysis:

1.1. Fully featured site crawling engine – in order to perform detailed analysis of site’s structure and content, Site Analysis tool uses a built-in web crawler, called “iisbot”, to download and cache all the publicly available web site content. The web crawler is fully compliant with robots exclusion protocol.

1.2. Report summary dashboard – the results of site analysis are presented in an easy to use dashboard page that serves as a start page for various types of analysis. In addition this page includes a large set of pre-built queries for most common reports.

1.3. Query builder – Site Analysis tool includes a powerful and flexible query builder user interface that lets you create any custom queries that are run against the cached web site content.

1.4. Detailed URL information – you can obtain various detailed information about every URL in your web site, such as response headers and content, the pages that link to that URL as well as all the referenced URLs.

1.5. Detailed Violations descriptions – each content or SEO violation found on a web site has a detailed description as well as a recommended corrective action.

1.6. Word Analysis – any web page can be analyzed with regards to the most commonly used words and phrases within the content of that page. The results of that analysis can be used to select the keywords that most accurately describe the content of the page.

1.7. Route Analysis – unique routes to any page can be displayed in a separate report. This kind of information helps better understand how search engine and site visitors reach a particular page on your web site.

  1. Robots Exclusion

2.1. User interface for editing robots.txt file – the content of the robots exclusion file – robots.txt – can be edited by using IIS Manager GUI

2.2. Selecting URL paths from physical view of web site – the paths that are specified for “Allow” and “Disallow” directives in robots.txt file can be selected from the physical file system layout of your web site.

2.3. Selecting URL paths from virtual view of web site – the paths that are specified for “Allow” and “Disallow” directives in robots.txt file can be selected from the logical view of your web site obtained from the results of site analysis.

  1. Sitemaps and Sitemap Indexes

3.1. User interface for managing sitemap and sitemap indexes files – the content of the sitemap and indexes files can be edited by using IIS Manager GUI

3.2. Selecting URLs from physical view of web site – the URLs that are specified within a sitemap can be selected from the physical file system layout of your web site.

3.3. Selecting URLs from virtual view of web site – the URLs that are specified within a sitemap can be selected from the logical view of your web site obtained from the results of site analysis.

Rich Internet Application Tools

Adobe AIR

The Adobe® AIR™ runtime lets developers use proven web technologies to build rich Internet applications that run outside the browser on multiple operating systems.

Adobe AIR is divided into 3 different categories as per the expertise of particular developer.

AJAX: http://www.adobe.com/products/air/develop/ajax/

AIR with Flex : http://www.adobe.com/products/air/develop/flex/

AIR with flash: http://www.adobe.com/products/air/develop/flash/

Google Web toolkit

Google Web Toolkit 1.6 is a unique and remarkable platform-independent Java to JavaScript cross-compiler. The whole application may be written using most of the Java 1.5 features for which there is much tooling and test support. Not only that, but it is also possible to follow the Model View Controller (MVC) approach separating user interface from business logic, reducing cost of maintenance and increasing development flexibility. DOJO, on the other hand, requires you to develop the client using only the JavaScript language. This can be much more time consuming and more difficult to work with

http://code.google.com/webtoolkit/

jQuery

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

http://jquery.com/

Yahoo User Interface

The YUI Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX

http://developer.yahoo.com/yui/

Apart from these library/toolkits, there are several other toolkits which can also be utilized.

Mootools: http://mootools.net/

Dojo: www.dojotoolkit.org/

List of other toolkits: http://www.javascriptlibraries.com/

Tools for Web Development & Testing

Following are few exiting tools for the web development testing.

  1. XenoCode Browser SandboxBrowser testing is one of the most tedious and frustrating parts of web development. What designer or programmer hasn’t screamed bloody murder at broken alignments in Internet Explorer 6? One of the difficult parts of browser testing is that no developer can have every browser type on a single computer for proper testing.Enter XenoCode Browser Sandbox, a series of virtual applications that can run all popular browsers simultaneously. It does not even require the installation of software. However, XenoCode (Xenocode)’s Browser Sandbox can be heavy in some browsers and is still lacking in a Mac version.Use the following URL for further instruction on how to make use of such toolsRef: http://www.xenocode.com/browsers/
  2. W3C Validation ServicesW3C is THE standard in all of web validation. The W3C Validator looks into the markup of any website and display errors based on industry standards. It comes in over a dozen languages and a dozen varieties. Here are some of the most important validators:Following are the popular validation services provided by W3CW3C Markup Validation
    W3C CSS Validation
    W3C Link Checker
    W3C mobileOK Checker
  3. Javascript & CSS minifyHere is the site which allows you to minify javascript and perhaps the css alsohttp://www.vlead.in/resources/tools/minify-javascript/index.php

Following are the list of few articles which can also be referenced for different area of

Web development tools

There are many other tools available over the internet which can be utilized in daily web development.

Check out following link to improve your productivity

http://mashable.com/2008/11/01/web-development-tools/

Web 2.0 application & tools

http://www.go2web20.net



NOTE :

If you are in need of any Web Development feel free to Inquire us . Dhanashree Inc. Expertise in Asp.net Development, Php Development, Website designing, Open Source customisation. Dhanashree Inc can be our offshore development company / outsourcing web development company, hire dedicated web programmers.

Above information is for knowledge sharing if you have problem / issue / suggestion please intimate us with details for proper and prompt action.

Storing and Retrieving image in SQL server 2005 & asp.net using large value data type & HTTP handler

ASPX page :
<form id=”form1″ runat=”server”>
<div style=”padding: 200px;”>
<asp:Image ID=”imagebox” runat=”server” ImageUrl=”~/sql-image-store/image-handler.ashx” />
</div>
</form>

Handler code: image-handler.ashx

<%@ WebHandler Language=”C#” Class=”image_handler” %>

using System;

using System.Web;

using System.IO;

using System.Data;

using System.Data.Sql;

using System.Data.SqlClient;

using System.Configuration;

public class image_handler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

string xStrCon = System.Configuration.ConfigurationManager.ConnectionStrings["conStrImage"].ConnectionString;

SqlConnection xCon = new SqlConnection(xStrCon);

xCon.Open();

SqlCommand xCom = new SqlCommand(“select * from images where”, xCon);

SqlDataAdapter xAda = new SqlDataAdapter(xCom);

DataSet ds = new DataSet();

xAda.Fill(ds);

// Image processing starts

byte[] bytImage = ReadFile(context.Server.MapPath(“banner.JPG”));

xCom.CommandText = “insert into images values(2,’kensington’,@imagedata)”;

xCom.Parameters.Add(new SqlParameter(“@imagedata”, (object)bytImage));

xCon.Close();

//Display image from SQL server

byte[] imageData = (byte[])ds.Tables[0].Rows[0][2];

context.Response.Clear();

context.Response.ContentType = “image/JPEG”;

context.Response.OutputStream.Write(imageData, 0, imageData.Length);

}

byte[] ReadFile(string sPath)

{

//Initialize byte array with a null value initially.

byte[] data = null;

//Use FileInfo object to get file size.

FileInfo fInfo = new FileInfo(sPath);

long numBytes = fInfo.Length;

//Open FileStream to read file

FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);

//Use BinaryReader to read file stream into byte array.

BinaryReader br = new BinaryReader(fStream);

//When you use BinaryReader, you need to supply number of bytes to read from file.

//In this case we want to read entire file. So supplying total number of bytes.

data = br.ReadBytes((int)numBytes);

return data;

}

public bool IsReusable

{

get

{

return false;

}

}

}



NOTE :

If you are in need of any Web Development feel free to Inquire us . Dhanashree Inc. Expertise in Asp.net Development, Php Development, Website designing, Open Source customisation. Dhanashree Inc can be our offshore development company / outsourcing web development company, hire dedicated web programmers.

Above information is for knowledge sharing if you have problem / issue / suggestion please intimate us with details for proper and prompt action.

Developing custom AD rotator control with multiple Image Mapping using C#.net & XML

We are all familiar with AD rotator control asp.net provides to show rotating/random ads on every page refresh.

But I found a limitation of this control while I needed to develop functionality where AD banners get changed on every page refresh as well as each banners should have multiple links which navigates to diff. URLs ( multiple image mapping in each AD banners )

As this is not possible with AD rotator I have developed a custom asp.net control which provides all this flexibilities with all AD rotator features.

Basic Concept:

To make the control easy to use & understand we will be keeping the concept of defining Ads same like AD rotator control using XML file.

Control will read the Ad banners from the XML file and render all the details with multiple image mappings in the aspx page.

XML file structure:

First and foremost step is to finalize the XML file structure that to be used in custom control to render the ads on random bases.

XML file will look as given in below sample file.

bannes.xml

<?xml version=”1.0″ encoding=”utf-8″ ?>

<banbers>

<banner>

<ImageUrl>http://xyz.com/banner1.jpg</ImageUrl>

<AlternateText>Site1 Main</AlternateText>

<mappings>

<map>

<left>0</left>

<top>0</top>

<right>50</right>

<bottom>50</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

</mappings>

</banner>

<banner>

<ImageUrl>banners/5.jpg</ImageUrl>

<AlternateText>b5</AlternateText>

<mappings>

<map>

<left>10</left>

<top>10</top>

<right>10</right>

<bottom>10</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

<map>

<left>25</left>

<top>25</top>

<right>25</right>

<bottom>25</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

<map>

<left>10</left>

<top>10</top>

<right>10</right>

<bottom>10</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

<map>

<left>25</left>

<top>25</top>

<right>25</right>

<bottom>25</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

<map>

<left>10</left>

<top>10</top>

<right>10</right>

<bottom>10</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

<map>

<left>25</left>

<top>25</top>

<right>25</right>

<bottom>25</bottom>

<navigateUrl>google.com</navigateUrl>

</map>

</mappings>

</banner>

</banbers>

Inside main banners TAG there will be multiple banners TAG to be added for each AD banner,

Each banner TAG will have child nodes(attributes) as listed below:

  1. Image URL – AD image URL to be specified here
  2. Alternate text – alt attribute for image
  3. Mappings – list of all mappings with relative left-right-top-Bottom attributes
    1. Left – left side relative axis
    2. Right – right side relative axis
    3. Top– Top relative axis
    4. Bottom– Bottom relative axis
    5. Navigate URL – URL to navigate

Developing Custom Control:

Now next step is to build a custom asp.net control which will read the above XML structure and renders the data accordingly on ASPX page.

C# code file will be as given below:

ad-banners.cs

this control will have 1 public property where the XML file path will be given called

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Xml;

namespace InfoquestLibrary.Controls

{

[DefaultProperty("Text")]

[ToolboxData("<{0}:banner runat=server />")]

public class banner : System.Web.UI.WebControls.WebControl

{

string _strImageURL, _strXMLpath;

[Bindable(true)]

[Category("Appearance")]

[DefaultValue("")]

[Localizable(true)]

public string ImageURL

{

get { return _strImageURL; }

set { _strImageURL = value; }

}

public string XMLpath

{

get { return _strXMLpath; }

set { _strXMLpath = value; }

}

public override void RenderBeginTag(HtmlTextWriter writer)

{

}

public override void RenderEndTag(HtmlTextWriter writer)

{

}

protected override void RenderContents(HtmlTextWriter output)

{

XmlDocument xDoc = new XmlDocument();

XmlNode xRandomNode;

bool useMapping = true;

int xIntRandomNumber;

Random r = new Random();

xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(this.XMLpath));

xIntRandomNumber = r.Next(xDoc.ChildNodes[1].ChildNodes.Count);

xRandomNode = xDoc.ChildNodes[1].ChildNodes[xIntRandomNumber];

if (xRandomNode.ChildNodes[2].Equals(null))

{

useMapping = false;

}

else

{

if (xRandomNode.ChildNodes[2].ChildNodes.Count == 0)

useMapping = false;

}

if (xRandomNode.HasChildNodes)

{

this.ImageURL = xRandomNode.ChildNodes[0].InnerText;

}

output.AddAttribute(HtmlTextWriterAttribute.Src, this.ImageURL);

if (useMapping)

{

output.AddAttribute(HtmlTextWriterAttribute.Usemap, “#map” + this.ID);

}

output.AddAttribute(HtmlTextWriterAttribute.Border, “none”);

this.AddAttributesToRender(output);

output.RenderBeginTag(HtmlTextWriterTag.Img);

if (useMapping)

{

int xIntMaps, xIntCounter;

xIntMaps = xRandomNode.ChildNodes[2].ChildNodes.Count;

output.AddAttribute(HtmlTextWriterAttribute.Name, “map” + this.ID);

output.AddAttribute(HtmlTextWriterAttribute.Id, “map” + this.ID);

this.AddAttributesToRender(output);

output.RenderBeginTag(HtmlTextWriterTag.Map);

for (xIntCounter = 0; xIntCounter < xIntMaps; xIntCounter++)

{

XmlNode xMap = xRandomNode.ChildNodes[2].ChildNodes[xIntCounter];

if (xMap.HasChildNodes)

{

output.AddAttribute(HtmlTextWriterAttribute.Shape, “rect”);

output.AddAttribute(HtmlTextWriterAttribute.Coords, xMap.ChildNodes[0].InnerText + “,” + xMap.ChildNodes[1].InnerText + “,” + xMap.ChildNodes[2].InnerText + “,” + xMap.ChildNodes[3].InnerText);

output.AddAttribute(HtmlTextWriterAttribute.Href, xMap.ChildNodes[4].InnerText);

output.AddAttribute(HtmlTextWriterAttribute.Title, “”);

output.AddAttribute(HtmlTextWriterAttribute.Alt, “”);

output.RenderBeginTag(HtmlTextWriterTag.Area);

output.RenderEndTag();

}

}

output.RenderEndTag();

}

}

protected override void OnPreRender(EventArgs e)

{

}

}

}

Using customer control in ASPX page:

Now we are done with developing customer control with all the required functionality.

And control now ready for use.

Registering custom control

<%@ Register Assembly=”code_center_library” TagPrefix=”TCC” Namespace=”TCC.Controls” %>

Defining Custom control in ASPX page

<TCC:banner ID=”ads” runat=”server” XMLpath=”~/banner-mapping/bannes.xml” />