<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Amit Gupta's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/amitgupta/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/amitgupta/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:14:18 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Creating Complext Charts Using Sharepoint 2010 OOB Capabilities</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/creating-complext-charts-using-sharepoint-2010-oob-capabilities</link>
      <pubDate>Mon, 14 May 2012 01:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2012/05/14/creating-complext-charts-using-sharepoint-2010-oob-capabilities/</guid>
      <description><![CDATA[Hi Guys,
Our Business Leaders take lot of decisions based on charts and graphs trends.One of our...]]></description>
      <content:encoded><![CDATA[<p>Hi Guys,</p>
<p>Our Business Leaders take lot of decisions based on charts and graphs trends.One of our client had a requirement to create chart in their dashboard page without using any kind of coding. we explored the ways in which we can create Charts in SharePoint 2010. After doing a quite good amount of research on Charts in Sharepoint, we came to know there could be 2 ways to show data in charts in sharepoint 2010:</p>
<p>1. PPS(Performance Point Service)<br />2. Chart webpart.</p>
<p>PerformancePoint Services in Microsoft SharePoint Server 2010 is a performance management service that you can use to monitor and analyze your business. By providing flexible, easy-to-use tools for building dashboards, scorecards, reports, and key performance indicators (KPIs), PerformancePoint Services can help everyone across an organization make informed business decisions that align with companywide objectives and strategy. Initially we thought PPS would be the perfect candidate for our requirement as it has lot of capablities it in for Dashboard,Scorecards and Kpi.But as our main requirement was to create chart webpart from sharepoint list and PPS has a limitation that we can only create charts on 3- dimensional object like Cube in SQL Server or Excel. so we had to move from PPS to Sharepoint OOB Chart webparts.</p>
<p>Chart Webpart gives us ways to create our Charts on top of List. Below can be the sources for Chart WebPart:<br /><br />1. WebPart<br />2. List<br />3. BDC<br />4. Excel Services<br /><br />There are lot of styling we can do with Chart Webparts along with&nbsp;Filtering of Data&nbsp; and Grouping by some field. But SharePoint doesn't provide OOB agreegate functions to&nbsp; Show data. But in the pratical senario's we would be more interested in showing agreegated data in Chart WebPart.If Chart WebPart doesn't provide way to agreegate data then in that case how will we show agreegated data using OOB Chart WebPart. I would be taking 2 examples that will show the way to implement complex charts using Sharepoint OOB WebParts.</p>
<p>&nbsp;</p>
<p>Example 1:</p>
<p>we have a project list&nbsp;which will show details about the project like Project Name, Project Status, Country, Department e.tc. User is interested in looking at number of project by status. something like the chart in below fig:&nbsp;</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/5076.Project%20Chart.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/5076.Project-Chart.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/5076.Project%20Chart.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/5076.Project-Chart.png" /></a></p>
<p>Follow the below steps to implement the above chart using OOB sharepoint Chart WebPart:</p>
<p>1. Create a list which will have master data of status-ProjectMaster.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3051.Projectmaster1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3051.Projectmaster1.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3051.Projectmaster1.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3051.Projectmaster1.png" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0083.Projectmaster.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0083.Projectmaster.png"></a></p>
<p>&nbsp;</p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">2. Create a ProjectList wihich will have all project related columns, also it will have one column with the name project status which will be lookup column from ProjectMaster Title Column.<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6763.Projectlist.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6763.Projectlist.jpg"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6763.Projectlist.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6763.Projectlist.jpg" /></a><o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"></span>&nbsp;</p>
<p></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">3.Create Column in ProjectMaster list which will be Lookup column from ProjectList's Project Status column like the fig shown below:<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3362.lookup.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3362.lookup.jpg"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3362.lookup.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3362.lookup.jpg" /></a></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">4. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Once this column is created in Projectmaster Table, this column will return the number of project in each status.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/2818.Projectmaster.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/2818.Projectmaster.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/2818.Projectmaster.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/2818.Projectmaster.png" /></a></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">5. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Now we will just configure Chart WebPart for ProjectMaster table. we will configure Title on the X-axis and Project Status Count on Y-axis.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"></span>&nbsp;</p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/2451.Chart1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/2451.Chart1.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/2451.Chart1.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/2451.Chart1.png" /></a></span></p>
<p></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">This Example was pretty easy to implement but not always we will get the simple senario's like the above one, so let's take little complex senario now.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Example 2:</span></p>
<p>In the same Project List, we would be adding one more column "Assign To" which will show the Project Assignee Name. Now we need show graph which will show the number of project which are assigned and which are not assigned.<br />this senario can't be implemented in the previous appraoch was as user who is creating or editing project will assign/Unassign project but hewon't be mentioning category for project like Assigned or UnAssigned. In these kind of senarios we need to populate our master list using SPD workFlow. Please follow the below steps to create graph like below :</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/5127.AssignedGraph.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/5127.AssignedGraph.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/5127.AssignedGraph.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/5127.AssignedGraph.png" width="334" height="290" /></a></p>
<p><br />1. Create a list which will have master data of status-ProjectResources.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/1731.ProjectResources.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/1731.ProjectResources.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/1731.ProjectResources.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/1731.ProjectResources.png" width="464" height="336" /></a></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">2. Create a ProjectList which will have all project related columns, also it will have one column with the name </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">AssignedUnAssigned</span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"> which will be lookup column from ProjectResources Title Column.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/2402.Projectlist.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/2402.Projectlist.jpg"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0172.ProjectList.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0172.ProjectList.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0172.ProjectList.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0172.ProjectList.png" /></a></span></p>
<p>&nbsp;</p>
<p>3. Create Column in ProjectResources List&nbsp; ResourceCount which will be lookup column from ProjectList's&nbsp;AssignedUnAssigned, the way we did it in previous example.</p>
<p>4. Create a SPD WorkFlow which will populate data in AssignedUnAssigned column of ProjectList. This workFlow will get triggered on Creation/Editing of ProjectList items. The workFlow will look like below:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0841.WF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0841.WF.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0841.WF.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0841.WF.png" /></a></p>
<p>5. Once this WF is attached to the ProjectList, it will populate data in AssignedUnAssigned field and which intern will populate data in ProjectResources ResourceCount.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/8400.ResourceCount.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/8400.ResourceCount.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/8400.ResourceCount.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/8400.ResourceCount.png" /></a></p>
<p>6. <span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Now we will just configure Chart WebPart for ProjectResources List. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">we will configure Title on the X-axis and </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">ResourceCount </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">on Y-axis.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">These ways we can create nice graphs on Sharepoint List without Using Single Line of code. Hope this will help you in creating Graphs.</span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Thanks :-)</span></p>
<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Access XML data using LINQ to XML</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/access-xml-data-using-linq-to-xml</link>
      <pubDate>Mon, 07 May 2012 10:19:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2012/05/07/access-xml-data-using-linq-to-xml/</guid>
      <description><![CDATA[Hi Friends,
Today we would be learning the way to read complex XML data using LINQ to XML, which...]]></description>
      <content:encoded><![CDATA[<p>Hi Friends,</p>
<p>Today we would be learning the way to read complex XML data using LINQ to XML, which would include 2 examples:</p>
<p>1. Reading XML data without namespaces.<br />2. Reading XML data with namespaces.<br /><br />In real life , we would be dealing with both of the above senarios very frequently. There are lot of approaches to read XML document, it could be XMLPathNavigator, XMLDocument etc-2. we would be taking the simplest approach to read XML document through LINQ.</p>
<p><span style="font-size: large;"><strong>Reading XML data without Namespaces</strong></span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Below is a complex xml document which contains nodes at n level,&nbsp; we need to read this document&nbsp; to fetch the City,Temperature and Image from it.</p>
<p><span style="font-size: large;"><strong><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0550.Untitled.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0550.Untitled.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0317.Untitled.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0317.Untitled.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0317.Untitled.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0317.Untitled.png" /></a></strong></span></p>
<p>To go to&nbsp;Element at n level, we will use Element("X").Element("Y")... and to fetch&nbsp;attribute value of some element we will write Element("X").Attribute("Y").Value.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XDocument doc = XDocument.Load(reader); //Creating the XDocument object and instantiating it with Xml file data.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var lv1s = (from lv1 in doc.Descendants("weather") //Weather is a node under which we need to&nbsp;fetch descendants.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select new<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; City = lv1.Element("forecast_information").Element("city").Attribute("data").Value,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TempC = lv1.Element("current_conditions").Element("temp_c").Attribute("data").Value,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageUrl = lv1.Element("current_conditions").Element("icon").Attribute("data").Value,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).ToList();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var v in lv1s)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Consolte.WriteLine("{0} {1} {2}", v.City, v.TempC, v.ImageUrl);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>above code will work perfectly, if our xml doesn't have any kind of namespaces. But in many senarios we&nbsp; will have to query xml which will have namespaces even.</p>
<p>&nbsp;</p>
<p><span style="font-size: large;"><strong>Reading XML data with Namespaces</strong></span></p>
<p><span style="font-size: large;"><strong></strong></span>&nbsp;</p>
<p><span style="font-size: small;">Below xml is having lot of namespaces in it. to access any node in the xml document with namespace, we need to prefix the node with namespace.</span></p>
<p><span style="font-size: large;"><strong></strong></span>&nbsp;</p>
<p><span style="font-size: large;"><strong><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6404.Untitled.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6404.Untitled.png"></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3771.Untitled.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3771.Untitled.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3771.Untitled.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3771.Untitled.png" /></a></strong></span></p>
<p><span style="font-size: small;">//creatinng variables for XmlNameSpace which we would be using to access different nodes.</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XNamespace y = "<a href="http://xml.weather.yahoo.com/ns/rss/1.0">http://xml.weather.yahoo.com/ns/rss/1.0</a>";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XNamespace z = "<a href="http://www.w3.org/2003/01/geo/wgs84_pos">http://www.w3.org/2003/01/geo/wgs84_pos</a>#";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XNamespace x = "<a href="http://where.yahooapis.com/v1/schema.rng">http://where.yahooapis.com/v1/schema.rng</a>";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XNamespace p = "<a href="http://www.yahooapis.com/v1/base.rng">http://www.yahooapis.com/v1/base.rng</a>";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var lv1s = (from lv1 in doc.Descendants("query")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select new<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; City = lv1.Element("results").Element(x + "weather").Element(x+ "rss").Element(x + "channel").Element(x+"title").Value.Split('-')[1],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TempC = lv1.Element("results").Element(x + "weather").Element(x+ "rss").Element(x + "channel").Element(x+"item").Element(y+"condition").Attribute("temp").Value,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageUrl =&nbsp; lv1.Element("results").Element(x + "weather").Element(x+ "rss").Element(x + "channel").Element(x+"item").Element(y+"condition").Attribute("code").Value + ".jpg",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).ToList();</p>
<p></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var v in lv1s)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Consolte.WriteLine("{0} {1} {2}", v.City, v.TempC, v.ImageUrl);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;</p>
<p>So, these are the ways to access xml data with namespace and without namespace.</p>
<p>&nbsp;</p>
<p>Happy Coding :-)</p>
<p>&nbsp;</p>
<p></p>]]></content:encoded>
    </item>
    <item>
      <title>Creating Bulk Users in Active Directory Using PowerShell</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/creating-bulk-users-in-active-directory-using-powershell</link>
      <pubDate>Mon, 06 Feb 2012 07:18:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2012/02/06/creating-bulk-users-in-active-directory-using-powershell/</guid>
      <description><![CDATA[We had a requirement of creating bulk users in Active directory for Test users. Initially i thought...]]></description>
      <content:encoded><![CDATA[<p>We had a requirement of creating bulk users in Active directory for Test users. Initially i thought of wrtting .NET code which will communicate to LDAP and creates the users. <br />but i was not aware of that it can be done very-2 quickly using the Powershell with 3-4 line of scripts.</p>
<p>we had a csv file which had all the users with AD information in it. The Format of that csv is some thing like the below one:</p>
<p>Please change the<span style="background-color: #ffff00;"> {Domain Name}</span> with your Environment Domain name.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6431.Untitled.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6431.Untitled.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6431.Untitled.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6431.Untitled.png" /></a></p>
<p>Below is powershell script which will create users in Active directory, please ensure to run this powershell script in "Active Directory Module For Windows PowerShell".<br />UserCreationfile.csv is a csv filename which has all users information.</p>
<p>Import-Csv .\<span style="background-color: #ffff00;">usercreationfile.csv</span> | foreach-object { <br />$userprinicpalname = $_.SamAccountName + "@{<span style="background-color: #ffff00;">domainname</span>}.com" <br />New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.cn -SurName $_.sn -Department $_.Department -Path "CN=Users,DC=biogen,DC=com" -AccountPassword (ConvertTo-SecureString "Microsoft~1;" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru }</p>
<p>Once we Execute above powershell statements, we will see the results like the below:</p>
<p></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6332.Untitled123.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6332.Untitled123.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/6332.Untitled123.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/6332.Untitled123.png" /></a></p>
<p>Hope this will help.</p>
<p>Happy Coding !!!</p>
<p><br />&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Calling Jscript function with parameters from XSLT</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/calling-jscript-function-with-parameters-from-xslt</link>
      <pubDate>Thu, 22 Sep 2011 10:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2011/09/22/calling-jscript-function-with-parameters-from-xslt/</guid>
      <description><![CDATA[Last week it took hours for me to Bing on how to call JavaScript with parameters from xslt. So I...]]></description>
      <content:encoded><![CDATA[<p>Last week it took hours for me to Bing on how to call JavaScript with parameters from xslt. So I thought of keeping it on blog to help people who are interested in doing same kind of thing.</p>
<p>Now a day&rsquo;s xslt is being used heavily to render XML.Here in this blog I have demonstrated the below things: <br />1. How to apply xslt on xml data.<br />2. How to call JavaScript functions with parameter from xslt.</p>
<p><br />I have create a very simple solution having 2 aspx pages, one will be treated as default page and other will be the popup page which will get called on clicking hyperlink on default.aspx page.</p>
<p>The html body of default page will look like the below one, we have one JavaScript function which open the popup window.</p>
<p>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />&lt;head runat="server"&gt;<br />&lt;script language="javascript" type="text/javascript"&gt;<br /><span style="background-color: #ffff00;">function ShowDialog(PageUrlWithQueryString) {</span><br /><span style="background-color: #ffff00;">window.open(PageUrlWithQueryString, null, "height=200,width=300,status=yes");</span> <br />}<br />&lt;/script&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&lt;form id="form1" runat="server"&gt;<br />&lt;div&gt;<br />&lt;/div&gt;<br />&lt;/form&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>
<p>The Xml data File that we used for demo is something like this, it's having 2 Elements for each Employee one is Title and other is Description:</p>
<p>&lt;?xml version="1.0" encoding="utf-8" ?&gt;<br />&lt;EmployeeFeedback&gt;<br />&lt;Employee&gt;<br />&lt;Title&gt;Amit&lt;/Title&gt;<br />&lt;Description&gt;He is Awesome&lt;/Description&gt; <br />&lt;/Employee&gt;<br />&lt;Employee&gt;<br />&lt;Title&gt;Sumit&lt;/Title&gt;<br />&lt;Description&gt;He is Ok&lt;/Description&gt;<br />&lt;/Employee&gt;<br />&lt;Employee&gt;<br />&lt;Title&gt;Namit&lt;/Title&gt;<br />&lt;Description&gt;He is Good&lt;/Description&gt;<br />&lt;/Employee&gt;<br />&lt;Employee&gt;<br />&lt;Title&gt;Zamit&lt;/Title&gt;<br />&lt;Description&gt;He is Awefull&lt;/Description&gt;<br />&lt;/Employee&gt;<br />&lt;/EmployeeFeedback&gt;</p>
<p><br />This is how the xslt would look like; anchor tag is bind with the Title Element of the xml data. We have defined the "onlclick" attribute for anchor tag, so on clicking of anchor tag the JavaScript will get called. Within the JavaScript function we are passing Description Element from the xml data.</p>
<p>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;<br />&lt;!-- Edited by XMLSpy&reg; --&gt;<br />&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;<br />&lt;xsl:template match="/"&gt;<br />&lt;xsl:for-each select="EmployeeFeedback/Employee"&gt;<br />&lt;a href="#"&gt;<br />&lt;xsl:attribute name="onclick"&gt;<br />javascript:ShowDialog('http://localhost:6742/TestXSLTJavascript/Description.aspx?itemId= &lt;xsl:value-of select="Description"&gt;&lt;/xsl:value-of&gt;')<br />&lt;/xsl:attribute&gt;<br />&lt;xsl:value-of select="Title"&gt;&lt;/xsl:value-of&gt;<br />&lt;br/&gt;<br />&lt;/a&gt; <br />&lt;/xsl:for-each&gt;<br />&lt;/xsl:template&gt;<br />&lt;/xsl:stylesheet&gt;</p>
<p>Within page load function, we are building the string from the xml data; there can be other ways to do it but I chose whatever was there in mind. We are calling XSLTTransformation function which will take xml string as input and apply the xslt transformation that we defined previously on the xml and returns the html output.</p>
<p>public partial class _Default : System.Web.UI.Page<br />{<br />protected void Page_Load(object sender, EventArgs e)<br />{<br />DataSet ds= new DataSet();<br />ds.ReadXml(@<a href="http://localhost:6742/TestXSLTJavascript/Data.xml">http://localhost:6742/TestXSLTJavascript/Data.xml</a>);<br />string response= XSLTTransformation(ds.GetXml().ToString(), "<a href="http://localhost:6742/TestXSLTJavascript/RssFeedTransform.xslt">http://localhost:6742/TestXSLTJavascript/RssFeedTransform.xslt</a>");<br />Response.Write(response);<br />}</p>
<p>/// &lt;summary&gt;<br />/// XSLTs transformation the given XML.<br />/// &lt;/summary&gt;<br />/// &lt;param name="xml"&gt;Xml to be transformed.&lt;/param&gt;<br />/// &lt;param name="xsltPath"&gt;The XSLT path.&lt;/param&gt;<br />/// &lt;returns&gt;The transformed string&lt;/returns&gt;<br />public static string XSLTTransformation(string xml, string xsltPath)<br />{<br />StringBuilder sb = new StringBuilder();<br />XmlTextReader readerStyleSheet;<br />XmlReader reader;<br />StringReader strReader = null;<br />using (readerStyleSheet = new XmlTextReader(xsltPath))<br />{<br />using (strReader = new StringReader(xml))<br />{<br />reader = XmlReader.Create(strReader);<br />XmlUrlResolver resolver = new XmlUrlResolver();<br />resolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;<br />readerStyleSheet.XmlResolver = resolver;<br />XslCompiledTransform transform = new XslCompiledTransform();<br />transform.Load(readerStyleSheet);<br />using (TextWriter writer = new StringWriter(sb))<br />{<br />XmlTextWriter results = new XmlTextWriter(writer);<br />transform.Transform(reader, results);<br />}<br />}<br />}<br />return sb.ToString();<br />}</p>
<p>On description.aspx page, we can access the query string like the below:</p>
<p>string str= Request.QueryString["ItemId"].ToString();<br />Response.Write(str);</p>
<p>Happy coding :-)</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/21/54/07/TestXSLTJavascript.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-21-54-07/TestXSLTJavascript.zip">TestXSLTJavascript.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Effective Use of AJAX and Threading while Creating ASP.NET controls</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/effective-use-of-ajax-and-threading-while-creating-asp-net-controls</link>
      <pubDate>Tue, 06 Sep 2011 23:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2011/09/06/effective-use-of-ajax-and-threading-while-creating-asp-net-controls/</guid>
      <description><![CDATA[EffectiveUse of AJAX and Threading while Creating ASP.NET controls
Despiteof having excellent...]]></description>
      <content:encoded><![CDATA[<p><b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Effective<br />Use of AJAX and Threading while Creating ASP.NET controls</span></b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Despite<br />of having excellent resources for parallel programming, we as a legacy programmer are used to of writing single treaded application which is not using our Multi core processors machines.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Some days back, I was writing a RSS Feed User Control which had to feed updates from multiple sites. As the client&rsquo;s main concern was performance with his existing application so we had to make this control keeping performance at first<br />priority.<o:p></o:p></span></p>
<p><b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Problem Statement:</span></b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"> we have to create a control which would show feeds from multiple urls. But initially when the user goes to the page he would be able to see only top 10 feeds, when user clicks on view more we have to make<br />AJAX request to append next top 10 results in the panel. This Control will have dropdown which will have Feed Titles of the feed when user changes dropdown value; again it should be an Ajax call to show top 10 updates from that feed. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">From<br />the Web Request point of view, we used AJAX for making light server calls. We can use AJAX in .NET web applications through 3 ways.<br /><br />1. Using inbuilt Update Panels controls- It&rsquo;s very easy to implement AJAX using update panel control but when we use it, it will call full page life cycle for each Ajax request which would be a costly operations so we dropped out this option.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">2.Using JQuery Ajax functions- This approach seems to be better than the previous approach but while using AJAX with Jquery, Jquery internally calls some function which makes it little less efficient.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">3.Using XmlHttp Request- XMLHttp requests are the base of AJAX, so if we go with this approach we can create ajax request of our own. This provides us more control over the prior methods and performance wise also this is best approach<br />for ajax calls.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">we went with 3rd approach keeping performance in mind.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Html of the running code is attached as a attachment with this post.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">whenever user clicks on view more link or select something from dropdown, we are making a xmlhttp request which send the request to AjaxRequestPage.aspx to get the updates based on filter criteria from dropdown. In case when user<br />clicks on view more option, we are appending the new string returned by AJAXRequestpage to div.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Below is a code to make an AJAX call using xmlHttpRequest object. request.ResponseText will have the complete data that we can show anywhere in the browser.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><br />var request = new XMLHttpRequest(); <br /><br />request.open('GET', 'http://www.bing.com/', true); <br /><br />request.onreadystatechange = function (aEvt) { <br /><br />if (request.readyState == 4) { <br /><br />if(request.status == 200) <br /><br />console.log(request.responseText) <br /><br />else <br /><br />console.log('Error', request.statusText); <br /><br />} <br /><br />}; <br /><br />req.send(null);<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><o:p>&nbsp;</o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">the AJAXRequestPage will handle the ajax request and will intern call the method which will returns the string that needs to be append to the div.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"><o:p>&nbsp;</o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">While XML Http Requests take care of making Asynchronous server calls but within each server request we should be able to use multi core processors to get the results very fast as our requirement was to get updates from multiple url feeds.<br />we ahve used C#.NET Threading classes to get updates from multiple feed in multithreading environment.Before starting on coding portion, it would be good to understand the Class the we used for handling threads in multi threaded environment.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">ManualResetEvent Class :<o:p></o:p></span></p>
<p><b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">ManualResetEvent</span></b><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;"> allows threads to communicate with each other by signalling. Typically, this communication concerns a task which one thread must complete before other threads can proceed. When a thread begins an activity that must complete before other threads proceed, it calls <a href="http://msdn.microsoft.com/en-us/library/aa332334(v=vs.71).aspx">Reset</a>&nbsp;to put <b>ManualResetEvent</b> in the nonsignaled state. This thread can be thought of as controlling the <b>ManualResetEvent</b>. Threads that call <a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.waitone(v=vs.71).aspx">WaitOne</a>&nbsp;on the <b>ManualResetEvent</b> will block, awaiting the signal. When the controlling thread completes the activity, it calls <a href="http://msdn.microsoft.com/en-us/library/aa332335(v=vs.71).aspx">Set</a>&nbsp;to signal that the waiting threads can proceed. All waiting threads are released.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Once it has been signaled, <b>ManualResetEvent</b> remains signalled until it is manually reset. That is, calls to <b>WaitOne</b> return immediately.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">You can control the initial state of a <b>ManualResetEvent </b>by passing a Boolean value to the constructor, <b>true</b> if the initial state is signalled and <b>false </b>otherwise. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Below statement will process each url that user has subscribed for and then assign<br />separate threads to execute LoadT function. After executing this loop the value of activeThreads variable will be equal to number of urls we are feeding.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">ManualResetEvent<br />isDone = new ManualResetEvent(false);// parameter value false means it is in<br />reset state(=&gt; thread will wait at waitone statement)<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">foreach<br />(var url in GetUrls())<br /><br />{<br /><br />ThreadPool.QueueUserWorkItem(this.LoadT, url);<br /><br />this.activeThreads++;<br /><br />}<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">the below statements will create one more thread which will execute FinishWork function and Main thread will wait till the time some of the running thread calls the isDone(ManualRestEvent) to set state.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">ThreadPool.QueueUserWorkItem(this.FinishWork);<br /><br />this.isDone.WaitOne(10000); //Main thread will wait here till the time any of<br />the running thread change the state to set state.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">LoadT Method will be called by Multiple thread and each thread will decrement the value of activeThreads.Once the value of activeThreads reachces 0, FinishWork method which is also executing will set the ManualResetEvent evnt and after<br />that </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">main thread will resume from waitone statement and do rest of task. </span><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">The reason behind using waitone statement in this example was all the Threads executing LoadT are trying to modify shared variable and Main thread will wait on waitone<br />till the time that shared variable is updated by all the threads. Here in RSS feed webpart we are Adding data in List and once list get data from all the thread main thread will resume from waitone and execute the rendering logic for RSS feed control.<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">private<br />void LoadT()<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">{<br /><br />//Process RSS Feeds here<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">this.activeThreads<br />--;<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">}<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">private<br />void FinishWork(object o)<br /><br />{<br /><br />while (this.activeThreads &gt; 0)<br /><br />{<br /><br />}<o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">this.isDone.Set();<br /><br />} <o:p></o:p></span></p>
<p><span style="color: black; font-family: 'Arial','sans-serif'; font-size: 9pt;">Here<br />is how the User control looks like:<o:p></o:p></span></p>
<p></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/4666.screen2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/4666.screen2.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/4666.screen2.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/300x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/4666.screen2.png" /></a></p>
<p>&nbsp;Full code for the implementation of RSSFeed Usercontrol is there in attachement.let me know in case of any further confusions.</p>
<p>Happy Coding :-)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>calling unmanaged code from  c-sharp</title>
      <link>https://docs.microsoft.com/archive/blogs/amitgupta/calling-unmanaged-code-from-c-sharp</link>
      <pubDate>Thu, 28 Jul 2011 04:54:00 GMT</pubDate>
      <dc:creator><![CDATA[Amit Gupta Hyderabad]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/amitgupta/2011/07/28/calling-unmanaged-code-from-c-sharp/</guid>
      <description><![CDATA[There may be&nbsp;lot &nbsp;of situations in which we may need to call unmanaged code from our...]]></description>
      <content:encoded><![CDATA[<p>There may be&nbsp;lot &nbsp;of situations in which we may need to call unmanaged code from our managed code. Below are the some of the situations:</p>
<p>1. If customer doesn't want to convert his old(Vc++ apps) applications to new .net technologies but still he wants to make new applications in.net code, in that case his new applications will have to interact with unmanaged code.</p>
<p>2. some of the customers are still having sentiments in writing their calculation engine code in unmanaged code mainly C++ code due to performance reasons.</p>
<p>Below the are steps to consume VC++ dll in C#.NET code.</p>
<p>Step 1 :Create unmanaged Assembly(dll)</p>
<ul>
<li>Create a project using VC++ Win 32 Project template.</li>
</ul>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0724.create%20Project.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0724.create-Project.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0724.create%20Project.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0724.create-Project.png" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0523.create%20Project.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0523.create-Project.png"></a></p>
<p><br />once we provide the project name, it will open up the wizard which will look like below,please select DLL from Application type for creating DLL and also select Export Symbols if you would like to debug unmanaged code.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0027.Wizard.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0027.Wizard.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/0027.Wizard.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/0027.Wizard.png" /></a></p>
<p><br />once you finish with the wizard the project structure will look similar to the one below:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/8228.ProjectStructure.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/8228.ProjectStructure.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/8228.ProjectStructure.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/8228.ProjectStructure.png" /></a></p>
<p><br />&nbsp;</p>
<p>below is a code for the TestProject.cpp file, which will have 2 functions(one returning flot and one returning string) which can be consumed by any external application.</p>
<p><br />// TestProject.cpp : Defines the exported functions for the DLL application.<br />//</p>
<p></p>
<p>#include "stdafx.h"<br />#include "TestProject.h"</p>
<p></p>
<p>// This is an example of an exported variable<br />TESTPROJECT_API int nTestProject=0;</p>
<p></p>
<p>// This is an example of an exported function.<br />TESTPROJECT_API int fnTestProject(void)<br />{<br />&nbsp;return 42;<br />}</p>
<p></p>
<p>// This is the constructor of a class that has been exported.<br />// see TestProject.h for the class definition<br />CTestProject::CTestProject()<br />{<br />&nbsp;return;<br />}</p>
<p></p>
<p><span style="background-color: #ffff00;">// User Defined Functions starts Here</span><br /><span style="background-color: #ffff00;">extern "C" TESTPROJECT_API float fnMyWin32Function(float a,float b)</span><br /><span style="background-color: #ffff00;">{</span><br /><span style="background-color: #ffff00;">&nbsp;&nbsp;&nbsp; return a*b;</span><br /><span style="background-color: #ffff00;">}</span></p>
<p></p>
<p><span style="background-color: #ffff00;">extern "C" TESTPROJECT_API char* fnMyWin32Functionstr()</span><br /><span style="background-color: #ffff00;">{</span><br /><span style="background-color: #ffff00;">&nbsp;&nbsp;&nbsp; return "Test string";</span><br /><span style="background-color: #ffff00;">}</span></p>
<p></p>
<p>&nbsp;-----------------------------------------------------------------------------------------------------------------</p>
<p>Build the project, it will create the dll for you. till this point you are done with creating unmanaged assembly.</p>
<p>&nbsp;</p>
<p>Step 2: Consuming and Debugging Unmanaged Assembly in .NET Code.</p>
<p>Create any type of C#.NET Project(for this Article we have chosen Console Application).</p>
<p>Initially we have to defined the vc++ functions that we would be calling from C#.net code &nbsp; and also we have to decorate it with DllImport Attribute. the signature of the function will be .net specific but data type that we are mentioning here in C#.net code must be compatible with the one in vc++ code.</p>
<p>--------------------------------------------------------------------------------------------------------------</p>
<p>using System;<br />using System.Collections.Generic;<br />using System.Text;<br />using System.Runtime.InteropServices;</p>
<p>namespace ConsoleApplication5<br />{<br />&nbsp;&nbsp;&nbsp; class Program<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [DllImport("TestProject.dll")]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static extern Single fnMyWin32Function(Single a, Single b);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [DllImport("TestProject.dll")]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static extern string fnMyWin32Functionstr();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Single a = 10.0f;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Single b = 20.0f;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Single c = fnMyWin32Function(a, b);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string s = fnMyWin32Functionstr();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Console.WriteLine(c);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Console.WriteLine(s);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Console.ReadLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; }<br />}</p>
<p>&nbsp;</p>
<p>--------------------------------------------------------------------------------------------------------------</p>
<p>&nbsp;Build this code, one point to remember here is if your unmanaged dll are not shared then&nbsp; copy the&nbsp; vc++ code dll that we created previously along with the debug symbols file &nbsp;to the working directory of the application (which in this case is&nbsp;<span style="background-color: #ffff00;"><strong>bin\debug)</strong></span> folder of C#.NET application.</p>
<p>once you run the .net application, you will get result like the below:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/4705.Result.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/4705.Result.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/4705.Result.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/4705.Result.png" /></a></p>
<p><br />So all done to call unmanaged functions from Managed code.</p>
<p>&nbsp;Visual Studio 2010 provides us the flexibility to debug unmanaged code from C#.NET application, below&nbsp; is a setting which you need to enable for unamnaged code debugging:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/7026.debugging%20umnanaged%20code.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/7026.debugging-umnanaged-code.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/7026.debugging%20umnanaged%20code.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/7026.debugging-umnanaged-code.png" /></a></p>
<p>once you check the "Enable unmanaged code debugging" property, you can easily debug your unmanaged code by using F10 and F11 keys.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3058.Debugg%20Window.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3058.Debugg-Window.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/64/3058.Debugg%20Window.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-64/3058.Debugg-Window.png" /></a></p>
<p>&nbsp;</p>
<p>Happy Coding :-)</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>