<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aneef.Net &#187; Visual Studio</title>
	<atom:link href="http://www.aneef.net/tag/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aneef.net</link>
	<description>Do it in .Net way &#124; Blogging about C#,ASP.Net, LINQ,WPF and .Net Technologies</description>
	<lastBuildDate>Tue, 29 Nov 2011 13:18:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Visual Studio 2010 RC Now Available for Download</title>
		<link>http://www.aneef.net/2010/02/10/visual-studio-2010-rc-now-available-for-download/</link>
		<comments>http://www.aneef.net/2010/02/10/visual-studio-2010-rc-now-available-for-download/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 22:55:53 +0000</pubDate>
		<dc:creator>Aneef Fashir</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Scott Guthrie]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://www.aneef.net/?p=127</guid>
		<description><![CDATA[Microsoft has just released the Release Candidate version of Visual Studio 2010 for public download. You can now download and try out Visual Studio 2010 RC and .NET Framework 4 RC before the final version which is due to hit retail in this first quarter of 2010. It was released for MSDN Subscribers on 8th [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Microsoft has just released the Release Candidate version of Visual Studio 2010 for public download. You can now download and try out Visual Studio 2010 RC and .NET Framework 4 RC before the final version which is due to hit retail in this first quarter of 2010. It was released for <a href="http://msdn.microsoft.com/">MSDN </a>Subscribers on 8th February and released for the public just few minutes ago (11th February 2010).</p>
<p><img class="alignnone" title="Visual studio 2010 RC" src="http://www.microsoft.com/visualstudio/en-us/content/images/msdn/placeholder_for_vid.jpg" alt="Visual studio 2010 RC" width="560" height="315" /></p>
<p>It is a much  awaited version of visual studio and it is available in following SKU&#8217;s:</p>
<ul>
<li>Visual Studio 2010 Ultimate</li>
<li>Visual Studio 2010 Premium</li>
<li>Visual Studio 2010 Professional</li>
</ul>
<p>Those who wish to try it, go get your copy <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">here</a>.</p>
<p>According to the reviews so far VS 2010 RC seems to be much faster in  Compiling, Building  and Intellisense. Read Scott Guthrie&#8217;s announcement on this release <a href="http://weblogs.asp.net/scottgu/archive/2010/02/08/vs-2010-net-4-release-candidate.aspx" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aneef.net/2010/02/10/visual-studio-2010-rc-now-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scott Guthrie Announces the WebsiteSpark Program</title>
		<link>http://www.aneef.net/2009/09/24/scott-guthrie-announces-the-websitespark-program/</link>
		<comments>http://www.aneef.net/2009/09/24/scott-guthrie-announces-the-websitespark-program/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 10:06:43 +0000</pubDate>
		<dc:creator>Aneef Fashir</dc:creator>
				<category><![CDATA[.Net Related]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[visual studio 2008]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[ScottGu]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[WebSpark]]></category>

		<guid isPermaLink="false">http://www.aneef.net/?p=104</guid>
		<description><![CDATA[Scott guthrie just did a great announcement about the WebsiteSpark Program. what is WebsiteSpark? WebsiteSpark is designed for independent web developers and web development companies that build web applications and web sites on behalf of others.  It enables you to get software, support and business resources from Microsoft at no cost for three years, and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Scott guthrie just did a great announcement about the <a href="http://www.microsoft.com/web/websitespark/">WebsiteSpark </a>Program.</p>
<p><strong>what is WebsiteSpark?</strong></p>
<p><span style="font-family: arial; font-size: x-small;"><a href="http://www.microsoft.com/web/websitespark/" target="_blank">WebsiteSpark</a> is designed for independent web developers and web development companies that build web applications and web sites on behalf of others.  It enables you to get software, support and business resources from Microsoft at no cost for three years, and enables you to expand your business and build great web solutions using ASP.NET, Silverlight, SharePoint and PHP, and the <a href="http://www.microsoft.com/web/gallery/default.aspx" target="_blank">open source applications</a> built on top of them.</p>
<h3><span style="text-decoration: underline;">What does the program provide?</span></h3>
<p><a href="http://www.microsoft.com/web/websitespark/" target="_blank">WebSiteSpark</a> provides software licenses that you can use for three years at no cost.  Once enrolled, you can download and immediately use the following software from Microsoft:</p>
<ul>
<li>3 licenses of Visual Studio 2008 Professional Edition</li>
<li>1 license of Expression Studio 3 (which includes Expression Blend, Sketchflow, and Web)</li>
<li>2 licenses of Expression Web 3</li>
<li>4 processor licenses of Windows Web Server 2008 R2</li>
<li>4 processor licenses of SQL Server 2008 Web Edition</li>
<li>DotNetPanel control panel (enabling easy remote/hosted management of your servers)</li>
</ul>
<p>The Windows Server and SQL Server licenses can be used for both development <em>and</em> production deployment.  You can either self-host the servers on your own, or use the licenses with a hoster.  <a href="http://www.microsoft.com/web/websitespark/" target="_blank">WebsiteSpark</a> makes it easy to find hosters who are also enrolled in the program, and who can use your licenses to provide you with either dedicated or virtual dedicated servers to host your sites on.</p>
<p>In addition to software, <a href="http://www.microsoft.com/web/websitespark/" target="_blank">WebsiteSpark</a> provides partner opportunities to grow and build your business (including customer referrals through our partner programs).  It also includes product support (including 2 professional support incidents) and free online training for the products.</p>
<p>for further information on this visit Scotts blog <a href="http://weblogs.asp.net/scottgu/archive/2009/09/24/announcing-the-websitespark-program.aspx">here.</a></p>
<p>Thanks Scott for the great information <img src='http://www.aneef.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aneef.net/2009/09/24/scott-guthrie-announces-the-websitespark-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ClickOnce Application,Expired Certificates &amp; Public Key Token PART II</title>
		<link>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-ii/</link>
		<comments>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-ii/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 10:40:36 +0000</pubDate>
		<dc:creator>Aneef Fashir</dc:creator>
				<category><![CDATA[ClickOnce]]></category>
		<category><![CDATA[visual studio 2008]]></category>
		<category><![CDATA[Certificate]]></category>
		<category><![CDATA[Public Token Key]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-ii/</guid>
		<description><![CDATA[In the first part of this series I wrote the possible solutions available for the ClicOnce certificate issue. if you have missed it please read it before continuing. ClickOnce Application,Expired Certificates &#38; Public Key Token PART I This post is not going to be a long one, I&#160; just want to point out a very [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>In the <a href="http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/" target="_blank">first part</a> of this series I wrote the possible solutions available for the ClicOnce certificate issue. if you have missed it please read it before continuing.</p>
<ol>
<ol>
<ul>
<li><a href="http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/" target="_blank">ClickOnce Application,Expired Certificates &amp; Public Key Token PART I</a></li>
</ul>
<ul>This post is not going to be a long one, I&nbsp; just want to point out a very important issue, when updating the ClickOnce using the method specified in <a href="http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/" target="_blank">PART I</a> . </ul>
<ul>When using <a href="http://www.jamesharte.com/blog/?p=11" target="_blank">Jim Harte&#8217;s</a> Method to update a ClickOnce with a new certificate, it checks for the public token key of the current application to find its uninstall string, and then execute runDLL32 to trigger the uninstall. below is the code which gets the uninstall string:</ul>
<ul></ul>
<ol>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Gets the uninstall string for the current ClickOnce app from the Windows </span>
<span class="rem">/// Registry.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name="PublicKeyToken"&gt;The public key token of the app.&lt;/param&gt;</span>
<span class="rem">/// &lt;returns&gt;The command line to execute that will uninstall the app.&lt;/returns&gt;</span>
 <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetUninstallString(<span class="kwrd">string</span> PublicKeyToken,</pre>
<pre class="csharpcode">                          <span class="kwrd">out</span> <span class="kwrd">string</span> DisplayName)
{
 <span class="kwrd">string</span> uninstallString = <span class="kwrd">null</span>;
 <span class="kwrd">string</span> searchString = <span class="str">"PublicKeyToken="</span> + PublicKeyToken;
 RegistryKey uninstallKey = _
      Registry.CurrentUser.OpenSubKey</pre>
<pre class="csharpcode">                (<span class="str">"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"</span>);
 <span class="kwrd">string</span>[] appKeyNames = uninstallKey.GetSubKeyNames();
 DisplayName = <span class="kwrd">null</span>;
 <span class="kwrd">foreach</span>(<span class="kwrd">string</span> appKeyName <span class="kwrd">in</span> appKeyNames)
{
  RegistryKey appKey = uninstallKey.OpenSubKey(appKeyName);
  uninstallString = (<span class="kwrd">string</span>)appKey.GetValue(<span class="str">"UninstallString"</span>);
  DisplayName = (<span class="kwrd">string</span>)appKey.GetValue(<span class="str">"DisplayName"</span>);
  appKey.Close();

 <span class="kwrd">if</span>(uninstallString.Contains(searchString))
                    <span class="kwrd">break</span>;
 }
            uninstallKey.Close();
            <span class="kwrd">return</span> uninstallString;
        }</pre>
<pre class="csharpcode">&nbsp;</pre>
<p>&nbsp;</p>
<p>In the above code it goes through registry keys of all ClickOnce application to get the uninstall string. and if that uninstall string contains the Public Token key of the current application, it will uninstall the application with that particular uninstall string. this is completely ok if there is only one application with that public token key. <strong>the public key of an assembly name identifies the developer (or the organization). Most organizations use only one public key to sign their assemblies with</strong>. so what if there is more than 1 application which has the same public token key?</p>
</ol>
<li>The code will uninstall the very first match in the above code and it might uninstall some other application, instead of uninstalling the one we need to uninstall.
<li>and it will&nbsp; also install the new application from new URL, but with a different name sometimes (Eg: application name -1).
<li>And if it had uninstalled another application, whenever user launches this application it will prompt the uninstall screen, each time when there are more than 1 application with the same public token key.</li>
</ol>
</ol>
<p>The Image below shows an uninstall string, which contains the application name, and public token key:</p>
<p><a href="http://www.aneef.net/wp-content/uploads/2009/06/debug.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="debug" src="http://www.aneef.net/wp-content/uploads/2009/06/debug-thumb.jpg" width="558" height="102"></a> </p>
<p>To avoid this problem of wrong application getting uninstalled, I changed this part of the code from above code to :</p>
<pre class="csharpcode"><span class="kwrd">if</span>(uninstallString.Contains(searchString)) <span class="kwrd">break</span>; </pre>
<p><style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
<p>this:</p>
<pre class="csharpcode"><span class="kwrd">if</span>(uninstallString.Contains(searchString)
               &amp;&amp; uninstallString.Contains(<span class="str">"yourApp.application"</span>))
                    <span class="kwrd">break</span>;</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<ol>
<ol>
<ol>
<p>&nbsp;</p>
<p>In the code above, I&#8217;m Checking the ClickOnce application name with extension, along with the public token key to find out the correct uninstall string. that&#8217;s it!. </p>
<p>Hope this solves your time in someway. </p>
<p><style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
</ol>
</ol>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-ii/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ClickOnce Application,Expired Certificates &amp; Public Key Token PART I</title>
		<link>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/</link>
		<comments>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 09:05:36 +0000</pubDate>
		<dc:creator>Aneef Fashir</dc:creator>
				<category><![CDATA[ClickOnce]]></category>
		<category><![CDATA[visual studio 2008]]></category>
		<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Certificate]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[thawte]]></category>
		<category><![CDATA[Update]]></category>
		<category><![CDATA[verisign]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/</guid>
		<description><![CDATA[Well, by this time I&#8217;m sure most of the ClickOnce application developers are aware of this problem. if you aren&#8217;t here is a basic description of what the problem is: Problem description ClickOnce allows application updates, only if the updated application manifests are signed with the same certificate (publisher) as was used to originally sign [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Well, by this time I&#8217;m sure most of the ClickOnce application developers are aware of this problem. if you aren&#8217;t here is a basic description of what the problem is:</p>
<blockquote style="width: 85%; height: 285px"><p><strong>Problem description</strong></p>
<p>ClickOnce allows application updates, only if the updated application manifests are signed with the same certificate (publisher) as was used to originally sign the application manifests. However, most CA&#8217;s like Verisign, and many enterprise customers own CA&#8217;s generate new certificates with new key pairs and only the same common name (CN). </p>
<p>The certificate is used for the Authenticode signature element and for the strong name signature element of the manifest file to protect it against tampering, and to provide identity information for the trust manager. If the signing certificate expires and you publish an application update with a renewed certificate which has different keys, then the update will fail with the error message described in the <a href="http://support.microsoft.com/kb/925521/en-us" target="_blank">KB article.</a></p>
</blockquote>
<p>&nbsp;</p>
<p>There are lots of issues, and threads are being discussed how to resolve this issue. and these are the preferable solutions available on net.</p>
<ol>
<li>Manually Uninstall and Re install the application with new certificate &#8211; which we cannot do when we have a large number of client base who are using our ClickOnce Applicaiton.
<li>Install .net Framework 2.0 SP1 for XP /&nbsp; .Net Framework 3.5 SP1 for vista or later, in these service pack s for .net Framework, this bug is fixed, and it will seamlessly update the application. &#8211; but we cannot force or inform clients to do that. yeah by this time most of the users might have installed .net framework 3.5 sp1 through windows automatic updates. but even if one guy haven&#8217;t done that KABOOM!!, clients are going to complain.
<li>Sign the new click once with 2 different keys &#8211; a solution by <a href="http://blogs.msdn.com/danielma/contact.aspx">Daniel Margetic</a> , even though developers may like it, when considering Automation, and&nbsp; Infrastructure of build servers this might not be a favorite solution.
<li>Automatically Uninstalling the old application, and re-install the new application. &#8211; a solution by <a href="http://www.jamesharte.com/blog/?p=11" target="_blank">Jim Harte</a> , using this method, we will be releasing an update for the application with expired certificate, which will have scripts for automatically uninstall the applicaiton, and install the application with new certificate, from a new location. the following thread on MSDN explains this process completely: <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/1217520d-6dc4-4fb1-83d1-0fa148d60e5d" target="_blank">VS2008 SP-1 change certificate, user can&#8217;t pick up update</a> </p>
<p>The last one seems to be a favorite of most of the people around the globe. it uses <a href="http://www.jamesharte.com/downloads/ClickOnceReinstall.zip" target="_blank">these classes</a> by&nbsp; Jim Harte&nbsp; to uninstall and re install the application, using the following code: </li>
</ol>
<pre class="csharpcode">MessageBox.Show(<span class="str">"Your Message to Client"</span>);
DeploymentUtils.UninstallMe()
DeploymentUtils.AutoInstall(<span class="str">"&lt;Path toNewApplication.application&gt;"</span>);
Application.Exit();</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&nbsp;</p>
<p>you can have the new path as a sub folder of current applications update URL. you can get a ClickOnce applicaitons update URL using the line below :</p>
<pre class="csharpcode">ApplicationDeployment.CurrentDeployment.UpdateLocation.Host</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>That would do the trick. so what is it about Public Token Key ??. I will explain this in the PART 2 of this article.</p>
<p>Hope it helps,</p>
<p>Aneef</p>
<p><strong>I just posted the Part II of this series is </strong><a href="http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-ii/"><strong>here</strong></a><strong>.</strong></p>
<p><strong>Special Note:</strong></p>
<p>Thanks to <a href="http://robindotnet.wordpress.com/" target="_blank">RobinDotNet</a> for his wonderful support through MSDN and through his blog to solve this problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aneef.net/2009/06/11/clickonce-applicationexpired-certificates-public-key-token-part-i/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ADO.Net &amp; OPENXML to Perform Bulk Database Operations</title>
		<link>http://www.aneef.net/2007/12/18/adonet-openxml-to-perform-bulk-database-operations/</link>
		<comments>http://www.aneef.net/2007/12/18/adonet-openxml-to-perform-bulk-database-operations/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 05:36:37 +0000</pubDate>
		<dc:creator>Aneef Fashir</dc:creator>
				<category><![CDATA[ADO.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Aneef]]></category>
		<category><![CDATA[BULK Data manipulation]]></category>

		<guid isPermaLink="false">http://www.aneef.net/?p=7</guid>
		<description><![CDATA[Last week at my work I had to write a tool to process few hundreds of thousand email files and insert their details to the MS SQL Server 2005 database. Doing it in traditional way might require much connectivity to the database and will consume many resources. I was wondering what if I could insert [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Last week at my work I had to write a tool to process few hundreds of thousand email files and insert their details to the MS SQL Server 2005 database. Doing it in traditional way might require much connectivity to the database and will consume many resources. I was wondering what if I could insert those whole hundreds thousands of data at once to the db which will be much more efficient. I started googgling and I found <a href="http://msdn2.microsoft.com/en-us/library/aa276847.aspx">OPENXML</a>. This is not a whole new technology but I didn’t know about this before (strange!!).</p>
<p>And few more minutes of research I found out how to perform bulk operations against the databases using OPENXML and stored procedures.</p>
<p><strong>What is OPENXML?</strong></p>
<p>OPENXML is a function added to SQL Server 2000 that provides a row set view over an XML document. Since a row set is simply a set of rows that contain columns of data, OPENXML is the function that allows an XML document to be treated in the familiar relational database format. It allows for the passing of an XML document to a T-SQL stored procedure for updating the data.</p>
<p><strong>OPENXML- Summery</strong></p>
<ul>
<li>It extends the SQL Language</li>
<li>It is used within T-SQL Stored Procedures
<ul>
<li>XML Document passed as parameter</li>
</ul>
</li>
<li>It uses row and column selectors utilizing XPath</li>
<li>It supports the following:
<ul>
<li>Attribute and element-centric mappings.</li>
<li>Edge table row set.</li>
<li>XML annotation/overflow column.</li>
<li>Hierarchy support.</li>
</ul>
</li>
</ul>
<p><strong>OPENXML and ADO.Net</strong></p>
<p>This code block explains the usage of OPENXML to insert bulk data to database. It simulates the actual process I wanted ( processing .eml files) by reading files in a folder and saving their names, created date and size in bytes.</p>
<ol>
<li>First create the table below:<br />
<h5></h5>
<h6></h6>
<blockquote>
<h5><em><font color="#0000ff">CREATE TABLE</font> FileDetails(</em></h5>
<h5><em>FileName varchar(50) <font color="#0000ff">PRIMARY KEY</font>,</em></h5>
<h5><em>CreatedDate varchar(50) ,</em></h5>
<h5><em>Size <font color="#0000ff">decimal</font>(18, 0) )</em></h5>
</blockquote>
</li>
<li>And then create the stored procedure below:<br />
<blockquote>
<h5><em><font color="#0000ff"><em><font color="#0000ff"><em><font color="#0000ff">CREATE PROC</font> sp_bulkinsert @xmldata varchar(max)</em></font></em></font></em></h5>
<h5><font color="#0000ff"><em>AS</em></font></h5>
<h5><em><font color="#0000ff">DECLARE</font> @hDoc int</em></h5>
<h5><em><font color="#0000ff">exec</font> sp_xml_preparedocument @hDoc OUTPUT,@xmldata</em></h5>
<h5><em>&#8211;inserting data</em></h5>
<h5><em><font color="#0000ff">Insert</font> Into FileDetails </em></h5>
<h5><em><font color="#0000ff">SELECT</font> FileName, CreatedDate, Size</em></h5>
<h5><em><font color="#0000ff">FROM</font> OPENXML (@hdoc, &#8216;/ds/fileDetails&#8217;,2)</em></h5>
<h5><em><font color="#0000ff">WITH</font> (FileName varchar(50), CreatedDate Datetime, Size decimal) XMLFileDetails</em></h5>
<h5><em><font color="#0000ff">Where</font> XMLFileDetails.FileName Not IN (Select FileName from FileDetails)</em></h5>
<h5><em><font color="#0000ff">EXEC</font> sp_xml_removedocument @hDoc</em></h5>
<h5><font color="#0000ff"><em>GO</em></font></h5>
</blockquote>
</li>
<li>The below sample code snippet shows how to call this stored procedure to insert bulk data to database at once.</li>
</ol>
<ol>We can retrieve the file details using FileInfo() objects and create a Dataset of the file details and then we can convert this Dataset to xml using <a href="http://msdn2.microsoft.com/en-us/library/system.data.dataset.writexml.aspx">WriteXml()</a> Method of the Dataset.</ol>
<blockquote><p><em>private static string preparexml(DataSet ds)</em></p>
<p><em>{</em></p>
<p><em>StringBuilder sb = new StringBuilder();</em></p>
<p><em>StringWriter sw = new StringWriter(sb);</em></p>
<p><em>ds.WriteXml(sw, XmlWriteMode.WriteSchema);</em></p>
<p><em>return sb.ToString();</em></p>
<p><em>}</em></p></blockquote>
<p>This xml representation of the data can be passed as the parameter to the stored procedure as given below :</p>
<blockquote><p><code><em>private static void bulkInsert(string xml)</em> </code></p>
<p><em>{</em></p>
<p><em>try{</em></p>
<p><em>SqlConnection con = creatCon();</em></p>
<p><em>con.Open();</em></p>
<p><em>SqlCommand cmd = new SqlCommand(&#8220;sp_bulkinsert&#8221;, con);</em></p>
<p><em>cmd.CommandType = CommandType.StoredProcedure;</em></p>
<p><em>cmd.Parameters.Add(new SqlParameter(&#8220;@xmldata&#8221;,SqlDbType.VarChar));</em></p>
<p><em>cmd.Parameters["@xmldata"].Value=xml;</em></p>
<p><em>cmd.ExecuteNonQuery();</em></p>
<p><em>Console.WriteLine(&#8220;Completed inserting file informations to database&#8221;);</em></p>
<p><em>con.Close();</em></p>
<p><em>}</em></p>
<p><em>catch(Exception ex)</em></p>
<p><em>{</em></p>
<p><em>Console.WriteLine(ex.Message);</em></p>
<p><em>}</em></p>
<p><em>}</em></p></blockquote>
<p>That’s all simple isn’t it? You can see the performance of this method by writing another code to insert the same fields using the traditional 1 at a time way. Which surprisingly will show a huge difference in performance and time.</p>
<p>You can use the same way to update, delete records in bulk.</p>
<p>The complete code can be downloaded and tested in the below link :</p>
<p><a href="http://www.aneef.net/wp-content/uploads/2007/12/bulkoperations.zip">Complete Source Code</a></p>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aneef.net/2007/12/18/adonet-openxml-to-perform-bulk-database-operations/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.aneef.net @ 2012-02-04 22:46:28 by W3 Total Cache -->
