Friday, February 26, 2010

Cursors in Sql server-Basics

We'll talk about the basics of cursors. These let you move through rows one at a time and perform processing on each row. (This article has been updated through SQL Server 2005.)

SQL Server is very good at handling sets of data. For example, you can use a single UPDATE statement to update many rows of data. There are times when you want to loop through a series of rows a perform processing for each row. In this case you can use a cursor.

Please note that cursors are the SLOWEST way to access data inside SQL Server. The should only be used when you truly need to access one row at a time. The only reason I can think of for that is to call a stored procedure on each row. In the Cursor Performance article I discovered that cursors are over thirty times slower than set based alternatives.

The basic syntax of a cursor is:

DECLARE @AuthorID char(11)

DECLARE c1 CURSOR READ_ONLY
FOR
SELECT au_id
FROM authors

OPEN c1

FETCH NEXT FROM c1
INTO @AuthorID

WHILE @@FETCH_STATUS = 0
BEGIN

PRINT @AuthorID

FETCH NEXT FROM c1
INTO @AuthorID

END

CLOSE c1
DEALLOCATE c1

The DECLARE CURSOR statement defines the SELECT statement that forms the basis of the cursor. You can do just about anything here that you can do in a SELECT statement. The OPEN statement statement executes the SELECT statement and populates the result set. The FETCH statement returns a row from the result set into the variable. You can select multiple columns and return them into multiple variables. The variable @@FETCH_STATUS is used to determine if there are any more rows. It will contain 0 as long as there are more rows. We use a WHILE loop to move through each row of the result set.

The READ_ONLY clause is important in the code sample above. That dramatically improves the performance of the cursor.

In this example, I just print the contents of the variable. You can execute any type of statement you wish here. In a recent script I wrote I used a cursor to move through the rows in a table and call a stored procedure for each row passing it the primary key. Given that cursors are not very fast and calling a stored procedure for each row in a table is also very slow, my script was a resource hog. However, the stored procedure I was calling was written by the software vendor and was a very easy solution to my problem. In this case, I might have something like this:

EXEC spUpdateAuthor (@AuthorID)

instead of my Print statement. The CLOSE statement releases the row set and the DEALLOCATE statement releases the resources associated with a cursor.

If you are going to update the rows as you go through them, you can use the UPDATE clause when you declare a cursor. You'll also have to remove the READ_ONLY clause from above.

DECLARE c1 CURSOR FOR
SELECT au_id, au_lname
FROM authors
FOR UPDATE OF au_lname

You can code your UPDATE statement to update the current row in the cursor like this

UPDATE authors
SET au_lname = UPPER(Smith)
WHERE CURRENT OF c1

That covers the basics of cursors

Export Gridview data to an Excel sheet

protected void imgExport_Click(object sender, ImageClickEventArgs e)
{
PrepareGridViewForExport(gvAttendance);
string attachment = "attachment; filename=CounsellingDetails.xls ";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
//GridView gv = new GridView();
//gv.DataSource = GetResults();
//gv.DataBind();
gvAttendance.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{

}
private void PrepareGridViewForExport(Control gv)
{

LinkButton lb = new LinkButton();

Literal l = new Literal();

string name = String.Empty;

for (int i = 0; i < gv.Controls.Count; i++)
{

if (gv.Controls[i].GetType() == typeof(LinkButton))
{

l.Text = (gv.Controls[i] as LinkButton).Text;

gv.Controls.Remove(gv.Controls[i]);

gv.Controls.AddAt(i, l);

}

else if (gv.Controls[i].GetType() == typeof(DropDownList))
{

l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;

gv.Controls.Remove(gv.Controls[i]);

gv.Controls.AddAt(i, l);

}

else if (gv.Controls[i].GetType() == typeof(CheckBox))
{

l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";

gv.Controls.Remove(gv.Controls[i]);

gv.Controls.AddAt(i, l);

}

if (gv.Controls[i].HasControls())
{

PrepareGridViewForExport(gv.Controls[i]);

}

}

}

Reading a xml file-Basics

Introduction

The main reason for writing this simple article is so many guys are asking doubts how to read Xml ,how to Write Xml in DotnetSpider Questions section. I Thought this article Will helpful for beginners. You can also find an article about how to write Xml document at
http://www.dotnetspider.com/kb/SubmitSample.aspx?ArticleId=2066

System.Xml namespace contains the XmlReader and XmlTextReader.
The XmlTextReader class is derived from XmlReader class. The XmlTextReader class can be used to read the XML documents. The read function of this document reads the document until end of its nodes.
Using the XmlTextReader class you get a forward only stream of XML data j It is then possible to handle each element as you read it without holding the entire DOM in memory.
XmlTextReader provides direct parsing and tokenizing of XML and implements the XML 1.0 specifications

This article explains how to read an Xml file.

Adding NameSpace as Reference

The first step in the process of reading Xml file is to add System.Xml namespace as reference to our project ,since System.Xml namespace contains the XmlReader and XmlTextReader.




using System.Xml;



let us assume there is an Xml file in c:\Dir\XmlExample.Xml

Open an Xml Document

Create an instance of an XmlTextReader object, and populate it with the XML file. Typically, the XmlTextReader class is used if you need to access the XML as raw data without the overhead of a DOM; thus, the XmlTextReader class provides a faster mechanism for reading XML.




XmlTextReader MyReader = new XmlTextReader("c:\\dir\\XmlExample.Xml");



the above code opens Xml file

Reading Data

The Read method of the XmlTextReader class read the data. See the code



while (MyReader.Read())
{
Response.Write(MyReader.Name);
}



that’s all now we are ready to read our Xml file from the above specified directory


Read the XML File into DataSet


You can use the ReadXml method to read XML schema and data into a DataSet. XML data can be read directly from a file, a Stream object, an XmlWriter object, or a TextWriter object.

The code simply looks like the following



string MyXmlFile = @"c:\\Dir\\XmlExample2.xml";
DataSet ds = new DataSet();

System.IO.FileStream MyReadXml = new System.IO.FileStream(MyXmlFile,System.IO.FileMode.Open);
ds.ReadXml(MyReadXml);

DataGrid1.DataSource = ds;
DataGrid1.DataBind();




Thus we can read Xml Data into Dataset .

Paging in a DataList or Repeater control

Introduction
DataList is a data bound list control that displays items using certain templates defined at the design time. The content of the DataList control is manipulated by using templates sections such as AlternatingItemTemplate, EditItemTemplate, FooterTemplate, HeaderTemplate, ItemTemplate, SelectedItemTemplate and SeparatorTemplate. Each of these sections has its own characteristics to be defined but at a very minimum, the ItemTemplate needs to be defined to display the items in the DataList control. Other sections can be used to provide additional look and feel to the DataList control.

PagedDataSource, is a class that encapsulates the paging related properties for data-bound controls such as DataGrid, GridView, DataList, DetailsView and FormView that allow it to perform paging. And this article is going to combine both DataList control and PagedDataSource class to explain dynamic or custom paging methods for Asp.Net developers.


For demonstration, we are going to list out all the countries in the Country Table. We are going to create a dynamic paging control for this list and define the page size at run-time from a DropDownList control and enrich the navigation with Next and Previous buttons.

Do the Basics Right

Since everything comes with Ajax, create an Ajax Enabled Website, in your Visual Studio 2005. In your Default.aspx page, drag and drop a DataList control from the Toolbox, named it as dlCountry. Our country Table contains two fields such as Country_Code And Country_Name. Right click on the dlCountry datalist, choose Edit Templates > Item Template. Add two Label controls into it; bind its Text property to Country_Code and Country_Name respectively.









Now switch to the Code-behind Default.aspx.cs, write a method to fetch data from the Country’s table.

private void BindGrid()
{
string sql = "Select * from Country Order By Country_Name";
SqlDataAdapter da = new SqlDataAdapter(sql, “Yourconnectionstring”);
DataTable dt = new DataTable();
da.Fill(dt);

dlCountry.DataSource = dt;
dlCountry.DataBind();
}


The above BindGrid method, fetches data from the Country table, bind it with the dlCountry datalist. So the dlCountry datalist is ready to display the records available in the Country table. Call this BindGrid method in the Page load event.

Click Here
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}


Save everything you have done and press F5. You can see the browser opening this page and dispalys all the records in the country table. No paging available at this level.
Let us focus On Paging


To create dynamic paging, we are going to use PagedDataSource Class along with another DataList control. Drag and drop the second DataList control into the page, name it as dlPaging. In its ItemTemplates section, add a LinkButton name it as lnkbtnPaging. Set its CommandName property as lnkbtnPaging. Then choose End Template Editing. Drag and drop a DropdownList Control, name it as ddlPageSize, add values such as 10, 20 and 30 or something as you wish. Then add two more LinkButton controls. Name it as lnkbtnPrevious and lnkbtnNext and change its Text property as Previous and Next respectively. Place both the Previous and Next link buttons on both sides of the dlPaging datalist. Better I suggest you to put an Html Table control and place these controls in it properly so that it will look nicely aligned.


Now we will work little bit on the code-behind of the Default.aspx. Declare a PagedDataSource object at page scope.


PagedDataSource pds = new PagedDataSource();


Then declare a public property called CurrentPage to maintain the latest selected page index. Selected page index is stored in a ViewState variable. The default value of the ViewState is 0.


public int CurrentPage
{

get
{
if (this.ViewState["CurrentPage"] == null)
return 0;
else
return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
}

set
{
this.ViewState["CurrentPage"] = value;
}

}


Next write a method ‘doPaging’ to create a list of page numbers. The total number of pages can be taken from the PagedDataSource object’s PageCount property. We create a DataTable from the information obtained from the PagedDataSource object and assign the DataTable to the dlPaging datalist.
private void doPaging()
{
DataTable dt = new DataTable();
dt.Columns.Add("PageIndex");
dt.Columns.Add("PageText");
for (int i = 0; i < pds.PageCount; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr);
}

dlPaging.DataSource = dt;
dlPaging.DataBind();
}

Look closely, at the doPaging method. Notice the two columns such as PageIndex and PageText. Even though it is understandable, PageIndex is the selected index value of the pages while PageText is the display value in the dlPaging Now we have to bind PageIndex and PageText into the dlPaging’s lnkbtnPaging link button. So set the CommandArgument and Text property of the lnkbtnPaging to PageIndex and PageText respectively. So the entire dlPaging datalist control’s Html source code will look like follows.







Modify BindGrid Method

The next step is to combine both the Country listing datalist and paging number datalist controls. To start this, we are going to modify the BindGrid() method slightly.


private void BindGrid()
{
string sql = "Select * from Country Order By Country_Name";
SqlDataAdapter da = new SqlDataAdapter(sql, “Yourconnectionstring”);
DataTable dt = new DataTable();
da.Fill(dt);

pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
pds.CurrentPageIndex = CurrentPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;

dlCountry.DataSource = pds;
dlCountry.DataBind();

doPaging();
}


In the above method, as usual we fetch data from the Country table and filled it in a DataTable. Then we assign it to the DataSource of the PagedDataSource object pds. Set its AllowPaging property to true and its PageSize with the value from the ddlPageSize DropDownList control. CurrentPageIndex is assigned with our pre-defined property CurrentPage. When the page index reaches first and last page, our Previous and Next button should be disabled. So in the next two lines we check the pds whether it reaches Last or First page, accordingly we set their Enabled property. Now everything is ready to assign the pds to our Country Listing DataList. Last but not least, we are calling the doPaging method to create page numbers.




Paging Events

In the ItemCommand event of the dlPaging control, write code for the paging to take place. Here we take the PageIndex value from the CommandArgument of the lnkbtnPaging and assign it to the CurrentPage property. On every event, we call the BindGrid method.


protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("lnkbtnPaging"))
{
CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
BindGrid();
}
}

Previous And Next Button Events


In the Click events of the lnkbtnPrevious and lnkbtnNext, write a line of code that decrease and increase the value of CurrentPage property.


protected void lnkbtnPrevious_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
BindGrid();
}

protected void lnkbtnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindGrid();
}


Change PageSize Dynamically


To change the PageSize of the PagedDataSource dynamically, we have to call the BindGrid method again because we have already assign the value of the ddlPageSize to the PageSize property of the PagedDataSource.
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
CurrentPage = 0;
BindGrid();
}

HighLight Selected Page Numbers

To inform the user about the selected page, we have to highlight the Page Number in different style. This can be achived by using the following code in ItemDataBound event of the dlPaging datalist.


protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
{
lnkbtnPage.Enabled = false;
lnkbtnPage.Font.Bold = true;
}
}


That’s it. Save everything and hit F5. You can see first DataList will display first 10 Records from the Country Table. The dlPaging control will populate the list of page numbers. Previous button will be in disabled state while Next button is active. Click on any page number, Page will navigate for the Page you choosed. Try by clicking Next and Previous buttons, then Change the ddlPageSize value.

To enable Ajax to this page, add the ScriptManager and include all the control inside an UpdatePanel. Its done.

Binding Data With ‘TreeView’ Control

Binding Data With �TreeView� Control Asp.net 2.0

Over the period of few weeks I have been trying to play with asp.net 2.0 controls. As most of asp.net 2.0 beginners know there are almost no working examples and tutorials available for beta release and honestly I haven�t found people working on asp.net 2.0 so far as much as I expected.

Now the real thing started when I decided to pick up some pace and started using Microsoft visual studio 2005 asp.net 2.0 instead of VS�s prior version.Among so many new tools the one which I found really fascinating in asp.net 2.0 is TreeView control, the reason is; I have been creating TreeViews on JavaScript and had really tough time integrating them with server requests/responses.

Introduction of TreeView Control

A tree view control displays a hierarchical list of items using lines to connect related items in a hierarchy. Each item consists of a label and an optional bitmap. Windows Explorer uses a tree view control to display directories. It displays a tree structure, or menu, that users can traverse to get to different pages in your site. A node that contains child nodes can be expanded or collapsed by clicking on it.

You can use ASP.NET site Navigation features to provide a consistent way for users to navigate your site. A simple solution is to include hyperlinks that allow users to jump to other pages, presenting the hyperlinks in a list or a navigation menu. However, as your site grows, and as you move pages around in the site, it quickly becomes difficult to manage all of the links.

To create a consistent, easily managed navigation solution for your site, you can use ASP.NET site navigation TreeView control.

Fig: 1.0

Note: you can manually populate this control by,
1) Clicking on TreeView control.
2) Right click � Edit Nodes
3) Under �Nodes� heading there are two buttons, to add Parent and child nodes respectively.

Lets do some work now!

Now that we have pretty clear understanding of TreeView control, we will quickly move on and integrate this control with our site.

Step 1

Create two database tables ParentTable and ChildTable, having 2 columns each.

ParentTable � [ParentName , ParentId (as PK)]
ChildTable � [ChildName , ParentId (as FK)]

Note: you can use any database, in our example we will use Microsoft SQL server.

Fig. 2.0

Step 2

Now that we have created our tables, open Microsoft Visual Studio 2005 and create and Asp.net 2.0 WebForm.

Note: You can do this by clicking File menu and then New web site.
While creating the new page do not uncheck Place code in separate file checkbox.

Step 3

Add the following LOC (Line of code) at the start of your programs along with other using keywords.

using System.Data.SqlClient;

Step 4

Place a TreeView control on your WebForm.

Note: Do not change its name, for simplicity we will use the default name TreeView1.

Now double click your page, point to Page_Load event and write fill_Tree();

protected void Page_Load(object sender, EventArgs e)
{
fill_Tree();
}

Do not worry, we will use this function in next step.

Step 5

Now the real thing starts. In this step we will populate our TreeView1 control using our two tables ParentTable and ChildTable.

Create a function fill_Tree()

void fill_Tree()

{
/*
* Fill the treeview control Root Nodes From Parent Table
* and child nodes from ChildTables
*/

/*
* Create an SQL Connection to connect to you our database
*/

SqlConnection SqlCon = new SqlConnection("server=D_hameed;uid=sa;pwd=airforce;database=test");

SqlCon.Open();

/*
* Query the database
*/

SqlCommand SqlCmd = new SqlCommand("Select * from ParentTable",SqlCon);

/*
*Define and Populate the SQL DataReader
*/

SqlDataReader Sdr = SqlCmd.ExecuteReader();

/*
* Dispose the SQL Command to release resources
*/

SqlCmd.Dispose ();

/*
* Initialize the string ParentNode.
* We are going to populate this string array with our ParentTable Records
* and then we will use this string array to populate our TreeView1 Control with parent records
*/

string[,] ParentNode = new string[100, 2];

/*
* Initialize an int variable from string array index
*/

int count = 0;

/*
* Now populate the string array using our SQL Datareader Sdr.

* Please Correct Code Formatting if you are pasting this code in your application.
*/

while (Sdr.Read())
{

ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("ParentID")).ToString();
ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("ParentName")).ToString();

}

/*
* Close the SQL datareader to release resources
*/

Sdr.Close();

/*
* Now once the array is filled with [Parentid,ParentName]
* start a loop to find its child module.
* We will use the same [count] variable to loop through ChildTable
* to find out the number of child associated with ParentTable.
*/

for (int loop = 0; loop < count; loop++)

{

/*
* First create a TreeView1 node with ParentName and than
* add ChildName to that node
*/

TreeNode root = new TreeNode();
root.Text = ParentNode[loop, 1];
root.Target = "_blank";

/*
* Give the url of your page
*/

root.NavigateUrl = "mypage.aspx";

/*
* Now that we have [ParentId] in our array we can find out child modules

* Please Correct Code Formatting if you are pasting this code in your application.

*/

SqlCommand Module_SqlCmd = new SqlCommand("Select * from ChildTable where ParentId =" + ParentNode[loop, 0], SqlCon);

SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();

while (Module_Sdr.Read())
{

// Add children module to the root node

TreeNode child = new TreeNode();

child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("ChildName")).ToString();

child.Target = "_blank";

child.NavigateUrl = "your_page_Url.aspx";

root.ChildNodes.Add(child);

}

Module_Sdr.Close();

// Add root node to TreeView
TreeView1.Nodes.Add(root);

}

/*
* By Default, when you populate TreeView Control programmatically, it expends all nodes.
*/
TreeView1.CollapseAll();
SqlCon.Close();

}

Lets see how it looks like!

Fig. 3.0

Wednesday, February 10, 2010

displaying xml with xslt

Displaying XML with XSLT

XSLT is the recommended style sheet language of XML.

XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS.

XSLT can be used to transform XML into HTML, before it is displayed by a browser:

Display XML with XSLT

If you want to learn more about XSLT, find our XSLT tutorial on our homepage.
Transforming XML with XSLT on the Server

In the example above, the XSLT transformation is done by the browser, when the browser reads the XML file.

Different browsers may produce different result when transforming XML with XSLT. To reduce this problem the XSLT transformation can be done on the server.

View the result.

Note that the result of the output is exactly the same, either the transformation is done by the web server or by the web browser.

xml tree example

XML Tree
« Previous Next Chapter »

XML documents form a tree structure that starts at "the root" and branches to "the leaves".
An Example XML Document

XML documents use a self-describing and simple syntax:


Tove
Jani
Reminder
Don't forget me this weekend!


The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1 = Latin-1/West European character set).

The next line describes the root element of the document (like saying: "this document is a note"):


The next 4 lines describe 4 child elements of the root (to, from, heading, and body):
Tove
Jani
Reminder
Don't forget me this weekend!

And finally the last line defines the end of the root element:


You can assume, from this example, that the XML document contains a note to Tove from Jani.

Don't you agree that XML is pretty self-descriptive?
XML Documents Form a Tree Structure

XML documents must contain a root element. This element is "the parent" of all other elements.

The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree.

All elements can have sub elements (child elements):


.....



The terms parent, child, and sibling are used to describe the relationships between elements. Parent elements have children. Children on the same level are called siblings (brothers or sisters).

All elements can have text content and attributes (just like in HTML).
Example:
DOM node tree

The image above represents one book in the XML below:


Everyday Italian
Giada De Laurentiis
2005
30.00


Harry Potter
J K. Rowling
2005
29.99


Learning XML
Erik T. Ray
2003
39.95



The root element in the example is . All elements in the document are contained within .

The element has 4 children: ,< author>, <year>, <price>. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/xml-tree-example.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/xml-tree-example.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:57:00-08:00'>7:57 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/xml-tree-example.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=1531453331309753968' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=1531453331309753968&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='3606349332059425106' itemprop='postId'/> <a name='3606349332059425106'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/javascript-regular-expression-object.html'>Javascript Regular Expression object</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-3606349332059425106' itemprop='description articleBody'> RegExp, is short for regular expression.<br />Complete RegExp Object Reference<br /><br />For a complete reference of all the properties and methods that can be used with the RegExp object, go to our complete RegExp object reference.<br /><br />The reference contains a brief description and examples of use for each property and method!<br />What is RegExp?<br /><br />A regular expression is an object that describes a pattern of characters.<br /><br />When you search in a text, you can use a pattern to describe what you are searching for.<br /><br />A simple pattern can be one single character.<br /><br />A more complicated pattern can consist of more characters, and can be used for parsing, format checking, substitution and more.<br /><br />Regular expressions are used to perform powerful pattern-matching and "search-and-replace" functions on text.<br />Syntax<br />var txt=new RegExp(pattern,modifiers);<br /><br />or more simply:<br /><br />var txt=/pattern/modifiers;<br /><br /> * pattern specifies the pattern of an expression<br /> * modifiers specify if a search should be global, case-sensitive, etc.<br /><br />RegExp Modifiers<br /><br />Modifiers are used to perform case-insensitive and global searches.<br /><br />The i modifier is used to perform case-insensitive matching.<br /><br />The g modifier is used to perform a global match (find all matches rather than stopping after the first match).<br />Example 1<br /><br />Do a case-insensitive search for "w3schools" in a string:<br />var str="Visit W3Schools";<br />var patt1=/w3schools/i;<br /><br />The marked text below shows where the expression gets a match:<br />Visit W3Schools<br /><br />Try it yourself »<br /><br />Example 2<br /><br />Do a global search for "is":<br />var str="Is this all there is?";<br />var patt1=/is/g;<br /><br />The marked text below shows where the expression gets a match:<br />Is this all there is?<br /><br />Try it yourself »<br /><br />Example 3<br /><br />Do a global, case-insensitive search for "is":<br />var str="Is this all there is?";<br />var patt1=/is/gi;<br /><br />The marked text below shows where the expression gets a match:<br />Is this all there is?<br /><br />Try it yourself »<br /><br />test()<br /><br />The test() method searches a string for a specified value, and returns true or false, depending on the result.<br /><br />The following example searches a string for the character "e":<br />Example<br />var patt1=new RegExp("e");<br />document.write(patt1.test("The best things in life are free"));<br /><br />Since there is an "e" in the string, the output of the code above will be:<br />true<br /><br />Try it yourself »<br /><br />exec()<br /><br />The exec() method searches a string for a specified value, and returns the text of the found value. If no match is found, it returns null.<br /><br />The following example searches a string for the character "e":<br />Example 1<br />var patt1=new RegExp("e");<br />document.write(patt1.exec("The best things in life are free"));<br /><br />Since there is an "e" in the string, the output of the code above will be:<br />e<br /><br />Try it yourself » <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/javascript-regular-expression-object.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/javascript-regular-expression-object.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:53:00-08:00'>7:53 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/javascript-regular-expression-object.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=3606349332059425106' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=3606349332059425106&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='4574219839971931647' itemprop='postId'/> <a name='4574219839971931647'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/javascript-to-create-clock.html'>javascript to create clock.</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-4574219839971931647' itemprop='description articleBody'> function startTime()<br />{<br />var today=new Date();<br />var h=today.getHours();<br />var m=today.getMinutes();<br />var s=today.getSeconds();<br />// add a zero in front of numbers<10<br />m=checkTime(m);<br />s=checkTime(s);<br />document.getElementById('txt').innerHTML=h+":"+m+":"+s;<br />t=setTimeout('startTime()',500);<br />}<br /><br />function checkTime(i)<br />{<br />if (i<10)<br /> {<br /> i="0" + i;<br /> }<br />return i;<br />} <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/javascript-to-create-clock.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/javascript-to-create-clock.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:50:00-08:00'>7:50 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/javascript-to-create-clock.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=4574219839971931647' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=4574219839971931647&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='5345048256291738178' itemprop='postId'/> <a name='5345048256291738178'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/sql-table-relations-primary-and-foreign.html'>SQL Table Relations, Primary and Foreign Keys, and Normalization</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-5345048256291738178' itemprop='description articleBody'> So far in all SQL examples we had we were dealing with a single table. The truth is that in real life when dealing with databases you’ll have to work with many tables, which are interrelated. The true power of the Relational Database Management Systems is the fact that they are Relational.<br /><br />The relationships in a RDBMS ensure that there is no redundant data. What is redundant data, you might ask? I’ll answer you with example. An online store, offers computers for sale and the easiest way to track the sales will be to keep them in a database. You can have a table called Product, which will hold information about each computer - model name, price and the manufacturer. You also need to keep some details about the manufacturer like their website and their support email. If you store the manufacturer details in the Product table, you will have the manufacturer contact info repeated for each computer model the manufacturer produces:<br /><br />model Price Manufacturer ManufacturerWebsite ManufacturerEmail<br />Inspiron B120 $499 Dell http://www.dell.com support@dell.com<br />Inspiron B130 $599 Dell http://www.dell.com support@dell.com<br />Inspiron E1705 $949 Dell http://www.dell.com support@dell.com<br />Satellite A100 $549 Toshiba http://www.toshiba.com support@toshiba.com<br />Satellite P100 $934 Toshiba http://www.toshiba.com support@toshiba.com<br /><br />To get rid of the redundant manufacturer data in the Product table, we can create a new table called Manufacturer, which will have only one entry (row) for each manufacturer and we can link (relate) this table to the Product table. To create this relation we need to add additional column in the Product table that references the entries in the Manufacturer table.<br /><br />A relationship between 2 tables is established when the data in one of the columns in the first table matches the data in a column in the second table. To explain this further we have to understand SQL relational concepts – Primary Key and Foreign Key. Primary Key is a column or a combination of columns that uniquely identifies each row in a table.<br />Foreign Key is a column or a combination of columns whose values match a Primary Key in a different table. In the most common scenario the relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table. Consider the new Product and Manufacturer tables below:<br /><br />Manufacturer<br />ManufacturerID Manufacturer ManufacturerWebsite ManufacturerEmail<br />1 Dell http://www.dell.com support@dell.com<br />2 Toshiba http://www.toshiba.com support@toshiba.com<br /><br />Product<br />model Price ManufacturerID<br />Inspiron B120 $499 1<br />Inspiron B130 $599 1<br />Inspiron E1705 $949 1<br />Satellite A100 $549 2<br />Satellite P100 $934 2<br /><br />The first table is Manufacturer which has 2 entries for Dell and Toshiba respectively. Each of these entries has a ManufacturerID value, which is unique integer number. Because the ManufacturerID column is unique for the Manufacturer table we can use it as a Primary Key in this table. The Product table retains the Model and the Price columns, but has a new column called ManufacturerID, which matches the values of the ManufacturerID column in the Manufacturer table. All values in the ManufacturerID column in the Product table have to match one of the values in the Manufacturer table Primary Key (for example you can’t have ManufacturerID with value of 3 in the Product table, simply because there is no manufacturer with this ManufacturerID defined in the Manufacturer table).<br /><br />I’m sure you’ve noticed that we used the same name for the Primary Key in the first table as for the Foreign Key in the second. This was done on purpose to show the relationship between the 2 tables based on these columns. Of course you can call the 2 columns with different names, but if somebody sees your database for a first time it won’t be immediately clear that these 2 tables are related.<br /><br />But how do we ensure that the Product table doesn’t have invalid entries like the last entry below:<br /><br />model Price ManufacturerID<br />Inspiron B120 $499 1<br />Inspiron B130 $599 1<br />Inspiron E1705 $949 1<br />Satellite A100 $549 2<br />Satellite P100 $934 2<br />ThinkPad Z60t $849 3<br /><br />We do not have a manufacturer with ManufacturerID of 3 in our Manufacturer table, hence this entry in the Product table is invalid. The answer is that you have to enforce referential integrity between the 2 tables. Different RDBMS have different ways to enforce referential integrity, and I will not go into more details as this is not important to understand the concept of relationship between tables.<br /><br />There are 3 types of relations between tables – One-To-Many, Many-To-Many and One-To-One. The relation we created above is One-To-Many and is the most common of the 3 types. In One-To-Many relation a row in one of the tables can have many matching rows in the second table, but a row the second table can match only one row in the first table.<br /><br />In our example, each manufacturer (a row in the Manufacturer table) produces several different computer models (several rows in the Product table), but each particular product (a row in the Product table) has only one manufacturer (a row in the Manufacturer table).<br /><br />The second type is the Many-To-Many relation. In this relation many rows from the first table can match many rows in the second and the other way around. To define this type of relation you need a third table whose primary key is composed of the 2 foreign keys from the other 2 table. To clarify this relation lets review the following example. We have a Article table (ArticleID is primary key) and Category (CategoryID is primary key) table.<br />Every article published in the Article table can belong to multiple categories. To accommodate that, we create a new table called ArticleCategory, which has only 2 columns – ArticleID and CategoryID (these 2 columns form the primary key for this table). This new table called sometimes junction table defines the Many-To-Many relationship between the 2 main tables. One article can belong to multiple categories, and every category may contain more than one article.<br /><br />In the One-To-One relation each row in the first table may match only one row in the second and the other way around. This relationship is very uncommon simply because if you have this type of relation you may as well keep all the info in one single table.<br /><br />By dividing the data into 2 tables we successfully removed the redundant manufacturer details from the initial Product table adding an integer column referencing the new Manufacturer table instead.<br /><br />The process of removing redundant data by creating relations between tables is known as Normalization. Normalization process uses formal methods to design the database in interrelated tables. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/sql-table-relations-primary-and-foreign.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/sql-table-relations-primary-and-foreign.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:45:00-08:00'>7:45 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/sql-table-relations-primary-and-foreign.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=5345048256291738178' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=5345048256291738178&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='1900544406093608094' itemprop='postId'/> <a name='1900544406093608094'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/using-stringbuilder-in-net.html'>Using StringBuilder in .NET</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-1900544406093608094' itemprop='description articleBody'> StringBuilder has an Append method that returns a reference to itself. This is useful for when you want to append several items in one go. The following code is an example. Obviously, you'll get more benefit the more items you add:<br /><br /><br /> StringBuilder sb = new StringBuilder( ) ;<br /> string s = sb.Append( @"Hello " )<br /> .Append( @"World" )<br /> .ToString( ) ;<br /><br />Editors Note: Here's the equivalent in VB.NET, which isn't quite as useful because you have to append the line breaks and, interestingly, the "dot" (.) has to go at the ends of the lines or you have to put the .Append at the end of the lines as shown. In other words, this works:<br /><br /><br /> Dim sb As StringBuilder = New StringBuilder<br /> Dim s As String = sb.Append("Hello "). _<br /> Append("World"). _<br /> Append("Junk"). _<br /> ToString()<br /><br />...and this works too:<br /><br /><br /> Dim sb As StringBuilder = New StringBuilder<br /> Dim s As String = sb.Append("Hello ").Append _<br /> ("World").Append _<br /> ("Junk").ToString<br /><br />...but this doesn't:<br /><br /> <br /> Dim sb As StringBuilder = New StringBuilder<br /> Dim s As String = sb.Append("Hello ") _<br /> .Append("World") _<br /> .Append("Junk") _<br /> .ToString() <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/using-stringbuilder-in-net.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/using-stringbuilder-in-net.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:43:00-08:00'>7:43 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/using-stringbuilder-in-net.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=1900544406093608094' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=1900544406093608094&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='4929904597573511587' itemprop='postId'/> <a name='4929904597573511587'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/introducing-linq-languageintegrated.html'>Introducing LINQ: Language‐Integrated Query</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-4929904597573511587' itemprop='description articleBody'> Problem: Data != Objects<br />Developers live in two worlds: The world of objects and the world of data. One of the things that makes<br />developers’ lives more difficult is the impedance mismatch between these two worlds and the<br />inordinate amount of plumbing code required to bridge the gap between them. For example, we might<br />want to retrieve customer data from a relational database, display it to the user for updating, then save<br />those changes back to the database. The traditional approach is to rely on an API like ADO.NET for the<br />data‐centric operations, potentially sacrificing on type‐safety and compiler syntax checking, and utilize<br />object‐oriented programming techniques for other parts of our application. Where these two worlds<br />intersect in our application, we are forced to deal with differences between the SQL and CLR type<br />systems, how entity relations work, as well as other incompatibilities. Conversely, we may wish to deal<br />with objects in a data‐centric fashion, filtering, sorting and grouping collections of objects, but this<br />means we may end up with code that is difficult to maintain because it obscures what we want to do at<br />a higher level.<br />The Missing LINQ<br />Not wanting us to languish in this no man’s land, the good folks at Microsoft, led by Anders Hejlsberg<br />(chief architect of the C# programming language), have created the LINQ Project. LINQ stands for<br />Language‐Integrated Query and seeks to make query a first‐class citizen of the programming language.<br />Microsoft plans to incorporate LINQ into C# 3.0 and Visual Basic 9.0, both of which will be released with<br />Visual Studio 2008 (code‐named Orcas). By introducing a SQL‐like syntax, LINQ allows you to interrogate<br />an in‐memory collection (anything implementing IEnumerable<T>), filter the results, group, sort,<br />transform and perform a number of other data‐centric operations. Take, for example, the following<br />array of strings:<br />string[] stooges = { "Moe", "Larry", "Curly", "Shemp" };<br />With C# 3.0’s new query syntax, you can extract only strings with a length of 5, sort them alphabetically,<br />and change the results to upper case:<br />IEnumerable<string> query =<br />from s in stooges<br />where s.Length == 5<br />orderby s<br />Page 2 of 6<br />select s.ToUpper();<br />In this snippet, from s in stooges indicates that you want to query the stooges collection and<br />use s to represent each item in the sequence. The select clause determines the data you want<br />returned and what shape it should take. Here we want to return each element converted to upper case.<br />The where and orderby clauses, as you might guess, restrict the results to those with 5 characters<br />and specify an ascending sort. Execution of the query is actually deferred until you iterate the query<br />results, typically with a foreach statement, or by calling extension methods, such as ToArray or ToList,<br />that perform the iteration internally (we’ll talk about extension methods in just a bit). The following<br />statement triggers the query execution:<br />foreach (string s in query) Console.WriteLine(s);<br />This produces the following output:<br />CURLY<br />LARRY<br />SHEMP<br />Behind the Magic: C# Language Enhancements<br />Supporting language‐integrated query is a set of powerful enhancements to the C# programming<br />language, each of which is useful in its own right, but when taken together provide the basis for LINQ.<br />The most significant of these is extension methods, which allow third parties to in essence add methods<br />to a type, thereby augmenting the type’s contract, while still allowing the type’s author to provide his or<br />her own implementations of these methods. Extension methods are nothing more than static methods<br />defined in static classes, and (in C#) have the operator in front of the first method parameter. The<br />System.Linq namespace contains what are called the standard query operators, which are extension<br />methods that provide the basic functionality of LINQ. The C# compiler, in fact, converts query syntax<br />(things like from, in, where, select) to extension method calls. One of these is the simplest query<br />operator, Where:<br />namespace System.Linq<br />{<br />public static class Enumerable<br />{<br />public static IEnumerable<T> Where<T><br />Page 3 of 6<br />(this IEnumerable<T> source, Func<T, bool> predicate)<br />{<br />foreach (T item in source)<br />{<br />if (predicate(item)) yield return item;<br />}<br />}<br />}<br />}<br />As you can see, the method accepts a source of type IEnumerable<T> and a predicate of the Func<br />generic delegate type. We can create an instance of the delegate as an anonymous method:<br />Func<string, bool> predicate = delegate(string s)<br />{ return s.Length == 5; };<br />The Where method simply iterates over the source, returning only items that pass the predicate test.<br />Because it’s defined as a static method, there’s nothing to prevent you from calling it directly, like so:<br />IEnumerable<string> query = Enumerable.Where(stooges, predicate);<br />However, because Where is defined as an extension method, we can invoke it using instance syntax<br />(note, however, that it’s not really an instance method!):<br />IEnumerable<string> query = stooges.Where(predicate);<br />Extension methods are brought into scope when the namespace in which they are contained is imported<br />with a using directive. However, they are only used if no matching methods with the same name and<br />signature exist on the target type or its base classes. This lets you plug in your own query operators<br />which take precedence over those in the System.Linq namespace.<br />Although you can define the predicate as an anonymous method (or a standalone method for that<br />matter), C# provides a much more compact syntax, called a lambda expression. If we were to re‐write<br />our anonymous method as a lambda expression and pass it as an argument, our call to Where would<br />look like this (notice how the type of “s” is inferred and “return” is left out):<br />Page 4 of 6<br />IEnumerable<string> query = stooges.Where(s => s.Length == 5);<br />The power of lambda expressions, however, is not just that they are compact (and hence more readable<br />when passed as method parameters), but they can be compiled as either code or data. When assigned<br />to the generic type Expression<T>, the compiler emits an expression tree representing the code rather<br />than IL that would execute the code. Frameworks like LINQ to SQL can then analyze the expression tree<br />to formulate SQL statements targeting a relational database.<br />Bridging the Gap: LINQ to SQL, Linq to XML<br />Besides enabling you to query in‐memory collections, LINQ is based on an extensible architecture that<br />allows you to plug in a query processing engine to fetch data from any external source. In fact, the first<br />version of LINQ comes with both these capabilities, called LINQ to SQL and LINQ to XML, respectively.<br />Combining these LINQ extensions, you could retrieve a list of products from the Northwind database,<br />place the result in an in‐memory collection, massage the data, then persist the output to an XML file, all<br />without having to translate “foreign” data constructs into CLR objects, while at the same time benefiting<br />from Intellisense and compile‐time syntax checking. Let’s start by querying relational data using LINQ to<br />SQL:<br />NorthwindDataContext db = new NorthwindDataContext();<br />IEnumerable<Product> prodQuery =<br />from p in db.Products<br />where p.Category.CategoryName == "Beverages"<br />select p;<br />The NorthwindDataContext class derives from DataContext, which does the heavy lifting to<br />convert the query expression into SQL, execute it against the database, and return the results as a<br />sequence of Product objects. Where, might you ask, are these classes defined? It just so happens<br />that Visual Studio 2008 comes with special tool support for LINQ to SQL, including a class designer<br />(which you get when adding a “LINQ to SQL Classes” item to a project). The designer generates the<br />NorthwindDataContext and Product classes when you drag the Products table from a data<br />connection in the Server Explorer onto the class designer. If you bring over multiple tables, relations<br />between the tables are reflected in the class diagram and become object properties in the designergenerated<br />code.<br />Page 5 of 6<br />Notice how the where clause in our query references the CategoryName property of the Category class,<br />which is shown to be a property of the Product class. When you execute this query, LINQ to SQL<br />generates a SQL statement that includes a JOIN on the Products and Categories tables. The join is<br />performed by SQL Server, which makes for efficient query execution. You can see this take place by<br />setting the Log property of the data context to dump output to the console window or a text file.<br />SELECT * FROM [dbo].[Products] AS [t0]<br />LEFT OUTER JOIN [dbo].[Categories] AS [t1]<br />ON [t1].[CategoryID] = [t0].[CategoryID]<br />WHERE [t1].[CategoryName] = @p0<br />-- @p0: Input String (Size = 9; Prec = 0; Scale = 0) [Beverages]<br />LINQ to SQL also includes support for tracking changes to in‐memory objects, then posting those<br />changes back to the database, while at the same time maintaining concurrency control. (If you like, you<br />can also specify stored procedures for the updates.) For example, we can store our product list in a local<br />collection, change the unit price of an item, then call SubmitChanges to persist the new data back to<br />SQL Server.<br />List<Product> products = prodQuery.ToList();<br />Product chai = (from p in products<br />where p.ProductName == "Chai"<br />select p).Single();<br />chai.UnitPrice = 20;<br />db.SubmitChanges();<br />Page 6 of 6<br />The ORM functionality of LINQ to SQL is somewhat limited (for example, many‐to‐many relationships<br />aren’t fully supported and it only works with SQL Server). But the power of LINQ really shines when<br />combining LINQ to Objects, LINQ to SQL and LINQ to XML. We can, for instance, take our list of<br />beverages, sort them, and save them as an XML file.<br />IEnumerable<XElement> xmlQuery =<br />from p in products<br />orderby p.ProductName<br />select new XElement("Product",<br />new XAttribute("ProductName", p.ProductName),<br />new XAttribute("UnitPrice", p.UnitPrice));<br />XElement bevXml = new XElement("Beverages", xmlQuery);<br />bevXml.Save("beverages.xml");<br />Notice how this code, unlike the DOM API, is element‐centric, as opposed to document‐centric, and that<br />there’s no need for XPath query strings. Nice. The beverages.xml file looks like this:<br /><!--xml version="1.0" encoding="utf-8"?--><br /><Beverages><br /><Product ProductName="Chai" UnitPrice="20.0000" /><br /><Product ProductName="Chang" UnitPrice="19.0000" /><br /><Product ProductName="Chartreuse verte" UnitPrice="18.0000" /><br /><Product ProductName="Côte de Blaye" UnitPrice="263.5000" /><br />[Remaining items elided for clarity ...]<br /></Beverages><br />Time to LINQ Up!<br />There is much more to LINQ than what I have room to cover here. Other C# features driving LINQ are<br />things like object initializers, anonymous types and implicitly typed local variables. There are standard<br />query operators that perform grouping, joins, partitioning, union, intersection, aggregation and<br />conversion, and other functions as well. And while LINQ does not completely resolve impedance<br />mismatch between objects and data, it is a step in the right direction, resulting in cleaner code that<br />more clearly reflects the developer’s intention. It also makes you more productive by eliminating much<br />of the plumbing code you would otherwise have to write, which, after all, is what frameworks are all<br />about. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/introducing-linq-languageintegrated.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/introducing-linq-languageintegrated.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:41:00-08:00'>7:41 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/introducing-linq-languageintegrated.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=4929904597573511587' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=4929904597573511587&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='1289294142848822540' itemprop='postId'/> <a name='1289294142848822540'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/how-to-bind-gridview-control-to-xml-in.html'>How to Bind a GridView Control to XML in ASP.NET</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-1289294142848822540' itemprop='description articleBody'> In this example, your XML content is assumed to be ready and well formatted. To be compatible with a GridView, the XML document has to have a database-like format (table and records):<br /><br /><br /><countries><br /> <country><br /> <name>ANGOLA</name><code>24</code><size>1345 amp</size><br /> </country><br /> <country><br /> <name>BENIN</name><code>204</code><size>435 amp</size><br /> </country><br /></countries><br /><br /> 1. Drag a GridView component from the Toolbox.<br /> 2. Add to your GridView a PreRender event.<br /> 3. Write your code (see below) to bind a DataSet to the GridView.<br /><br /><br />public partial class _Default : System.Web.UI.Page<br />{<br /> protected void MyGridView_PreRender(object sender, EventArgs e)<br /> {<br /> // Creates a DataSet and loads it with an Xml Content<br /> DataSet aDataSet = new DataSet();<br /> aDataSet.ReadXml(new StringReader(aXmlDoc.OuterXml));<br /><br /> // Bind the DataSet to the grid view<br /> GridView gv = (GridView)sender;<br /> gv.DataSource = aDataSet;<br /> gv.DataBind();<br /> }<br />} <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/how-to-bind-gridview-control-to-xml-in.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/how-to-bind-gridview-control-to-xml-in.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:38:00-08:00'>7:38 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/how-to-bind-gridview-control-to-xml-in.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=1289294142848822540' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=1289294142848822540&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='5316431649206073729' itemprop='postId'/> <a name='5316431649206073729'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/autocomplete-textbox.html'>AutoComplete TextBox</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-5316431649206073729' itemprop='description articleBody'> Introduction<br /><br />I was in need of a simple auto-completing textbox for a project I was working on at work when I realized that there were really not a whole lot of good choices for this. Many of them derive from a combo box which will not work properly for a dropdown list that continues to filter out items as you continue to type. This is my first article, so any feedback is welcome.<br />Using the textbox<br /><br />Using the text box is simple, just add some AutoCompleteEntry items to the textbox:<br /><br />The Items collection holds objects that implement the IAutoCompleteEntry interface. This allows you to use the AutoCompleteTextBox for a wide range of purposes. The IAutoCompleteEntry objects publish a list of string objects that are used to match with the user input. The popup list displays the result of a call to the object's ToString() method.<br />Collapse<br /><br /> // Add some sample auto complete entry items...<br /><br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Phoenix, Az", "Phoenix, Az",<br /> "Az", "PHX"));<br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Tempe, Az", "Tempe, Az","Az",<br /> "TPE"));<br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Chandler, Az", <br /> "Chandler, Az", "Az", "CHA"));<br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Boxford, Ma", "Boxford, Ma",<br /> "Ma", "BXF"));<br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Topsfield, Ma", <br /> "Topsfield, Ma", "Ma", "TPF"));<br /> this.coolTextBox1.Items.Add(new AutoCompleteEntry("Danvers, Ma", "Danvers, Ma", <br /> "Ma", "DNV"));<br /><br /><br />Note: I created a control called CoolTextBox that is a composite control with an AutoCompleteTextBox in it. all it really does is add a cool looking border to the textbox. I am using the CooltextBox in the demo project.<br />Design<br /><br />So I decided to use a simple textbox and handle key press events to show a popup window that has a list in it. The list will be filtered to show only items that match the text in the textbox.<br />Problems<br /><br />The problem with this is that there is no easy way to get the popup window to behave like any normal person would expect it to. It is easy to get the popup to show, but we need to keep the focus on the textbox, update the list on the popup, and even send some keystroke events over to the popup. Also, we need to hide the popup anytime the user clicks the mouse outside of the popup or outside the textbox (I know this sounds like it should be simple).<br />Implementation<br />Controlling the popup<br /><br />I like to make controls as generic and customizable as possible. I like my auto-complete text box to popup after I type a couple characters, or if I press the Control+Space key combination. Someone else may have a completely different set of preferences, so I decided to control the popup events through a customizable set of AutoCompleteTrigger objects. Here is how the default behavior is set up (the ones that say "Consume" prevent further processing of the key press):<br />Collapse<br /><br /> // Add default triggers.<br /><br /> this.triggers.Add(new TextLengthTrigger(2));<br /> this.triggers.Add(new ShortCutTrigger(Keys.Enter, TriggerState.SelectAndConsume));<br /> this.triggers.Add(new ShortCutTrigger(Keys.Tab, TriggerState.Select));<br /> this.triggers.Add(new ShortCutTrigger(Keys.Control | Keys.Space, TriggerState<br /> .ShowAndConsume));<br /> this.triggers.Add(new ShortCutTrigger(Keys.Escape, TriggerState.HideAndConsume));<br /><br />When to close the popup<br /><br />The popup should close under any of the following circumstances:<br /><br /> 1. The user clicks on an item in the list<br /> 2. Any of the triggers evaluate to<br /> 1. TriggerState.Select<br /> 2. TriggerState.SelectAndConsume<br /> 3. TriggerState.Hide<br /> 4. TriggerState.HideAndConsume<br /> 3. The user clicks anywhere other than the popup or the text box.<br /><br />Scenarios 1 and 2 are fairly easy, so I won't delve into that here. You can check out the source code if you are interested. Its the 3rd scenario that really turned out to be a challenge.<br />Handling mouse clicks<br /><br />So there are several places we need to hook in to determine if the mouse was clicked outside of the text box or the popup.<br /><br />We need to catch the OnLostFocus of the text box, as well as the Deactivate event of the popup.<br />Collapse<br /><br /> protected override void OnLostFocus(EventArgs e)<br /> {<br /> base.OnLostFocus (e);<br /> if (!(this.Focused || this.popup.Focused || this.list.Focused))<br /> {<br /> this.HideList();<br /> }<br /> }<br /><br /> private void Popup_Deactivate(object sender, EventArgs e)<br /> {<br /> if (!(this.Focused || this.popup.Focused || this.list.Focused))<br /> {<br /> this.HideList();<br /> }<br /> }<br /><br />Those are the easy ones. Now we need to trap all mouse events that go to the form that the textbox lives on and its child controls. This is a little more difficult. o do this I used a NativeWindow as a base class for my mouse hook. I then listened for any mouse click event. If the mouse click occurred within the bounding box of the text box, then the popup remains visible. Otherwise, we should hide the popup.<br />Collapse<br /><br /> /// <summary><br /><br /> /// This is the class we will use to hook mouse events.<br /><br /> /// </summary><br /><br /><br /> private class WinHook : NativeWindow<br /> {<br /> private AutoCompleteTextBox tb;<br /> /// <summary><br /><br /> /// Initializes a new instance of <see cref="WinHook"/><br /><br /> /// </summary><br /><br /> /// <param name="tbox">The <see cref="AutoCompleteTextBox"/> the hook is running <br /><br /> /// for.</param><br /><br /><br /> public WinHook(AutoCompleteTextBox tbox)<br /> {<br /> this.tb = tbox;<br /> }<br /> /// <summary><br /><br /> /// Look for any kind of mouse activity that is not in the<br /><br /> /// text box itself, and hide the popup if it is visible.<br /><br /> /// </summary><br /><br /> /// <param name="m"></param><br /><br /> protected override void WndProc(ref Message m)<br /> {<br /> switch (m.Msg)<br /> {<br /> case Win32.Messages.WM_LBUTTONDOWN:<br /> case Win32.Messages.WM_LBUTTONDBLCLK:<br /> case Win32.Messages.WM_MBUTTONDOWN:<br /> case Win32.Messages.WM_MBUTTONDBLCLK:<br /> case Win32.Messages.WM_RBUTTONDOWN:<br /> case Win32.Messages.WM_RBUTTONDBLCLK:<br /> case Win32.Messages.WM_NCLBUTTONDOWN:<br /> case Win32.Messages.WM_NCMBUTTONDOWN:<br /> case Win32.Messages.WM_NCRBUTTONDOWN:<br /> {<br /> // Lets check to see where the event took place<br /><br /> Form form = tb.FindForm();<br /> Point p = form.PointToScreen(new Point((int)m.LParam));<br /> Point p2 = tb.PointToScreen(new Point(0, 0));<br /> Rectangle rect = new Rectangle(p2, tb.Size);<br /> // Hide the popup if it is not in the text box<br /><br /> if (!rect.Contains(p))<br /> {<br /> tb.HideList();<br /> }<br /> } break;<br /> case Win32.Messages.WM_SIZE:<br /> case Win32.Messages.WM_MOVE:<br /> {<br /> tb.HideList();<br /> } break;<br /> // This is the message that gets sent when a child control gets activity<br /><br /> case Win32.Messages.WM_PARENTNOTIFY:<br /> {<br /> switch ((int)m.WParam)<br /> {<br /> case Win32.Messages.WM_LBUTTONDOWN:<br /> case Win32.Messages.WM_LBUTTONDBLCLK:<br /> case Win32.Messages.WM_MBUTTONDOWN:<br /> case Win32.Messages.WM_MBUTTONDBLCLK:<br /> case Win32.Messages.WM_RBUTTONDOWN:<br /> case Win32.Messages.WM_RBUTTONDBLCLK:<br /> case Win32.Messages.WM_NCLBUTTONDOWN:<br /> case Win32.Messages.WM_NCMBUTTONDOWN:<br /> case Win32.Messages.WM_NCRBUTTONDOWN:<br /> {<br /> // Same thing as before<br /><br /> Form form = tb.FindForm();<br /> Point p = form.PointToScreen(new Point((int)m.LParam));<br /> Point p2 = tb.PointToScreen(new Point(0, 0));<br /> Rectangle rect = new Rectangle(p2, tb.Size);<br /> if (!rect.Contains(p))<br /> {<br /> tb.HideList();<br /> }<br /> } break;<br /> }<br /> } break;<br /> }<br /> <br /> base.WndProc (ref m);<br /> }<br /> }<br /><br />Conclusion<br /><br />While there are more details as to how the whole thing goes together, they are alot more straight forward. I feel this is a viable solution for an Auto-Complete TextBox and I hope you find it interesting. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/autocomplete-textbox.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/autocomplete-textbox.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:35:00-08:00'>7:35 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/autocomplete-textbox.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=5316431649206073729' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=5316431649206073729&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='5582389513529370492' itemprop='postId'/> <a name='5582389513529370492'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/sending-and-playing-microphone-audio.html'>Sending and playing microphone audio over network</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-5582389513529370492' itemprop='description articleBody'> Introduction<br /><br />This example shows you how to receive data from a microphone and stream it over UDP to another computer. The example application can act like a direct phone, if both endpoints listen for data and send microphone data to each other. One would probably suspect that no source code exists for that, but of course it does. I hate those who will do commercial advertising. There is also a second related project what will contain a UDP server that we need to send/receive audio and compress it with g711 codec.Though only UDP is not the best way to transport audio data, RTP is the right way to go. RTP adds quality of service to transported audio, you can see how many packets are lost and can even arrange disordered packets. I will try to add an RTP example soon, so be calm, it's under way. There are some similar example applications, but most of them aren't well commented and missing some parts, so I will try to fill this part.<br /><br />The package contains:<br /><br /> * LumiSoft.Media - Audio related API (Included in example app)<br /> * LumiSoft.Net - UDP server, G711 codec<br /> * Example Application<br /><br />Using the code<br /><br /> * WaveIn - class provides a simple way to receive audio from a microphone.<br /> Actually all what you need to do is:<br /> WavIn.Devices - returns all available input devices from where we can get data.<br /> Collapse<br /><br /> /// <summary><br /><br /> /// Application main class.<br /><br /> /// </summary><br /><br /> public class Test<br /> {<br /> private WavIn m_pSoundReceiver = null;<br /><br /> /// <summary><br /><br /> /// Default constructor.<br /><br /> /// </summary><br /><br /> public Test()<br /> {<br /> // G711 needs 8KHZ 16 bit 1 channel audio, <br /><br /> // 400kb buffer gives us 25ms audio frame.<br /><br /> m_pSoundReceiver = new WavIn(WavIn.Devices[0],8000,16,1,400);<br /> m_pSoundReceiver.BufferFull += new BufferFullHandler <br /> (m_pSoundReceiver_BufferFull);<br /> m_pSoundReceiver.Start();<br /> }<br /><br /> /// <summary><br /><br /> /// This method is called when recording buffer is full <br /><br /> /// and we need to process it.<br /><br /> /// </summary><br /><br /> /// <param name="buffer">Recorded data.</param><br /><br /> private void m_pSoundReceiver_BufferFull(byte[] buffer)<br /> {<br /> // Just store audio data or stream it over the network ... <br /><br /> }<br /> }<br /><br /> * WaveOut - class provides methods for playing out streaming data.<br /> The only thing you need to do is just call waveoutInstance.Play method.<br /> In my opinion, the whole example application has been coded well enough, so dig into the code.<br /><br /> Note: Sound quality depends on network delay jittering, if there will be too big a variance in delays, voice will have holes in it. In addition, UDP packet loss and disordered packets will affect it too. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/sending-and-playing-microphone-audio.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/sending-and-playing-microphone-audio.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-10T19:33:00-08:00'>7:33 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/sending-and-playing-microphone-audio.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=5582389513529370492' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=5582389513529370492&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> </div></div> <div class="date-outer"> <h2 class='date-header'><span>Friday, February 5, 2010</span></h2> <div class="date-posts"> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='1766315865176933955' itemprop='postId'/> <a name='1766315865176933955'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/loading-image-files-from-database-using.html'>Loading image files from a database, using ADO</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-1766315865176933955' itemprop='description articleBody'> Introduction<br />Putting and retrieving image files in to a database, is not a simple task. I you want to look on the Internet for such a sample, you will be surprised that there is no C++ sample for that. There is only information, that you have to use the Safearray, SetChunk, and GetChunk methods.<br /><br />This article will show how you can put image files in to a database via ADO, as well as how you can retrieve them. With this example, you can use any file format such as Word, Excel etc., not just image file formats.<br /><br />Implementation<br />The example contains two methods for putting and retrieving image files to and from a database. The first method retrieves data from the database, create a file in a temporary directory, and puts the data into a file created. The parameter strImageName is the name of the file that will be created. The second parameter indicates the ADO field object containing the image data.<br /><br />The following code sample shows the implementation:<br /><br /> Collapse Copy Code<br />CString CADOImageDBDlg::GetImageFromADO(CString <br /> strImageName, FieldPtr pField)<br />{<br /> //Creating temp file<br /> char tmpPath[_MAX_PATH+1];<br /> GetTempPath(_MAX_PATH,tmpPath);<br /> strImageName.Insert(0,tmpPath);<br /> CFile outFile(strImageName, <br /> CFile::modeCreate|CFile::modeWrite);<br /> <br /> //Helper variable for retrieving image data<br /> unsigned char* lpData = NULL;<br /> long lngOffSet = 0;<br /> long lngSize=pField->ActualSize;<br /> const long ChunkSize=50; <br /> _variant_t varChunk; <br /> UCHAR chData;<br /> HRESULT hr;<br /> long lBytesCopied = 0;<br /> lpData=new unsigned char [lngSize];<br /> <br /> //Retrieveing data from vararray<br /> while(lngOffSet < lngSize)<br /> { <br /> try<br /> {<br /> //Get 50 size long chunk from database<br /> varChunk = pField->GetChunk(ChunkSize);<br /> <br /> //putting chunk in to safe array<br /> for(long lIndex = 0; lIndex <= <br /> (ChunkSize - 1); lIndex++)<br /> {<br /> hr= <br /> SafeArrayGetElement(varChunk.parray, <br /> &lIndex, &chData);<br /> if(SUCCEEDED(hr))<br /> {<br /> ((UCHAR*)lpData)[lBytesCopied] = chData;<br /> lBytesCopied++;<br /> }<br /> else<br /> break;<br /> }<br /> lngOffSet += ChunkSize;<br /> }<br /> catch(_com_error &e)<br /> {<br /> dump_com_error(e);<br /> return FALSE;<br /> }<br /> }<br /> <br /> //<br /> LPSTR buffer = (LPSTR)GlobalLock(lpData);<br /> // write data in to file<br /> outFile.Write(lpData,lngSize);<br /> <br /> // free reserved data<br /> GlobalUnlock(lpData);<br /> delete lpData;<br /> <br /> //Return full path file<br /> return strImageName;<br />}<br /> <br />bool CADOImageDBDlg::PutImageInADO(CString <br /> strFilePath,FieldPtr pFileData)<br />{<br /> //Opent File<br /> CFile fileImage;<br /> CFileStatus fileStatus;<br /> fileImage.Open(strFilePath, CFile::modeRead);<br /> fileImage.GetStatus(fileStatus);<br /><br /> //Alocating memory for data <br /> ULONG nBytes = (ULONG)fileStatus.m_size;<br /> HGLOBAL hGlobal = GlobalAlloc(GPTR,nBytes);<br /> LPVOID lpData = GlobalLock(hGlobal);<br /><br /> //Putting data in to file<br /> fileImage.Read(lpData,nBytes);<br /> <br /> <br /> HRESULT hr;<br /> _variant_t varChunk;<br /> long lngOffset = 0;<br /> UCHAR chData;<br /> SAFEARRAY FAR *psa = NULL;<br /> SAFEARRAYBOUND rgsabound[1];<br /> <br /> try<br /> {<br /> //Create a safe array to <br /> //store the array of BYTES <br /> rgsabound[0].lLbound = 0;<br /> rgsabound[0].cElements = nBytes;<br /> psa = SafeArrayCreate(VT_UI1,1,rgsabound);<br /> <br /> while(lngOffset < (long)nBytes)<br /> {<br /> chData = ((UCHAR*)lpData)[lngOffset];<br /> hr = SafeArrayPutElement(psa, <br /> &lngOffset, &chData);<br /> <br /> if(hr!=S_OK) <br /> return false;<br /> <br /> lngOffset++;<br /> }<br /> lngOffset = 0;<br /> <br /> //Assign the Safe array to a variant. <br /> varChunk.vt = VT_ARRAY|VT_UI1;<br /> varChunk.parray = psa;<br /> <br /> hr = pFileData->AppendChunk(varChunk);<br /> <br /> if(hr!=S_OK) <br /> return false;<br /> }<br /> catch(_com_error &e)<br /> {<br /> dump_com_error(e);<br /> return FALSE;<br /> }<br /><br /> //Free memory<br /> GlobalUnlock(lpData);<br /> return true;<br />}For image display, I created a class which wraps the freeimage library.<br /><br />Update history <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/loading-image-files-from-database-using.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/loading-image-files-from-database-using.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-05T20:35:00-08:00'>8:35 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/loading-image-files-from-database-using.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=1766315865176933955' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=1766315865176933955&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='3276872304151496077' itemprop='postId'/> <a name='3276872304151496077'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/sql-bulk-copy-with-c-net.html'>Sql bulk copy with c# .net</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-3276872304151496077' itemprop='description articleBody'> Introduction<br />Programmers usually need to transfer production data for testing or analyzing. The simplest way to copy lots of data from any resources to SQL Server is BulkCopying. .NET Framework 2.0 contains a class in ADO.NET "System.Data.SqlClient" namespace: SqlBulkCopy. The bulk copy operation usually has two separated phases. <br /><br />In the first phase you get the source data. The source could be various data platforms such as Access, Excel, SQL.. You must get the source data in your code wrapping it in a DataTable, or any DataReader class which implements IDataReader. After that, in the second phase, you must connect the target SQL Database and perform the bulk copy operation. <br /><br />The bulk copy operation in .Net is a very fast way to copy large amount of data somewhere to SQL Server. The reason for that is the Bulkcopy Sql Server mechanism. Inserting all data row by row, one after the other is a very time and system resources consuming. But the bulkcopy mechanism process all data at once. So the data inserting becomes very fast. <br /><br />Solution walkthrough<br />While you are programming for bulk copy, first open a connection for the source data. In this sample we are connecting a SQL Server named SQLProduction. We are using SqlConnectionStringBuilder to build our connection string.<br /><br /> Collapse Copy Code<br />// Establishing connection<br />SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder(); <br />cb.DataSource = "SQLProduction"; <br />cb.InitialCatalog = "Sales"; <br />cb.IntegratedSecurity = true;<br />SqlConnection cnn = new SqlConnection(cb.ConnectionString); <br />Then we are retrieving data from the source with SqlCommand and SqlDataReader classes. <br /><br /> Collapse Copy Code<br />// Getting source data<br />SqlCommand cmd = new SqlCommand("SELECT * FROM PendingOrders",cnn); <br />cnn.Open(); <br />SqlDataReader rdr = cmd.ExecuteReader(); <br />Now we have a data in rdr variable. It's time to initialize a SqlBulkCopy object and copy the data. The SqlBulkCopy class needs a connection to copy data into a Sql server. You can establish a second connection explicitly or the class will do it for you. We are using the second alternative with creating a SqlBulkCopy object. We are passing a connection string as a parameter in constructor method.<br /><br /> Collapse Copy Code<br />// Initializing an SqlBulkCopy object<br />SqlBulkCopy sbc = new SqlBulkCopy("server=.;database=ProductionTest;" + "Integrated Security=SSPI"); OK. The sbc object is ready to copy. Now you must tell the object the destination table name, start the copying process calling WriteToServer method and pass the method the SqlDataReader variable rdr as parameter.<br /><br /> Collapse Copy Code<br />// Copying data to destination<br />sbc.DestinationTableName = "Temp"; <br />sbc.WriteToServer(rdr); At the end, close all SqlConnection, SqlDataReader and SqlBulkCopy objects.<br /><br /> Collapse Copy Code<br />// Closing connection and the others<br />sbc.Close(); <br />rdr.Close(); <br />cnn.Close(); That's all. Just a few lines and in a few seconds...<br /><br /> Collapse Copy Code<br />// Establishing connection<br />SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder(); <br />cb.DataSource = "SQLProduction"; <br />cb.InitialCatalog = "Sales"; <br />cb.IntegratedSecurity = true;<br />SqlConnection cnn = new SqlConnection(cb.ConnectionString); <br /><br />// Getting source data<br />SqlCommand cmd = new SqlCommand("SELECT * FROM PendingOrders",cnn); <br />cnn.Open(); <br />SqlDataReader rdr = cmd.ExecuteReader(); <br /><br />// Initializing an SqlBulkCopy object<br />SqlBulkCopy sbc = new SqlBulkCopy("server=.;database=ProductionTest;" + "Integrated Security=SSPI"); <br /><br />// Copying data to destination<br />sbc.DestinationTableName = "Temp"; <br />sbc.WriteToServer(rdr); <br /><br />// Closing connection and the others<br />sbc.Close(); <br />rdr.Close(); <br />cnn.Close(); <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/sql-bulk-copy-with-c-net.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/sql-bulk-copy-with-c-net.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-05T20:30:00-08:00'>8:30 PM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/sql-bulk-copy-with-c-net.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=3276872304151496077' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=3276872304151496077&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='7866557403921263329' itemprop='postId'/> <a name='7866557403921263329'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/google-earth-network-link.html'>Google Earth network link</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-7866557403921263329' itemprop='description articleBody'> Introduction<br /><br />This article aims to show the creation of Network Links for Google Earth.<br />The Code Source<br /><br />Create a new ASP.NET Web application and upon Page_Load, copy and paste this code, or download the source code.<br />Grid Creation: Creating the Constructor for the Grid<br />Collapse<br /><br />Imports System.Xml<br />Partial Public Class _Default<br /> Inherits System.Web.UI.Page<br /> Protected Sub Page_Load(ByVal sender As Object,<br /> ByVal e As System.EventArgs) Handles Me.Load<br /> Me.Response.Clear()<br /> Me.Response.ContentType = "application/vnd.google-earth.kml+xml"<br /> 'Para ver o documento XML<br /> 'For view XML document<br /> 'My.Response.ContentType = "plain/text"<br /> Me.Response.ContentEncoding = System.Text.Encoding.UTF8<br /> Dim stream As New System.IO.MemoryStream<br /> Dim XMLwrite As New XmlTextWriter(stream, System.Text.Encoding.UTF8)<br /> XMLwrite.WriteStartDocument()<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteStartElement("kml")<br /> XMLwrite.WriteAttributeString("xmlns",<br /> "http://earth.google.com/kml/2.0")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> '<Document><br /> XMLwrite.WriteStartElement("Document")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("name", "Signal Control")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> '<Placemark><br /> XMLwrite.WriteStartElement("Placemark")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("description", "MY DESCRIPTION/MINHA DESCRIÇÃO")<br /> XMLwrite.WriteElementString("name", "MY NAME/MEU NOME")<br /> XMLwrite.WriteStartElement("LookAt")<br /> XMLwrite.WriteElementString("longitude", "MY LONGITUDE/MINHA LONGITUDE")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("latitude", "MY LATITUDE/MINHA LATITUDE")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteEndElement()<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("visibility", "1")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> '<Style><br /> XMLwrite.WriteStartElement("Style")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> '<IconStyle><br /> XMLwrite.WriteStartElement("IconStyle")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> '<Icon><br /> XMLwrite.WriteStartElement("Icon")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> 'Meu ícone, mudar este diretório<br /> 'My Icon, change this directory<br /> XMLwrite.WriteElementString("href", "C:\Code_Project\01.ico")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("w", "-1")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteElementString("h", "-1")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteEndElement()<br /> '</Icon><br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteEndElement()<br /> '</IconStyle><br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteEndElement()<br /> '</Style><br /> '<Point><br /> XMLwrite.WriteStartElement("Point")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> 'Minhas coordenadas, mudar aqui<br /> 'My Coordinates, change aqui<br /> XMLwrite.WriteElementString("coordinates", <br /> "-25.4942072754", "-49.5426559491",<br /> "50")<br /> XMLwrite.WriteWhitespace(Environment.NewLine)<br /> XMLwrite.WriteEndElement()<br /> XMLwrite.WriteEndElement()<br /> '</Point>'Fim do XML<br /> 'Finish XML<br /> XMLwrite.WriteEndDocument()<br /> XMLwrite.Flush()<br /> Dim reader As IO.StreamReader<br /> stream.Position = 0<br /> reader = New IO.StreamReader(stream)<br /> Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd())<br /> Me.Response.BinaryWrite(bytes)<br /> Me.Response.End()<br /> End Sub<br />End Class <br /><br />Points of Interest<br /><br />Go to places on Google Earth and click Add Network Link.<br /><br />Screenshot - image002.jpg<br /><br />Screenshot - image003.jpg<br /><br />After compiling the project, this icon will arise:<br /><br />Screenshot - image004.jpg<br /><br />My link is created:<br /><br />Screenshot - image005.jpg <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/google-earth-network-link.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/google-earth-network-link.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-05T02:15:00-08:00'>2:15 AM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/google-earth-network-link.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=7866557403921263329' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=7866557403921263329&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='3731598866235249865' itemprop='postId'/> <a name='3731598866235249865'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/integrate-webcam-with-net-application.html'>Integrate webcam with a .net application</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-3731598866235249865' itemprop='description articleBody'> Introduction<br /><br />Webcam is a Simple Object Access Protocol (SOAP) project that will permit client's software to get, from a Web Service, JPEG pictures captured by a Webcam. It is my first step experiment in the world of SOAP after several projects using COM/DCOM and ATL.<br /><br />The project is split in three parts:<br /><br /> * Server: Active Template Library Server capturing a picture from the Webcam.<br /> * Web Service: Generated with WSDL Generator from Microsoft�.<br /> * Client: ActiveX client connecting to Webcam SOAP Server getting pictures and displaying them.<br /><br />Server<br /><br />We use Visual C++ and the Active Template Library (ATL) object Wizard to create a Simple COM object, called Camera. It handles the grabbing of the picture and the JPEG compression.<br /><br />The jpeg compression is achieved with Intel� JPEG Library v1.5. Get it here. You may use other libraries, like IJG JPEG LIBRARY, by using the abstract base class CPicturePacker.<br /><br />Camera handling is done using Microsoft� Video for Windows� (VFW). Get more information on MSDN / Platform SDK Documentation / Graphics and Multimedia Services / Windows Multimedia / Video Capture.<br /><br />Trick: VFW needs a handler on a window to attach the camera driver to. As we chose to create a Simple COM object we do not have access to any window handler. Calling GetDesktopWindow() got us one.<br />Collapse<br /><br /> // Don't have access to the container's window so just use the desktop.<br /><br /> // RMK: If the desktop is not at least 24bits colors, then the grab will<br /><br /> // fail<br /><br /> HWND hWnd = ::GetDesktopWindow();<br /><br /> if ( hWnd )<br /> { ...<br /><br />All functionalities needed to grab a picture on a Webcam are done in the class CWebCam. For example the method GrabFrame:<br />Collapse<br /><br /> bool CWebCam::GrabFrame( CPicturePacker * pPacker,<br /> unsigned char ** ppPackedPicture,<br /> unsigned long * pnPackedPictureBytes )<br /><br />Use a reference to a CPicturePacker base class to pack the original picture's bits, permitting to extend the packing to whatever format you want, as mentioned before. In this sample I have written the class CIntelJpegPacker inheriting from CPicturePacker and using the Intel� JPEG Library v1.5 to pack the picture grabbed. You may consider using GDI+ for example to do the same.<br /><br />The rest of the source is dealing with COM and is nothing special.<br />Server Interface<br /><br />Our server needs to achieve two simple operations: grabbing a picture from a Webcam and compressing it as a JPEG picture according to a compression ratio defined by the caller. This is achieved in the GrabFrame method.<br />Collapse<br /><br />HRESULT GrabFrame( [in] short nQuality, <br /> [out, retval] SAFEARRAY(unsigned char) * ppGrabbedPicture );<br /><br />The input parameter 'nQuality' represents the jpeg compression ratio, from 1 to 99. A value of one meaning lowest quality (highest compression) and a value of ninety-nine meaning highest quality (lowest compression).<br /><br />As an output return value the client get the jpeg picture in a SAFEARRAY of unsigned char. We use this data type because it is fully supported by SOAP (See faced problem 1 and 2).<br /><br />Our COM object supports the interface IErrorInfo as indicated by the ISupportErrorInfo interface. It permits sending back to the client information about possible issues encountered by the server. The good point is that it is fully automatic for us. Read more about that point in Microsoft SOAP User Guide: "Understanding the SOAP Fault <detail> Contents".<br /><br />Before writing your interfaces check out the different types supported by SOAP in "Data Type Mappings" and there equivalence in programming languages. You find them in the Microsoft SOAP User Guide.<br />Web Service<br /><br />We simply use Microsoft WSDL Generator to wrap our COM object, Camera, into a SOAP Web Service.<br /><br />On the welcome page click Next.<br /><br /> <br /><br />On the dialog "Select the COM .dll to analyze":<br /><br />Enter the name of your Web Service, i.e. webcam. <br /><br />Browse to select your dll.<br /><br />Click Next.<br /><br /> <br /><br />On the dialog "Select the services you would like to expose":<br /><br />Expand the list and check the GrabFrame method.<br /><br />Click Next.<br /><br /> <br /><br /> <br /><br />On the dialog "SOAP listener information":<br /><br />In the URI text box, type the url of your webservice, i.e. http://localhost/webservices/webcam.<br /><br />Choose ISAPI Listener type.<br /><br />Then select 2001 as XSD Schema Namespace.<br /><br />Click Next.<br /> <br /><br />On the dialog "Specify the location for the new WSDL and WSML files":<br /><br />Select UTF-8 as character set.<br /><br />Then select the place you want to store the new files, i.e. c:\inetpub\WebServices\webcam.<br /><br />Click Next.<br /><br />Click Finish.<br /><br /> <br /><br />Now we have our Web Service! You must also define a Virtual Directory called WebServices in IIS.<br />In the case you want to change the location of the Web Service you need to change the WSDL file generated by Microsoft WSDL Generator.<br />Client<br /><br />We use Visual C++ and Active Template Library (ATL) object Wizard to create an ActiveX, called Webcam. This ActiveX is the client part of the Web Service Webcam. It is connecting to the Webcam Web Service, receiving back a jpeg picture and displaying it.<br /><br />To be able to compile the project you must have installed SOAP Toolkit on your computer. Find it here. For the client you must also have WTL installed. If It is not the case donwload it here.<br />Client Interface<br /><br />To be able to grab a picture on the Webcam Web Service, we need to specify the location of the Web Service and a compression ratio. We define this interface:<br />Collapse<br /><br /> HRESULT GrabFrame([in] BSTR strWeb ServiceURL, [in] short nQuality);<br /><br /> * Input parameter 'strWeb ServiceURL' represents Web Service's URL.<br /> * Input parameter 'nQuality' represents the jpeg compression ratio, from 1 to 99. A value of one meaning lowest quality (highest compression) and a value of ninety-nine meaning highest quality (lowest compression).<br /><br />If we get an error, we display it in a tooltip. To create and display the tooltip we use Windows Template Library (WTL).<br />Test<br /><br />You may test this Web Service after installing client ActiveX on this page.<br />Problems Faced<br /><br /> * When adding the "GrabFrame" method to Webcam Server using the ATL "Add Method to Interface", the method was created correctly in .idl and .h files but the not in the .cpp. We can find a kind of explanation on MSDN: Q198017.<br /> * Before SOAP SDK SP2, SAFEARRAY(unsigned char) was not correctly handled. You need the SP2 to get a correct wrapping from SAFEARRAY(unisgned char) to base64Binary. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/integrate-webcam-with-net-application.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/integrate-webcam-with-net-application.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-05T02:11:00-08:00'>2:11 AM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/integrate-webcam-with-net-application.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=3731598866235249865' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=3731598866235249865&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='8769773808837040573' itemprop='blogId'/> <meta content='5129877808639049927' itemprop='postId'/> <a name='5129877808639049927'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='http://manojpoojasharma.blogspot.com/2010/02/secure-net-application.html'>Secure a .Net Application</a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-5129877808639049927' itemprop='description articleBody'> Introduction<br /><br />There is no glamour in building secure ASP.NET web applications. The vast majority of developers I’ve met would much rather focus on building new & flashy features that can impress their managers and end-users. Even though security can usually take a backseat during the initial stages of development, it usually comes back to bite you when it’s least expected. This article covers some of the security aspects to be aware of when developing a new web application and what to do throughout the development process to protect applications and databases against common attacks.<br />Back to Reality<br /><br />Building web applications with ASP.NET has been getting easier as the technology and the development environment, Visual Studio, become more sophisticated. Many of the complexities are taken care of by the framework and are out of view from developers. This allows us to focus more on the business value and features of our web applications and less on technical aspects that very few really understand or appreciate. As a result, many developers believe that security is also taken care of for them and they need not to worry about it.<br /><br />Unfortunately the reality is quite different. Unless developers make security one of their priorities early on in the development cycle, project managers might end up with a great application but one that cannot go live without compromising the safety of their end-users and their data.<br />Attacks Are Easier Than You Might Think<br /><br />It might be surprising to many project & product managers that exploiting web applications does not necessarily require expert knowledge. Attacks are often perpetrated by hobbyists with very simple means. Here are two recent examples.<br />Attack I: SQL injection at Telegraph results in 700,000 emails stolen<br /><br />The Attack - On March 6th, 2009, a hacker used blind SQL injection to penetrate to the web site of The Telegraph, a leading English daily paper. Based on reports, he or she was able to gain access to about 700,000 email addresses on the site’s database. Telegraph’s response can be found on their blog.<br /><br />Some Background – SQL statements are generally used to retrieve, update and delete data against a web application’s database. This is normally done behind the scenes and the results are displayed to a user based on their authority level. This means that the data is protected and access is granted on a selective basis.<br /><br />Attack Explanation - Many web applications provide some form of search capabilities where users can provide their own filtering on the data the application might display. For example, a filter to see only the records posted in 2009. If the application is not secure, a hacker can potentially exploit this functionality. Rather than supplying a value to filter upon, he might provide another SQL statement that is then injected in to the SQL statement that the application uses to retrieve data.<br /><br />Attack Example – Let’s assume a user only has access to the records of his department and to filter through the records, he enters some criteria. He wants to see the latest records, so he enters 2009 in the year range.<br /><br />The application might attempt to execute the following statement against the database: SELECT * FROM … WHERE … AND Year = 2009<br /><br />A hacker on the other hand, might try to trick the application and enter the following into that same year range field: 2009 OR 1=1<br /><br />The application, if not careful, might then execute the following statement against the database: SELECT * FROM … WHERE … AND Year = 2009 OR 1=1<br /><br />This would potentially provide the user with access to all the records in the system, even the ones to which they shouldn’t.<br />Attack II: Authentication Security Holes at Sage<br /><br />The Attack – Sage, a leading provider of accounting software in the UK, was about to launch Sage Live, a small business accounting product as SaaS (software as a service). However according to ZDnet, Sage Live went dead after serious security flaws were exposed in the product. The flaws were exposed by the founder of a tiny rival. Duane Jackson, CEO of UK-based KashFlow, described what she found on her blog: “A little bit of prodding around the site and I found myself looking at… pages that only authorized people should be seeing.”<br /><br />Attack Explanation - Users navigate to and though web applications by going from one URL address to another, much like postal addresses point to residential homes and businesses. As a result, users can easily change the URL and its parameters that can potentially lead to pages and information that they wouldn’t ordinarily be allowed to view.<br />Common ASP.NET Security Flaws<br /><br />There is a wide array of attacks that ASP.NET web applications need to protect against but most security holes are due to flaws in the following:<br /><br />- Authentication<br /><br />Making it easy for attackers to reveal users credentials, or worse to circumvent the application’s authentication altogether.<br /><br />Possible deficiencies: lack of password policy (strong passwords, expiration date etc), passing internal messages back to the browser, using dynamic SQL on the login page (SQL injection), using cookies and other insecure means to store users’ credentials, and passing user names and passwords in clear text .<br /><br />Possible attacks: network eavesdropping, brute force & dictionary attacks, SQL injection (on login page), Cookie replay attacks and credential theft.<br /><br />- Authorization<br /><br />Allowing logged-in users to perform actions without authorization verification (i.e. vertical & horizontal privilege escalation.)<br /><br />Possible deficiencies: inconsistent checks for user authorization for every user’s request and web page, lack of data validation and trusting data submitted by users (i.e. cookies, hidden fields, URL parameters, etc.)<br /><br />Possible attacks: privilege escalation attacks (horizontal and vertical), disclosure of confidential data and Data tampering attacks.<br /><br />- Data Validation<br /><br />Trusting data submitted by the user and acting upon it.<br /><br />Possible deficiencies: lack of consistent and strict data validation throughout the web, and failing to encode data sent to the browser.<br /><br />Common Attacks: cross-site scripting (XSS), SQL injection, data tampering (query string, form fields, cookies, and HTTP headers), embedded malicious characters and HTTP response splitting.<br /><br />- Application Configuration<br /><br />Using default configuration on the application and hosted server.<br /><br />Possible deficiencies: granting the application more permissions than it actually needs, failing to properly secure resources (operating system, database, etc.) and passing internal application information back to the browser (internal messages, exceptions and trace information.)<br /><br />Common Attacks: unauthorized access to administrator functionality, unauthorized access to configuration information, retrieval of clear text configuration information and unauthorized access to data stores.<br />Securing Your ASP.NET Web Application<br /><br />Implementing security after the fact has a steep cost associated with it. Fixing software defects after the application goes into production might cost up to 15 times more than during development. Lax security also has some other indirect costs, such as damaging a company’s reputation and losing customers.<br /><br />While securing an ASP.NET web application can be complex, it needs to be done on a continuous basis. The .NET framework, and ASP.NET in particular, offers great features to make it easier to properly secure your web application.<br />Authentication<br /><br />Although ASP.NET supports several authentication methods, form authentication is the most commonly used by web applications. Unfortunately, this approach is not a particularly secure approach as it sends user’s credentials to the server in clear text. Depending on requirements, you might want to consider using SSL throughout the site or at least on the login page.<br /><br />But since SSL might be impractical for many commercial web applications, one new & unique approach that you can consider is using Silverlight. Silverlight can be embedded on any sensitive page and provide encryption of any submitted data.<br /><br />A web application’s authentication can be further enhanced with the following:<br /><br />- Password Policy<br /><br />Enforce a password policy including strong passwords, password expiration, and possibly locking user accounts after a few unsuccessful login attempts.<br /><br />- Guessing Credentials – Brute Force Attacks<br /><br />In addition to the above, you might want to introduce a random delay of a few seconds upon unsuccessful user login. This would make brute force attacks impractical to execute (use Thread.Sleep for this scenario.)<br /><br />- Password Hashing<br /><br />If you manage your authentication store, make sure to hash all user passwords.<br />Page Authorization & Data Validation<br /><br />Small web applications are often built as a series of fairly isolated web pages. Each page is designed to handle its own security and functionality, basically acting as a mini application. Although this approach might work when security & maintenance concerns are few, it very rarely works for a larger web application.<br /><br />One approach that is commonly implemented, which can offer a solid data validation and authorization infrastructure, is the development of a web framework to be used by all ASP.NET web pages in a consistent manner. This web framework should be designed to employ common authorization and data validation security check points upon every user request, allowing the application to streamline and tighten many security aspects throughout the application.<br /><br />Building such a web framework in ASP.NET is surprisingly easy. Using .NET inheritance, we can design one or more ASP.NET base classes to inherit from the System.Web.UI.Page object. These base classes would run during each page lifecycle and would verify each user request before the results are served to the user.<br /><br />The following page lifecycle events are commonly used to perform security checks before the page begins processing the request: Init, InitComplete and PreLoad.<br />Constructing the ASP.NET Web Framework<br /><br />Structuring base web pages is easy. Let’s assume that our ASP.NET web application supports three kinds of users:<br /><br />Unregistered users – allowed to browse anything publicly available.<br /><br />Logged-in users – allowed to browse anything that’s public plus their own private information.<br /><br />Administrators - same as a logged-in user plus some extra admin functionality.<br /><br />Diagram 1: Base class to serve unregistered users and the foundation for other base classes<br />Collapse<br /><br />public abstract class BaseWebPage : System.Web.UI.Page<br />{<br /> ...<br />}<br /><br />Note: This class should verify general information submitted by users, such as URL parameters, form data to some extent, cookies and other info that is not tied to any particular user.<br /><br />Diagram 2: User base class to be inherited by all pages used by logged-in users<br />Collapse<br /><br />public abstract class UserWebPage : BaseWebPage<br />{<br /> ...<br />}<br /><br />Note: This class should ensure that the user is currently logged-in and has access to the page functionality and to the date they want to view.<br /><br />Diagram 3: Administrator base class to be inherited by all pages used by administrators<br />Collapse<br /><br />public abstract class AdminWebPage : UserWebPage<br />{<br /> ...<br />}<br /><br />Note: This class should ensure that in the current user is indeed an administrator.<br />Linking the Page to Our Web Framework<br /><br />Utilizing the ASP.NET web framework above requires very minor adjustments to a web page. Rather than using the default ASP.NET page base class (System.Web.UI.Page) use the appropriate base class defined earlier.<br /><br />For instance, if we defined a new ASPX page that is supposed to serve logged-in users we would define it as follows:<br /><br />Diagram 4: Sample ASPX code-behind page serving a particular user<br />Collapse<br /><br />public partial class ShowUserSettingsPage : UserWebPage<br />{<br /> ...<br />}<br /><br />Performing Page Authorization & Data Validation<br /><br />Now that we have built our web framework, all we have left is to verify user authorization per page and to perform general data validation for each request.<br /><br />To perform page authorization, we would define one virtual method on the BaseWebPage class to authorize the current user. Both the UserWebPage and the AdminWebPage would override this method and provide their own implementation. We would call this method on Page_Init from the BaseWebPage before any page processing is taking place.<br /><br />This might be implemented as follows:<br /><br />Diagram 5: Page authorization & data validation on BaseWebPage base class<br />Collapse<br /><br />public abstract class BaseWebPage : System.Web.UI.Page<br /> {<br /> protected void Page_Init(object sender, EventArgs e)<br /> {<br /> AuthorizeUser();<br /><br /> ValidateSubmittedData();<br /> }<br /><br /> protected virtual void AuthorizeUser()<br /> {<br /> //no need to do anything for unregistered users<br /> }<br /><br /> ...<br /><br /> }<br /><br />Note: Class calls a virtual method AuthorizeUser that inheriting classes can implement to force specific user access rights, and once the user is authorized, the class verifies all data submitted to the web page.<br /><br />Diagram 6: Page authorization on UserWebPage for ASP.NET web pages designated for logged-in users<br />Collapse<br /><br />public abstract class UserWebPage : BaseWebPage<br /> {<br /> protected override void AuthorizeUser()<br /> {<br /> if(!User.IsInRole("User"))<br /> {<br /> //user cannot see the page - redirect to appropriate page<br /> }<br /> }<br /> }<br /><br />Note: Class overrides the AuthorizeUser to make sure current user is logged-in.<br />More on Data Validation<br /><br />A centralized web framework can offer many security benefits to web applications, but it often needs to be complemented with page-specific security measures to ensure proper data validation.<br /><br />Web pages should employ data validation based on the following guidelines:<br /><br /> * Data validation – web pages should enforce strict data validation on any piece of data not strictly covered by the web framework. This might include additional type casting (for instance ensures that a piece of data is an integer) range and length. Regular expressions and Regex class are a great a great way to constrain input in ASP.NET.<br /> * Encoding – any web page displaying data on the browser that cannot be guaranteed to be safe should be encoded using Server.HtmlEncode to prevent any malicious cross-site scripting (XSS) attacks.<br /> * URL write actions– avoid performing database write actions against URL parameters even if data is valid and the user has authorization to perform such actions. Also ensure that every POST action is actually done from an internal application page to prevent cross-site request forgeries (CSRF) attacks.<br /> * Exceptions – make sure to catch any possible exceptions and only send user-friendly messages to the browser to avoid revealing any sensitive information that might reveal an application’s vulnerabilities.<br /><br />Data Authorization – Data Access Framework<br /><br />N-tier infrastructure is not a foreign concept to most ASP.NET developers and can provide substantial benefits in terms of performance and scalability. Among the many benefits of n-tier architecture, it also can be used to centralize and enforce strict authorization rules.<br /><br />To do this effectively, a data access framework should be built as an isolated component and should be designed to do the following for each piece of functionality exposed to the ASP.NET web application:<br /><br /> * Parameter Validation - validate all parameters supplied by the user for type, range, length, etc.<br /> * Authentication - ensure that the calling user is a valid user.<br /> * Authorization – verify that the user has rights to perform the current database operation.<br /> * Database Queries - avoid using dynamic SQL queries, if possible, and only use parameters.<br /> * User Data - only send back data that the current user is entitled to view or return user-friendly exceptions.<br /><br />Application Configuration<br /><br />Different applications require different configurations but the focus of this section is on those that fall under the responsibility of the web developer.<br />Encrypting Sensitive Configuration Information<br /><br />Any sensitive configuration information on the web.config and beyond should be properly encrypted to avoid exposing sensitive details like connection strings to potential attackers. You can use the web.config protectedData section to indicate which sections of the web.config file should be encrypted.<br /><br />The following shows how to protect the connectionStrings section:<br /><br />Diagram 7: Protecting the connectionStrings section within the web.config<br />Collapse<br /><br /><protectedData><br /> <protecteddatasections><br /> <add name="connectionStrings" provider="RSAProtectedConfigurationProvider"><br /> </add><br /></protecteddatasections><br /><br />Note: This is a more suitable way to protect data across different web servers. Unlike DPAPI, the information is not tied down to any particular machine.<br /><br />You can now use aspnet_regiis to encrypt the appropriate section:<br />aspnet_regiis -pef connectionStrings "c:\...\MyWebApplication"<br />Protect Internal Exceptions<br /><br />Prevent detailed exceptions from being displayed on the client’s browser entirely or display this only when the client is browsing on the web server itself.<br />Final Note<br /><br />Even though it can be tempting to push off dealing with security (or avoiding it altogether), its importance should never be underestimated. An attack or even a request for a security audit by a customer can cost you time, money and potentially your company’s reputation. <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/10032995026597187555' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' title='author profile'> <span itemprop='name'>Manoj Sharma Technology is a Boom----</span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://manojpoojasharma.blogspot.com/2010/02/secure-net-application.html' itemprop='url'/> <a class='timestamp-link' href='http://manojpoojasharma.blogspot.com/2010/02/secure-net-application.html' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2010-02-05T02:09:00-08:00'>2:09 AM</abbr></a> </span> <span class='post-comment-link'> <a class='comment-link' href='http://manojpoojasharma.blogspot.com/2010/02/secure-net-application.html#comment-form' onclick=''> No comments: </a> </span> <span class='post-icons'> <span class='item-action'> <a href='https://www.blogger.com/email-post.g?blogID=8769773808837040573&postID=5129877808639049927' title='Email Post'> <img alt='' class='icon-action' height='13' src='https://resources.blogblog.com/img/icon18_email.gif' width='18'/> </a> </span> <span class='item-control blog-admin pid-328658345'> <a href='https://www.blogger.com/post-edit.g?blogID=8769773808837040573&postID=5129877808639049927&from=pencil' title='Edit Post'> <img alt='' class='icon-action' height='18' src='https://resources.blogblog.com/img/icon18_edit_allbkg.gif' width='18'/> </a> </span> </span> <div class='post-share-buttons goog-inline-block'> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> </div></div> </div> <div class='blog-pager' id='blog-pager'> <span id='blog-pager-newer-link'> <a class='blog-pager-newer-link' href='http://manojpoojasharma.blogspot.com/' id='Blog1_blog-pager-newer-link' title='Newer Posts'>Newer Posts</a> </span> <span id='blog-pager-older-link'> <a class='blog-pager-older-link' href='http://manojpoojasharma.blogspot.com/search?updated-max=2010-02-05T02:09:00-08:00&max-results=7' id='Blog1_blog-pager-older-link' title='Older Posts'>Older Posts</a> </span> <a class='home-link' href='http://manojpoojasharma.blogspot.com/'>Home</a> </div> <div class='clear'></div> <div class='blog-feeds'> <div class='feed-links'> Subscribe to: <a class='feed-link' href='http://manojpoojasharma.blogspot.com/feeds/posts/default' target='_blank' type='application/atom+xml'>Posts (Atom)</a> </div> </div> </div><div class='widget Followers' data-version='1' id='Followers1'> <h2 class='title'>Followers</h2> <div class='widget-content'> <div id='Followers1-wrapper'> <div style='margin-right:2px;'> <div><script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <div id="followers-iframe-container"></div> <script type="text/javascript"> window.followersIframe = null; function followersIframeOpen(url) { gapi.load("gapi.iframes", function() { if (gapi.iframes && gapi.iframes.getContext) { window.followersIframe = gapi.iframes.getContext().openChild({ url: url, where: document.getElementById("followers-iframe-container"), messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { '_ready': function(obj) { window.followersIframe.getIframeEl().height = obj.height; }, 'reset': function() { window.followersIframe.close(); followersIframeOpen("https://www.blogger.com/followers.g?blogID\x3d8769773808837040573\x26colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26origin\x3dhttp://manojpoojasharma.blogspot.com/"); }, 'open': function(url) { window.followersIframe.close(); followersIframeOpen(url); }, 'blogger-ping': function() { } } }); } }); } followersIframeOpen("https://www.blogger.com/followers.g?blogID\x3d8769773808837040573\x26colors\x3dCgt0cmFuc3BhcmVudBILdHJhbnNwYXJlbnQaByM2NjY2NjYiByM1NTg4YWEqByNmZmZmZmYyByNjYzY2MDA6ByM2NjY2NjZCByM1NTg4YWFKByM5OTk5OTlSByM1NTg4YWFaC3RyYW5zcGFyZW50\x26pageSize\x3d21\x26origin\x3dhttp://manojpoojasharma.blogspot.com/"); </script></div> </div> </div> <div class='clear'></div> </div> </div></div> </div> <div id='sidebar-wrapper'> <div class='sidebar section' id='sidebar'><div class='widget Feed' data-version='1' id='Feed1'> <h2>Latest News</h2> <div class='widget-content' id='Feed1_feedItemListDisplay'> <span style='filter: alpha(25); opacity: 0.25;'> <a href='http://indiatoday.intoday.in/site/rssGenerator.jsp?secId=4&feed=LATEST%20NEWS'>Loading...</a> </span> </div> <div class='clear'></div> </div><div class='widget Subscribe' data-version='1' id='Subscribe1'> <div style='white-space:nowrap'> <h2 class='title'>Subscribe To my Blog</h2> <div class='widget-content'> <div class='subscribe-wrapper subscribe-type-POST'> <div class='subscribe expanded subscribe-type-POST' id='SW_READER_LIST_Subscribe1POST' style='display:none;'> <div class='top'> <span class='inner' onclick='return(_SW_toggleReaderList(event, "Subscribe1POST"));'> <img class='subscribe-dropdown-arrow' src='https://resources.blogblog.com/img/widgets/arrow_dropdown.gif'/> <img align='absmiddle' alt='' border='0' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> Posts </span> <div class='feed-reader-links'> <a class='feed-reader-link' href='https://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fmanojpoojasharma.blogspot.com%2Ffeeds%2Fposts%2Fdefault' target='_blank'> <img src='https://resources.blogblog.com/img/widgets/subscribe-netvibes.png'/> </a> <a class='feed-reader-link' href='https://add.my.yahoo.com/content?url=http%3A%2F%2Fmanojpoojasharma.blogspot.com%2Ffeeds%2Fposts%2Fdefault' target='_blank'> <img src='https://resources.blogblog.com/img/widgets/subscribe-yahoo.png'/> </a> <a class='feed-reader-link' href='http://manojpoojasharma.blogspot.com/feeds/posts/default' target='_blank'> <img align='absmiddle' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> Atom </a> </div> </div> <div class='bottom'></div> </div> <div class='subscribe' id='SW_READER_LIST_CLOSED_Subscribe1POST' onclick='return(_SW_toggleReaderList(event, "Subscribe1POST"));'> <div class='top'> <span class='inner'> <img class='subscribe-dropdown-arrow' src='https://resources.blogblog.com/img/widgets/arrow_dropdown.gif'/> <span onclick='return(_SW_toggleReaderList(event, "Subscribe1POST"));'> <img align='absmiddle' alt='' border='0' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> Posts </span> </span> </div> <div class='bottom'></div> </div> </div> <div class='subscribe-wrapper subscribe-type-COMMENT'> <div class='subscribe expanded subscribe-type-COMMENT' id='SW_READER_LIST_Subscribe1COMMENT' style='display:none;'> <div class='top'> <span class='inner' onclick='return(_SW_toggleReaderList(event, "Subscribe1COMMENT"));'> <img class='subscribe-dropdown-arrow' src='https://resources.blogblog.com/img/widgets/arrow_dropdown.gif'/> <img align='absmiddle' alt='' border='0' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> All Comments </span> <div class='feed-reader-links'> <a class='feed-reader-link' href='https://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fmanojpoojasharma.blogspot.com%2Ffeeds%2Fcomments%2Fdefault' target='_blank'> <img src='https://resources.blogblog.com/img/widgets/subscribe-netvibes.png'/> </a> <a class='feed-reader-link' href='https://add.my.yahoo.com/content?url=http%3A%2F%2Fmanojpoojasharma.blogspot.com%2Ffeeds%2Fcomments%2Fdefault' target='_blank'> <img src='https://resources.blogblog.com/img/widgets/subscribe-yahoo.png'/> </a> <a class='feed-reader-link' href='http://manojpoojasharma.blogspot.com/feeds/comments/default' target='_blank'> <img align='absmiddle' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> Atom </a> </div> </div> <div class='bottom'></div> </div> <div class='subscribe' id='SW_READER_LIST_CLOSED_Subscribe1COMMENT' onclick='return(_SW_toggleReaderList(event, "Subscribe1COMMENT"));'> <div class='top'> <span class='inner'> <img class='subscribe-dropdown-arrow' src='https://resources.blogblog.com/img/widgets/arrow_dropdown.gif'/> <span onclick='return(_SW_toggleReaderList(event, "Subscribe1COMMENT"));'> <img align='absmiddle' alt='' border='0' class='feed-icon' src='https://resources.blogblog.com/img/icon_feed12.png'/> All Comments </span> </span> </div> <div class='bottom'></div> </div> </div> <div style='clear:both'></div> </div> </div> <div class='clear'></div> </div><div class='widget HTML' data-version='1' id='HTML2'> <h2 class='title'>Visitor Map</h2> <div class='widget-content'> <a id="clustrMapsLink" href="http://www3.clustrmaps.com/counter/maps.php?url=http://manojpoojasharma.blogspot.com"><img id="clustrMapsImg" style="border:0px;" alt="Locations of visitors to this page" src="http://www3.clustrmaps.com/counter/index2.php?url=http://manojpoojasharma.blogspot.com" onerror="this.onerror=null; this.src='http://www2.clustrmaps.com/images/clustrmaps-back-soon.jpg'; document.getElementById('clustrMapsLink').href='http://www2.clustrmaps.com';" title="Locations of visitors to this page" /> </a> </div> <div class='clear'></div> </div><div class='widget Image' data-version='1' id='Image1'> <h2>Manoj Sharma</h2> <div class='widget-content'> <img alt='Manoj Sharma' height='230' id='Image1_img' src='http://1.bp.blogspot.com/_5e0hpfk5tgU/SynVrgTfpHI/AAAAAAAAAA0/zdXN_nY0Yug/S230/IMG0053A.jpg' width='173'/> <br/> </div> <div class='clear'></div> </div><div class='widget HTML' data-version='1' id='HTML1'> <h2 class='title'>My Visits</h2> <div class='widget-content'> <a href="http://xyz.freelogs.com/stats/m/manojsharma123/" target="_top"><img border="0" vspace="2" hspace="4" alt="myspace web counter" src="http://xyz.freelogs.com/counter/index.php?u=manojsharma123&s=bbldotg" align="middle"/></a><script src="http://xyz.freelogs.com/counter/script.php?u=manojsharma123"></script> <br/><a style="font-size:12" href="http://www.freelogs.com/" target="_top">web counter code</a> </div> <div class='clear'></div> </div><div class='widget Profile' data-version='1' id='Profile1'> <h2>About Me</h2> <div class='widget-content'> <dl class='profile-datablock'> <dt class='profile-data'> <a class='profile-name-link g-profile' href='https://www.blogger.com/profile/10032995026597187555' rel='author' style='background-image: url(//www.blogger.com/img/logo-16.png);'> Manoj Sharma Technology is a Boom---- </a> </dt> <dd class='profile-textblock'>Hi I am a Software Developer in .net Technologies.I love coding and implementing new concepts.</dd> </dl> <a class='profile-link' href='https://www.blogger.com/profile/10032995026597187555' rel='author'>View my complete profile</a> <div class='clear'></div> </div> </div><div class='widget Feed' data-version='1' id='Feed2'> <h2>Cricinfo Live Scores</h2> <div class='widget-content' id='Feed2_feedItemListDisplay'> <span style='filter: alpha(25); opacity: 0.25;'> <a href='http://static.cricinfo.com/rss/livescores.xml'>Loading...</a> </span> </div> <div class='clear'></div> </div><div class='widget BlogArchive' data-version='1' id='BlogArchive1'> <h2>Blog Archive</h2> <div class='widget-content'> <div id='ArchiveList'> <div id='BlogArchive1_ArchiveList'> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2010/'> 2010 </a> <span class='post-count' dir='ltr'>(22)</span> <ul class='hierarchy'> <li class='archivedate expanded'> <a class='toggle' href='javascript:void(0)'> <span class='zippy toggle-open'> ▼  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2010/02/'> February </a> <span class='post-count' dir='ltr'>(21)</span> <ul class='posts'> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/cursors-in-sql-server-basics.html'>Cursors in Sql server-Basics</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/export-gridview-data-to-excel-sheet.html'>Export Gridview data to an Excel sheet</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/reading-xml-file-basics.html'>Reading a xml file-Basics</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/paging-in-datalist-or-repeater-control.html'>Paging in a DataList or Repeater control</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/binding-data-with-treeview-control.html'>Binding Data With ‘TreeView’ Control</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/displaying-xml-with-xslt.html'>displaying xml with xslt</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/xml-tree-example.html'>xml tree example</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/javascript-regular-expression-object.html'>Javascript Regular Expression object</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/javascript-to-create-clock.html'>javascript to create clock.</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/sql-table-relations-primary-and-foreign.html'>SQL Table Relations, Primary and Foreign Keys, and...</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/using-stringbuilder-in-net.html'>Using StringBuilder in .NET</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/introducing-linq-languageintegrated.html'>Introducing LINQ: Language‐Integrated Query</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/how-to-bind-gridview-control-to-xml-in.html'>How to Bind a GridView Control to XML in ASP.NET</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/autocomplete-textbox.html'>AutoComplete TextBox</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/sending-and-playing-microphone-audio.html'>Sending and playing microphone audio over network</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/loading-image-files-from-database-using.html'>Loading image files from a database, using ADO</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/sql-bulk-copy-with-c-net.html'>Sql bulk copy with c# .net</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/google-earth-network-link.html'>Google Earth network link</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/integrate-webcam-with-net-application.html'>Integrate webcam with a .net application</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/secure-net-application.html'>Secure a .Net Application</a></li> <li><a href='http://manojpoojasharma.blogspot.com/2010/02/com-and-net-framework-building-complete.html'>COM+ and the .NET Framework Building a complete CO...</a></li> </ul> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2010/01/'> January </a> <span class='post-count' dir='ltr'>(1)</span> </li> </ul> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2009/'> 2009 </a> <span class='post-count' dir='ltr'>(4)</span> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2009/12/'> December </a> <span class='post-count' dir='ltr'>(2)</span> </li> </ul> <ul class='hierarchy'> <li class='archivedate collapsed'> <a class='toggle' href='javascript:void(0)'> <span class='zippy'> ►  </span> </a> <a class='post-count-link' href='http://manojpoojasharma.blogspot.com/2009/11/'> November </a> <span class='post-count' dir='ltr'>(2)</span> </li> </ul> </li> </ul> </div> </div> <div class='clear'></div> </div> </div><div class='widget BlogList' data-version='1' id='BlogList1'> <h2 class='title'>My Blog List</h2> <div class='widget-content'> <div class='blog-list-container' id='BlogList1_container'> <ul id='BlogList1_blogs'> <li style='display: block;'> <div class='blog-icon'> <img data-lateloadsrc='https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s-p4LZatzylEgIoDx0tB56xYkBvNnxu7Cl8BmUkD3YGv2Yh2EB_W1WyNdx0vbanA-I4bUFi1hn2REe_E6x9F7jCVN05xgGuZD-qUWRUJScXZc=s16-w16-h16' height='16' width='16'/> </div> <div class='blog-content'> <div class='blog-title'> <a href='http://bharatkushwaha.blogspot.com/' target='_blank'> Kushwaha Rocks</a> </div> <div class='item-content'> <span class='item-title'> <a href='http://bharatkushwaha.blogspot.com/2015/03/blog-post_23.html' target='_blank'> प्रश्नोत्तरी ( मानव और राष्ट्र इतिहास विषय ) </a> </span> <div class='item-time'> 9 years ago </div> </div> </div> <div style='clear: both;'></div> </li> <li style='display: block;'> <div class='blog-icon'> <img data-lateloadsrc='https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vgaDjrkM1pDKtxuSw6G8Tuaj_A-MV-JqaAdXjYHCO_SE5mi2vCUFKXCP41wWBfJRNH365Wm5_fDwETOcXzoA_5CtwVIj9bNNWaYQRT9Q=s16-w16-h16' height='16' width='16'/> </div> <div class='blog-content'> <div class='blog-title'> <a href='http://mastpiyush.blogspot.com/' target='_blank'> Software Engineer</a> </div> <div class='item-content'> <span class='item-title'> <a href='http://mastpiyush.blogspot.com/2014/12/convert-html-to-plain-text.html' target='_blank'> Convert HTML to Plain Text </a> </span> <div class='item-time'> 9 years ago </div> </div> </div> <div style='clear: both;'></div> </li> <li style='display: block;'> <div class='blog-icon'> <img data-lateloadsrc='https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_t1GAORAINXU_GkSn_eq_WLCllJNUwfpDbkgOEaOMzRZOReUufQ062fti_xbLg9run0yqyJTwD156DPu-qA2xVDFae1LghvHdxxAw=s16-w16-h16' height='16' width='16'/> </div> <div class='blog-content'> <div class='blog-title'> <a href='http://www.indiatechjob.com/' target='_blank'> IT & Engineering Jobs in India</a> </div> <div class='item-content'> <span class='item-title'> <a href='http://www.indiatechjob.com/2014/10/infosys-is-hiring-freshers-for-role-of.html' target='_blank'> Infosys is hiring freshers for the role of Systems Engineer : Last Date 13th Oct 2014 </a> </span> <div class='item-time'> 9 years ago </div> </div> </div> <div style='clear: both;'></div> </li> <li style='display: block;'> <div class='blog-icon'> <img data-lateloadsrc='https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uRpej4HswLj5SP-aT4RPFR4Ub5R6w-c2ZOAfz4BGIqdFErKrAdcDqrttYF1v5p-hfOy4gY8IhgyozfzoGBaJ1-NrGwwC-dJ55h52c95rwI4B_ctsxjZmbJdA=s16-w16-h16' height='16' width='16'/> </div> <div class='blog-content'> <div class='blog-title'> <a href='http://dotnetdevelopersheaven.blogspot.com/' target='_blank'> DotNet Developers Heaven</a> </div> <div class='item-content'> <span class='item-title'> <a href='http://dotnetdevelopersheaven.blogspot.com/2014/06/password-encryption-code.html' target='_blank'> Password Encryption Code </a> </span> <div class='item-time'> 9 years ago </div> </div> </div> <div style='clear: both;'></div> </li> </ul> <div class='clear'></div> </div> </div> </div><div class='widget Feed' data-version='1' id='Feed3'> <h2>Photos</h2> <div class='widget-content' id='Feed3_feedItemListDisplay'> <span style='filter: alpha(25); opacity: 0.25;'> <a href='http://indiatoday.intoday.in/site/rssPhoto.jsp?secId=5&feed=Photos'>Loading...</a> </span> </div> <div class='clear'></div> </div><div class='widget Poll' data-version='1' id='Poll1'> <h2 class='title'>Males are more good at work than females </h2> <div class='widget-content'> <iframe allowtransparency='true' frameborder='0' height='140' name='poll-widget-6943760567809095626' style='border:none; width:100%;'></iframe> <div class='clear'></div> </div> </div></div> </div> <!-- spacer for skins that want sidebar and main to be the same height--> <div class='clear'> </div> </div> <!-- end content-wrapper --> <div id='footer-wrapper'> <div class='footer no-items section' id='footer'></div> </div> </div></div> <!-- end outer-wrapper --> <script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/1807328581-widgets.js"></script> <script type='text/javascript'> window['__wavt'] = 'AOuZoY6UK3wGWCj4nInn6X4WJ-rWaJ__uw:1714339439308';_WidgetManager._Init('//www.blogger.com/rearrange?blogID\x3d8769773808837040573','//manojpoojasharma.blogspot.com/2010/02/','8769773808837040573'); _WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '8769773808837040573', 'title': '.Net C# SqlServer Javascript Ajax! Thats something abt me!', 'url': 'http://manojpoojasharma.blogspot.com/2010/02/', 'canonicalUrl': 'http://manojpoojasharma.blogspot.com/2010/02/', 'homepageUrl': 'http://manojpoojasharma.blogspot.com/', 'searchUrl': 'http://manojpoojasharma.blogspot.com/search', 'canonicalHomepageUrl': 'http://manojpoojasharma.blogspot.com/', 'blogspotFaviconUrl': 'http://manojpoojasharma.blogspot.com/favicon.ico', 'bloggerUrl': 'https://www.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'en-US', 'localeUnderscoreDelimited': 'en', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': false, 'isMobileRequest': false, 'mobileClass': '', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22.Net C# SqlServer Javascript Ajax! Thats something abt me! - Atom\x22 href\x3d\x22http://manojpoojasharma.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22.Net C# SqlServer Javascript Ajax! Thats something abt me! - RSS\x22 href\x3d\x22http://manojpoojasharma.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22.Net C# SqlServer Javascript Ajax! Thats something abt me! - Atom\x22 href\x3d\x22https://www.blogger.com/feeds/8769773808837040573/posts/default\x22 /\x3e\n', 'meTag': '', 'adsenseClientId': 'ca-pub-1748691594509619', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': false, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/16e657cb9c57b8a2', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': 'Get link', 'key': 'link', 'shareMessage': 'Get link', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Share to Facebook', 'target': 'facebook'}, {'name': 'BlogThis!', 'key': 'blogThis', 'shareMessage': 'BlogThis!', 'target': 'blog'}, {'name': 'Twitter', 'key': 'twitter', 'shareMessage': 'Share to Twitter', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Share to Pinterest', 'target': 'pinterest'}, {'name': 'Email', 'key': 'email', 'shareMessage': 'Email', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27en\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': 'Read more', 'pageType': 'archive', 'pageName': 'February 2010', 'pageTitle': '.Net C# SqlServer Javascript Ajax! Thats something abt me!: February 2010'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': 'Edit', 'linkCopiedToClipboard': 'Link copied to clipboard!', 'ok': 'Ok', 'postLink': 'Post Link'}}, {'name': 'template', 'data': {'name': 'custom', 'localizedName': 'Custom', 'isResponsive': false, 'isAlternateRendering': false, 'isCustom': true}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': false, 'title': '.Net C# SqlServer Javascript Ajax! Thats something abt me!', 'description': '', 'url': 'http://manojpoojasharma.blogspot.com/2010/02/', 'type': 'feed', 'isSingleItem': false, 'isMultipleItems': true, 'isError': false, 'isPage': false, 'isPost': false, 'isHomepage': false, 'isArchive': true, 'isLabelSearch': false, 'archive': {'year': 2010, 'month': 2, 'rangeMessage': 'Showing posts from February, 2010'}}}]); _WidgetManager._RegisterWidget('_NavbarView', new _WidgetInfo('Navbar1', 'navbar', document.getElementById('Navbar1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'lightboxEnabled': true, 'lightboxModuleUrl': 'https://www.blogger.com/static/v1/jsbin/1666805145-lbx.js', 'lightboxCssUrl': 'https://www.blogger.com/static/v1/v-css/13464135-lightbox_bundle.css'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_FollowersView', new _WidgetInfo('Followers1', 'main', document.getElementById('Followers1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_FeedView', new _WidgetInfo('Feed1', 'sidebar', document.getElementById('Feed1'), {'title': 'Latest News', 'showItemDate': false, 'showItemAuthor': false, 'feedUrl': 'http://indiatoday.intoday.in/site/rssGenerator.jsp?secId\x3d4\x26feed\x3dLATEST%20NEWS', 'numItemsShow': 5, 'loadingMsg': 'Loading...', 'openLinksInNewWindow': false, 'useFeedWidgetServ': 'true'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_SubscribeView', new _WidgetInfo('Subscribe1', 'sidebar', document.getElementById('Subscribe1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HTMLView', new _WidgetInfo('HTML2', 'sidebar', document.getElementById('HTML2'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_ImageView', new _WidgetInfo('Image1', 'sidebar', document.getElementById('Image1'), {'resize': false}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HTMLView', new _WidgetInfo('HTML1', 'sidebar', document.getElementById('HTML1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_ProfileView', new _WidgetInfo('Profile1', 'sidebar', document.getElementById('Profile1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_FeedView', new _WidgetInfo('Feed2', 'sidebar', document.getElementById('Feed2'), {'title': 'Cricinfo Live Scores', 'showItemDate': false, 'showItemAuthor': false, 'feedUrl': 'http://static.cricinfo.com/rss/livescores.xml', 'numItemsShow': 5, 'loadingMsg': 'Loading...', 'openLinksInNewWindow': false, 'useFeedWidgetServ': 'true'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'sidebar', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': 'Loading\x26hellip;'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogListView', new _WidgetInfo('BlogList1', 'sidebar', document.getElementById('BlogList1'), {'numItemsToShow': 0, 'totalItems': 4}, 'displayModeFull')); _WidgetManager._RegisterWidget('_FeedView', new _WidgetInfo('Feed3', 'sidebar', document.getElementById('Feed3'), {'title': 'Photos', 'showItemDate': false, 'showItemAuthor': false, 'feedUrl': 'http://indiatoday.intoday.in/site/rssPhoto.jsp?secId\x3d5\x26feed\x3dPhotos', 'numItemsShow': 5, 'loadingMsg': 'Loading...', 'openLinksInNewWindow': false, 'useFeedWidgetServ': 'true'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_PollView', new _WidgetInfo('Poll1', 'sidebar', document.getElementById('Poll1'), {'pollid': '-6943760567809095626', 'iframeurl': '/b/poll-results?pollWidget\x3dPoll1\x26txtclr\x3d%23666666\x26lnkclr\x3d%235588aa\x26chrtclr\x3d%235588aa\x26font\x3dnormal+normal+100%25+Georgia,+Serif\x26hideq\x3dtrue\x26purl\x3dhttp://manojpoojasharma.blogspot.com/'}, 'displayModeFull')); </script> </body> </html>