tag:blogger.com,1999:blog-24526294455578201382017-08-18T08:00:13.139+05:30Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumersA Microsoft Technology blog, dedicated to a set of great developers and consumers (Windows 10, Windows Phone, MS Office, Azure, Silverlight, LightSwitch, WPF, XAML, C#, Visual Studio and .Net)Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.comBlogger1102125tag:blogger.com,1999:blog-2452629445557820138.post-37211214663251192012017-08-18T08:00:00.000+05:302017-08-18T08:00:13.148+05:30Do you know that, there exist a snippet to generate reverse 'for' loop?<p>In every programming language, when you want to loop through a collection, you use the '<font color="brown">for</font>' loop in maximum scenarios. When writing code in Visual Studio, you might be aware that, there exist a code snippet to write the for-loop structure.</p>
<p>&#160;</p>
<p>But you might not noticed that, there exist another code snippet to generate a reverse for-loop. Let's see what it is and how it operates.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-oYihj2C_A1M/WZXI-8BX_DI/AAAAAAAAS5s/-4upYMoqHDQS91wfHEGDj7iLhCPsb9OxwCLcBGAs/s700/reverse-for-loop-snippet.png" class="postImage" alt="Do you know that, there exist a snippet to generate reverse 'for' loop?" title="Do you know that, there exist a snippet to generate reverse 'for' loop?"/></p>
<p>&#160;</p>
<p>Code snippets are the templates that makes it easier to generate repeating code patterns, such as loops, conditional statements or try-catch exception block. The code snippet '<font color="brown">for</font>' does the same to generate a normal for-loop.</p>
<p>&#160;</p>
<p>To generate the for-loop structure, write '<font color="brown"><b>for</b></font>' inside your Visual Studio code editor and press <b>TAB</b> key twice to generate it:</p>
<p><img src="https://3.bp.blogspot.com/-uc9_bZXO4tM/WZXBT4V0SAI/AAAAAAAAS5c/tkrr1R6Ke0cZm_8bTXa_FDK69zl0iOXDwCLcBGAs/s700/for-code-snippet.png" class="postImage" alt="Generate for-loop using the 'for' code snippet" title="Generate for-loop using the 'for' code snippet"/></p>
<p class="infoGreen">Did you check the book titled '<a href="http://amzn.to/2uFTRy8" target="_blank"><strong>Mastering Visual Studio 2017</strong></a>'? It covers all the new features introduced in Visual Studio 2017. You can <b>buy the book from Amazon</b> at: <a href="http://amzn.to/2uFTRy8" target="_blank"><b>http://amzn.to/2uFTRy8</b></a>.
<p>&#160;</p>
<p>The other code snippet '<font color="brown">forr</font>' is there to create a reverse for-loop structure. In your Visual Studio code editor window, type '<font color="brown"><b>forr</b></font>' and press <b>TAB</b> key twice. This will result the following code block in the editor:</p>
<p><img src="https://3.bp.blogspot.com/-8iTtUU1Gu24/WZXBTyU1pdI/AAAAAAAAS5Y/Ivc1UOIe5ksLH1eKa6MU6RxLXovQ4t_bgCLcBGAs/s700/forr-code-snippet.png" class="postImage" alt="Generate reverse for-loop using the 'forr' code snippet" title="Generate reverse for-loop using the 'forr' code snippet"/></p>
<p>&#160;</p>
<p>I hope that the post was clear and easy to understand. For more posts on Visual Studio Tips & Tricks, stay tuned to this blog.</p>
<p>&#160;</p>
<p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-40745125073846452172017-08-14T22:41:00.000+05:302017-08-15T08:30:33.417+05:30Visual Studio 2017 (version 15.3) and .NET Core 2.0 is now available<p>Visual Studio 2017 version 15.3, has been released, along with .NET Core 2.0 and Visual Studio for Mac (version 7.1) operating system. Microsoft, in a <a href="https://blogs.msdn.microsoft.com/visualstudio/2017/08/14/visual-studio-2017-version-15-3-released/" target="_blank">blog post</a>, announced the availability of both the products. Visual Studio 2017 version 15.3 contains many new improvements and fixes.</p>
<p>&#160;</p>
<p>.NET Core 2.0 is the second major version of .NET Core and this release focuses on performance improvements and expanded set of APIs available via .NET Standard 2.0.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-n4VEiQlIgm4/WZJjkfg38FI/AAAAAAAAS5I/HQ9_qYHr_HU_PKws46bhKploDSZwcehAQCLcBGAs/s700/visual-studio-2017.png" class="postImage" alt="Visual Studio 2017 (version 15.3) and .NET Core 2.0 is now available" title="Visual Studio 2017 (version 15.3) and .NET Core 2.0 is now available"/></p>
<h2>From where to download?</h2>
<p>
<ul>
<li><a href="https://www.visualstudio.com/downloads/" target="_blank">Download Visual Studio 2017 (version 15.3)</a></li>
<li><a href="https://dot.net/core" target="_blank">Download .NET Core 2.0</a></li>
<li><a href="https://www.visualstudio.com/downloads/?os=mac" target="_blank">Download Visual Studio for Mac</a></li>
</ul>
</p>
<p>&#160;</p>
<p class="infoGreen">Don't forget to checkout my book <a href="http://www.kunal-chowdhury.com/p/mastering-visual-studio-2017-book.html" target="_blank"><strong>Mastering Visual Studio 2017</strong></a> (Buy from <a href="http://amzn.to/2v871pc" target="_blank"><b>Amazon</b></a>)
<p>&#160;</p>
<h2>What's new in Visual Studio 2017, version 15.3?</h2>
<p>
<ul>
<li><a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#Accessibility">Accessibility Improvements</a> make Visual Studio more accessible than ever.</li>
<li><a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#azfunctions">Azure Function Tools</a> are included in the Azure development workload. You can develop Azure Function applications locally and publish directly to Azure.</li>
<li>You can now build applications in Visual Studio 2017 that run on <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#azstack">Azure Stack</a> and government clouds, like Azure in China.</li>
<li>Microsoft improved <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#dotnetcoreimprovements15P3">.NET Core development</a> support for .NET Core 2.0, and Windows Nano Server containers.</li>
<li>In <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#IDEimprovements15">Visual Studio IDE</a>, Microsoft improved Sign In and Identity, the start page, Lightweight Solution Load, and setup CLI. Microsoft also improved refactoring, code generation and Quick Actions.</li>
<li>The <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#VSEditor153">Visual Studio Editor</a> has better accessibility due to the new ‘Blue (Extra Contrast)’ theme and improved screen reader support.</li>
<li>Microsoft improved the <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#Debugging">Debugger and diagnostics</a> experience. This includes Point and Click to Set Next Statement. Microsoft also refreshed all nested values in variable window, and made Open Folder debugging improvements.</li>
<li><a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#xamarin">Xamarin</a> has a new standalone editor for editing app entitlements.</li>
<li>The <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#cmake">Open Folder and CMake Tooling</a> experience is updated. You can now use CMake 3.8.</li>
<li>Microsoft made improvements to the IntelliSense engine, and to the project and the code wizards for <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#C++LanguageServices">C++ Language Services.</a></li>
<li><a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#C++ToolsetLibs15">Visual C++ Toolset</a> supports command-prompt initialization targeting.</li>
<li>Microsoft added the ability to use <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#cs71">C# 7.1 Language</a> features.</li>
<li>You can install <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#typescript">TypeScript</a> versions independent of Visual Studio updates.</li>
<li>Microsoft added support for <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#Node.js">Node 8 debugging</a>. </li>
<li><a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#NuGetimprovements15P3">NuGet</a> has added support for new TFMs (netcoreapp2.0, netstandard2.0, Tizen), Semantic Versioning 2.0.0, and MSBuild integration of NuGet warnings and errors.</li>
<li>Visual Studio now offers <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#dotnet47">.NET Framework 4.7</a> development tools to supported platforms with 4.7 runtime included. </li>
<li>Microsoft added clusters of related events to the search query results in the <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#appInsights">Application Insights</a> Search tool. </li>
<li>Microsoft improved syntax support for SQL Server 2016 in <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#redgate">Redgate</a> SQL Search.</li>
<li>Microsoft enabled support for <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#MSGraph">Microsoft Graph APIs</a> in Connected Services.</li>
</ul>
</p>
<p>&#160;</p>
<p>For the complete changes and fixes, as part of this new build, checkout the <a href="https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes" target="_blank">official <b>Release Notes</b></a>.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-7602164280858266222017-08-14T08:00:00.000+05:302017-08-14T08:00:13.905+05:30Integrating Bitbucket extension to Visual Studio 2015/2017<p>If you are using BitBucket Git repositories for hosting and managing your code, Visual Studio 2015 and Visual Studio 2017 has the extension to easily manage your files, directly from the Team Explorer view of the IDE.</p>
<p>&#160;</p>
<p>In this post, we are going to get you started with the extension and see the main features that the extension supports.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-mghtxf13-GU/WZCEZPTLmzI/AAAAAAAAS4c/DnvPZtR2kMUgvenLwNDM1ZdT3ynci0g2wCLcBGAs/s600/bitbucket-extension-visual-studio.png" class="postImage" alt="Integrating Bitbucket extension to Visual Studio 2015/2017 (www.kunal-chowdhury.com)" title="Integrating Bitbucket extension to Visual Studio 2015/2017 (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>Visual Studio Bitbucket Extension, which is available on Visual Studio Marketplace, is a plugin for Visual Studio to help you improve your productivity while working on Bitbucket as your Git repository. Currently, it supports <a href="http://www.kunal-chowdhury.com/2016/06/visual-studio-2015-update-3.html" target="_blank"><strong>Visual Studio 2015</strong></a> and <a href="http://www.kunal-chowdhury.com/2017/03/download-visual-studio-2017.html" target="_blank"><strong>Visual Studio 2017</strong></a>.</p>
<p>&#160;</p>
<p>This extension supports the following core features:</p>
<ul>
<li><font color="brown"><b>Create -</b></font> You can create a git repository on Bitbucket.org and synchronize it with your local version.</li>
<li><font color="brown"><b>Clone -</b></font> This will list all existing Bitbucket repositories and allows you to clone it locally.</li>
<li><font color="brown"><b>Publish -</b></font> You can publish your local-only repositories to Bitbucket server.</li>
<li><font color="brown"><b>Pull Requests -</b></font> You can view all pull requests, create a new one, Approve/Disapprove pull requests, view files, commit changes and submit comments from pull request. You can also view Pull Request diff with syntax language highlighting.</li>
</ul>
<p>Before starting with it, you need to know that the extension is not available by default in Visual Studio installation. You need to download it from the Visual Studio Marketplace. To download it:</p>
<ul>
<li>Either open your browser and navigate to Visual Studio Marketplace at: <a href="https://marketplace.visualstudio.com/items?itemName=MistyK.VisualStudioBitbucketExtension" target="_blank">https://marketplace.visualstudio.com/items?itemName=MistyK.VisualStudioBitbucketExtension</a> and download the extension.<br/><br/></li>
<li>OR, you can open Visual Studio menu '<font color="green"><strong>Tools</strong></font> | <font color="green"><strong>Extension and Updates...</strong></font>' and search for the '<font color="green"><strong>bitbucket</strong></font>' extension, as shown below:<span><img src="https://3.bp.blogspot.com/-wzF6kedaP-s/WZCEaK2DzlI/AAAAAAAAS4o/LT2FbbRDMLAMQ7N3RMeRjBKR0zPiW1w_ACLcBGAs/s600/visualstudio-extension.png" class="postImage" alt="Visual Studio Extensions and Updates" title="Visual Studio Extensions and Updates"/></span><br/></li>
<li>Select the '<font color="green"><strong>Visual Studio Bitbucket Extension</strong></font>'and click '<font color="green"><strong>Download</strong></font>'.<br/><br/></li>
<li>The following dialog window will popup. Select the product(s) that you want to install the extension to, and then click '<font color="green"><strong>Install</strong></font>'.<span><img src="https://3.bp.blogspot.com/-Zd2WLfUywi4/WZCEZqxoScI/AAAAAAAAS4g/zWBfKUI4Vc4sDxwujUreCFgKw8r2FZPpACLcBGAs/s600/install-bitbucket-extension.png" class="postImage" style="width:400px !important;" alt="Install Bitbucket Extension" title="Install Bitbucket Extension"/></span><br/></li>
<li>Once the installation completes successfully, close and restart all your open Visual Studio instances, for the changes to take effect.<span><img src="https://3.bp.blogspot.com/-jkX-QhMdEQM/WZCEYGaMMkI/AAAAAAAAS4U/_3Ywyo1HF3oufDWpJUDjZvoMCtdsFt0ZACLcBGAs/s600/bitbucket-extension-installed.png" class="postImage" style="width:400px !important;" alt="Bitbucket extension installed in Visual Studio" title="Bitbucket extension installed in Visual Studio"/></span><br/></li>
<li>Once you reopen Visual Studio, switch on to '<font color="green"><strong>Team Explorer</strong></font>' where you can see the extension added to it already.<span><img src="https://3.bp.blogspot.com/-ftc8b9uO3gw/WZCEYnBn9SI/AAAAAAAAS4Y/gcCI5m4C1GA7qSyWeLgTTBXHnsfBbNizQCLcBGAs/s600/bitbucket-extension-in-visualstudio.png" class="postImage" style="width:400px !important;" alt="Bitbucket extension in Visual Studio Team Explorer" title="Bitbucket extension in Visual Studio Team Explorer"/></span><br/></li>
<li>Click on the '<font color="green"><strong>Login</strong></font>' link to connect to the Bitbucket server from Visual Studio Team Explorer. Then you will be allowed to perform the Git operations to your Bitbucket repositories, directly from Visual Studio.<span><img src="https://3.bp.blogspot.com/-JR_CDIwROBM/WZCEZi6RE1I/AAAAAAAAS4k/mEjD-NX1Xl4aUS3oJpwLdfpT-mdY61PFACLcBGAs/s600/login-to-bitbucket.png" class="postImage" style="width:400px !important;" alt="Login to Bitbucket account from Visual Studio Team Explorer" title="Login to Bitbucket account from Visual Studio Team Explorer"/></span><br/></li>
</ul>
<p>Was the post helpful? Which Git server do you use in your development environment? Do let us know.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-15666460481667640232017-08-10T20:25:00.000+05:302017-08-10T20:25:22.966+05:30Marshal.ReleaseComObject() vs. Marshal.FinalReleaseComObject()<p>If you are using COM components on your .NET code, you might be already aware of the <font color="brown">Marshal.ReleaseComObject</font> and <font color="brown">Marshal.FinalReleaseComObject</font>, which are used to release the managed reference to Runtime Callable Wrapper (RCW) of the COM object.</p>
<p>&#160;</p>
<p>If both are used to release COM objects from memory, and you are unsure which one to use, then this post will help you to learn the differences between the calls.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-9iyriBRHmaY/WYxzbrKp8xI/AAAAAAAAS3c/Wq0rwhf133kP5QIt7JqC0zduQkLjYaJLwCLcBGAs/s600/marshal-release-com-object.png" class="postImage" alt="Which one to use: Marshal.ReleaseComObject() or Marshal.FinalReleaseComObject()?" title="Which one to use: Marshal.ReleaseComObject() or Marshal.FinalReleaseComObject()?"/></p>
<p>&#160;</p>
<p>.NET Framework is always a better choice managing your .NET objects. Once you are done, and the object that you are referring to goes out of scope, <b>Garbage Collector</b> automatically handles it to remove from memory. But that's not the same for unmanaged COM objects. Even though the scope of the instance variable goes out of it, but the reference still stays in memory as an <b>RCW</b> (<strong>Runtime Callable Wrapper</strong>).</p>
<p>&#160;</p>
<p>Every time a COM interface pointer enters into the <strong>Common Language Runtime</strong> (<b>CLR</b>), it wraps it inside an <b>RCW</b>. Then the <b>RCW</b> keeps a reference count which is then incremented every time a COM interface pointer is mapped to it.</p>
<p>&#160;</p>
<p>To release that memory instance, <font color="brown"><strong>Marshal.ReleaseComObject</strong></font> method is used which enables you to force the <b>RCW</b> and decrements the reference count. When the reference count reaches to zero, the runtime releases all its references on that unmanaged COM object. Attempting to access that object afterwards, throws you an <font color="brown"><strong>Exception</strong></font>.</p>
<p>&#160;</p>
<p><font color="brown"><strong>Marshal.FinalReleaseComObject</strong></font> also does the same, but with a little difference. When you call <font color="brown">Marshal.ReleaseComObject</font> method, it releases one <b>RCW</b> reference and decrements the count by one. To remove all the managed references to a COM object, you need to call the <font color="brown">Marshal.ReleaseComObject</font>, the following way, in a loop until it returns '0' (zero) to free up the COM object:</p>
<p>&#160;</p>
<p>
<div class="csharpcode">
<pre class="alt">&nbsp;</pre>
<pre> while (<b>Marshal.ReleaseComObject(obj)</b> != 0) ;</pre>
<pre class="alt">&nbsp;</pre>
</div>
</p>
<p>&#160;</p>
<p>But in case of <font color="brown">Marshal.FinalReleaseComObject</font>, you don't have to loop in to release all the associated references to <b>RCW</b>. Because, the method itself performs the same internally. If you check the <a href="https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs" target="_blank">original implementation</a> of the <font color="brown"><strong>System.Runtime.InteropServices.Marshal</strong></font> class, you will notice the following:</p>
<p>&#160;</p>
<p>
<div class="csharpcode">
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">int</span> <b>FinalReleaseComObject (<span class="kwrd">object</span> o)</b></pre>
<pre class="alt"> {</pre>
<pre> <b>while (ReleaseComObject (o) != 0) ;</b></pre>
<pre class="alt"> <span class="kwrd">return</span> 0;</pre>
<pre> }</pre>
<pre class="alt">&nbsp;</pre>
</div>
</p>
<p>&#160;</p>
<p>So, after reading this, which one will you prefer? It's definitely the <font color="brown">FinalReleaseComObject</font> as it internally loops through the <b>RCW</b> to release all the instance references, until the count becomes '0' (zero). Isn't it? Call the <font color="brown">ReleaseComObject</font> only if it is absolutely required to perform on a single reference.</p>
<p>&#160;</p>
<p>To learn further about the above two methods, checkout the MSDN reference: <a href="https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject(v=vs.110).aspx" target="_blank">Marshal.ReleaseComObject</a> and <a href="https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.finalreleasecomobject(v=vs.110).aspx" target="_blank">Marshal.FinalReleaseComObject</a>. I hope that the above post was clear and easy to understand. Don't forget to read my other posts/articles published on this blog.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-20185929775375111712017-08-08T20:23:00.000+05:302017-08-08T20:23:19.128+05:30Get 'Early Access' to .NET Framework 4.7.1<p>.NET Framework 4.7.1 is the next version of the .NET Framework, which is going to ship with Windows 10 Fall Creators Update. Microsoft, in a blog post, announced the availability of 'Early Access Preview Build' of .NET Framework 4.7.1.</p>
<p>&#160;</p>
<p>It's now a feature complete build and running under testing phase. If you are a Windows Insider, you can start validating your applications running on the latest version.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-DVNqctnJ_Cs/WYnP9F72aVI/AAAAAAAAS3M/ukOYpwyJWGcdaTixDgrsDuaR3B5-tXLmgCLcBGAs/s600/dotnet471.png" class="postImage" alt="Get 'Early Access' to .NET Framework 4.7.1" title="Get 'Early Access' to .NET Framework 4.7.1"/></p>
<p>&#160;</p>
<p>The .NET Framework 4.7 is the latest version of the .NET Framework. It can be used for production deployments on Windows 7, Windows Server 2008 R2 SP1, and later versions of both the client and server Windows families. The <strong>.NET Framework 4.7.1</strong> will be the next version of the .NET Framework and can be installed (build: 2538) on the following Windows versions:</p>
<p><ul>
<li>Windows 7 SP1</li>
<li>Windows 8.1</li>
<li>Windows 10 Anniversary Update</li>
<li>Windows 10 Creators Update<br/><br/></li>
<li>Windows Server 2008 R2 SP1</li>
<li>Windows Server 2012</li>
<li>Windows Server 2012 R2</li>
<li>Windows Server 2016</li>
</ul></p>
<p>There are a bunch of improvements in several areas of the .NET Framework 4.7.1, that includes: .NET Framework support for .NET Standard 2.0, Enhancements in the Visual Tree for WPF applications, Accessibility improvements in keyboard navigation, narration, high contrast and focus control areas, Support for the more secure SHA256 hashing algorithm, Performance, reliability and many more.</p>
<p>&#160;</p>
<p>You can install .NET Framework 4.7.1 Early Access from GitHub at: <a href="https://github.com/Microsoft/dotnet-framework-early-access/blob/master/README.md" target="_blank">https://github.com/Microsoft/dotnet-framework-early-access/blob/master/README.md</a>, review and accept the pre-release license terms and then you will be able to download the current build 2538.</p>
<p>&#160;</p>
<p>You can access the complete list of improvements present in .NET Framework 4.7.1, by visiting the 'Release Notes', available here: <a href="https://github.com/Microsoft/dotnet/blob/master/releases/net471/dotnet471-changes.md" target="_blank"><strong>.NET Framework 4.7.1 Release Notes</strong></a>. It describes the product improvements grouped by product area. Each change includes a Microsoft-internal VSTS bug ID, the primary binary that was updated and whether the change was a bug or a feature. Point to note that, there are no known issues in the current build 2538, released on 7th August 2017.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-32989514858591348382017-08-07T09:00:00.000+05:302017-08-07T08:57:07.441+05:30Here's how to retrieve Process details of Excel, PowerPoint app instance<p>If you are using COM objects like <a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank">Microsoft Excel</a> or <a href="/2017/02/how-to-read-microsoft-powerpoint-document.html" target="_blank">Microsoft PowerPoint</a>, you may sometime notice that the COM instances are not releasing from the process list; even though you called <font color="brown">Close()</font>, <font color="brown">Quit()</font> on the application instance.</p>
<p>&#160;</p>
<p>In case you faced the same issue, this post will guide you to find the Process ID (from the HWND) of that particular instance to take further action to release it.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-HcRJSG9py6I/WYDFJpJMibI/AAAAAAAAS2s/qVpyIhUW2jYRFbqIdT2fOB8xj6O8NFL-gCLcBGAs/s600/process-details.png" class="postImage" alt="Here's how to retrieve Process details of Excel, PowerPoint app instance" title="Here's how to retrieve Process details of Excel, PowerPoint app instance"/></p>
<p>&#160;</p>
<p>The <font color="brown"><strong>DllImport</strong></font> attribute in .NET is very useful when you want to reuse an existing unmanaged code in a managed application. It provides the information needed to call a function exported from an unmanaged DLL. You can find this under the '<font color="brown"><strong>System.Runtime.InteropServices</strong></font>' namespace, named as '<font color="brown"><strong>DllImportAttribute</strong></font>'.</p>
<p>&#160;</p>
<p>To get the process ID, based on handler of the Microsoft Excel or Microsoft PowerPoint application instance, you need to import '<font color="brown">user32.dll</font>' via DllImport and then use the Win32 API '<font color="brown"><strong>GetWindowThreadProcessId</strong></font>'.</p>
<p>&#160;</p>
<p>The '<font color="brown"><b>GetWindowThreadProcessId</b></font>' takes an integer parameter of application handler (<font color="brown">HWND</font>) and returns the process ID as <font color="blue">out</font> parameter. The extern modifier is used to declare the method which is implemented externally in a managed DLL.</p>
<p>&#160;</p>
<p>You can declare it as follow, to import the unamanged API <font color="brown">GetWindowThreadProcessId</font> and use it to retrieve the process ID:</p>
<p>&#160;</p>
<p>
<div class="csharpcode">
<pre class="alt">&nbsp;</pre>
<pre> <b>[DllImport(<span class="str">"user32.dll"</span>)]</b></pre>
<pre class="alt"> <span class="kwrd">static</span> <span class="kwrd">extern</span> <span class="kwrd">int</span> <b>GetWindowThreadProcessId</b>(<span class="kwrd">int</span> hWnd, <span class="kwrd">out</span> <span class="kwrd">int</span> lpdwProcessId);</pre>
<pre>&nbsp;</pre>
</div>
</p>
<p>&#160;</p>
<p>Then retrieve the <font color="brown">HWND</font> from the PowerPoint application instance or Excel application instance, that you created in your C# code. Pass that value to the <font color="brown">GetWindowThreadProcessId</font> method as first parameter and retrive the desired process ID of the same instance via the <font color="blue">out</font> parameter. Here's the code snippet for your reference:</p>
<p>&#160;</p>
<p>
<div class="csharpcode">
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">var</span> applicationHwnd = powerpointApp.HWND;</pre>
<pre class="alt"> <span class="kwrd">var</span> processID = GetProcessIdBy(applicationHwnd);</pre>
<pre> .</pre>
<pre class="alt"> .</pre>
<pre> .</pre>
<pre class="alt"> <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">int</span> GetProcessIdBy(<span class="kwrd">int</span> hwnd)</pre>
<pre> {</pre>
<pre class="alt"> <span class="kwrd">int</span> processId = 0;</pre>
<pre> GetWindowThreadProcessId(hwnd, <span class="kwrd">out</span> processId);</pre>
<pre class="alt"> <span class="kwrd">return</span> processId;</pre>
<pre> }</pre>
<pre class="alt">&nbsp;</pre>
</div>
</p>
<p>&#160;</p>
<p class="infoGreen"><b>Point to Note:</b> The same concept is not applicable for Microsoft Word application instance, as the Microsoft Automation API for Word does not provide relevant data like HWND; which is available for Excel and PowerPoint.</p>
<p>&#160;</p>
<p>Now, once you have the process ID, you can easily retrieve the process and perform your desire operation on it. I hope that the above code snippet was useful. Do let me know, if you are facing any issues or have any further queries.</p>
<p>&#160;</p>
<p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-6809456671044357442017-08-04T08:00:00.000+05:302017-08-04T08:00:20.320+05:30Solution for runtime error while repeatedly calling Ping.Send from C#<p>If you are using .NET Framework 2.0 or .NET Framework 3.5, and getting unexpected Runtime Error while repeatedly calling the <font color="brown">System.Net.NetworkInformation.Ping.Send</font> method from C# code, this is due to an issue which got resolved in .NET Framework 4.0 and above.</p>
<p>&#160;</p>
<p>Today, we are going to discuss about the issue, the root cause and the workaround to resolve this issue targeting .NET Framework version older than 4.0.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-tiQBuTbNXGw/WYCzwISXowI/AAAAAAAAS2c/Swjl96w7mKk5TY7j64mkrN7cK02Qjp9owCLcBGAs/s600/ping-send.png" class="postImage" alt="Solution for runtime error while repeatedly calling Ping.Send from C# (www.kunal-chowdhury.com)" title="Solution for runtime error while repeatedly calling Ping.Send from C# (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>According to <a href="http://support.microsoft.com/kb/2533627" target="_blank">Microsoft help documentation</a>, you may get unexpected runtime error or access violation exception when calling <font color="brown"><strong>System.Net.NetworkInformation.Ping.Send</strong></font> repeatedly by creating and destroying the instance of the <font color="brown"><strong>System.Net.NetworkInformation.Ping</strong></font> class.</p>
<p>&#160;</p>
<p>It has been also noticed that, if you are continuously calling the <font color="brown">Send</font> method, it occasionally fails even before the timeout expires and returns <font color="brown"><strong>System.Net.NetworkInformation.IPStatus.TimedOut</strong></font> as the response.</p>
<p>&#160;</p>
<p>The issue can happen only in applications targeting .NET Framework 2.0, 3.5. If you are using .NET Framework 4.0 or above, the problem does not occur.</p>
<h2>Solution (Workaround)</h2>
<p>To resolve this issue, as a workaround, you can follow either of the following listed options:</p>
<ul>
<li>Microsoft recommends to upgrade your solution to .NET 4.0 or above.<br/><br/></li>
<li>Change your implementation, so that, it does not create and destroy the <font color="brown">Ping</font> class object repeatedly. For this, move out the object creation out of the loop; or create the static instance of the class and use it globally, across the application. Here's a sample implementation of the code:</li><p>&#160;</p>
<div class="csharpcode">
<pre class="alt">Ping pingRequest = <span class="kwrd">new</span> Ping();</pre>
<pre>PingReply pingResponse;</pre>
<pre class="alt">&nbsp;</pre>
<pre>while(<span class="kwrd">true</span>)</pre>
<pre class="alt">{</pre>
<pre> pingResponse = pingRequest.Send(<span class="str">"www.kunal-chowdhury.com"</span>);</pre>
<pre class="alt">}</pre>
<pre>&nbsp;</pre>
</div><br/>
<li>Alternatively, you can call the <font color="brown"><strong>GC.KeepAlive</strong></font> on the <font color="brown">Ping</font> class object and ask the garbage collector not to destroy it. By calling this, the cause of the problem will be eliminated and the Access Violation Exception can be avoided. Here's the sample code on how to call the <font color="brown">GC.KeepAlive</font> method:</li><p>&#160;</p>
<div class="csharpcode">
<pre class="alt">while(<span class="kwrd">true</span>)</pre>
<pre>{</pre>
<pre class="alt"> Ping pingRequest = <span class="kwrd">new</span> Ping();</pre>
<pre> PingReply pingResponse = pingRequest.Send(<span class="str">"www.kunal-chowdhury.com"</span>);</pre>
<pre class="alt"> <b>GC.KeepAlive(pingRequest);</b></pre>
<pre>}</pre>
<pre class="alt">&nbsp;</pre>
</div>
</ul>
<p>I hope, if you are facing this issue, either of the above solutions will help you to resolve the error in your application. In case you are still facing it, try clubbing them. For my case, I was able to resolve it by setting a static object reference of the <font color="brown">Ping</font> class and calling the <font color="brown">GC.KeepAlive</font> method, after every <font color="brown">Send</font> call. What was the solution for your case?</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-21674199560247058532017-08-02T08:00:00.000+05:302017-08-02T08:00:26.770+05:30Parse or TryParse? Which one should I use?<p>It's often require to parse a string value to another data type, like integer, and there exists a confusion among the developers whether to use the <font color="brown">Parse</font> method or the <font color="brown">TryParse</font> method that the framework provides to us.</p>
<p>&#160;</p>
<p>In this post, we will discuss the difference between each of those two methods and guide you to understand and pick the preferable one. Continue reading to know more.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-uXcds1gJ7j0/WX9xeRJ0PHI/AAAAAAAAS2M/39U1aqwI7VgXVTmFOz5TJp-BhR_S6wR1gCLcBGAs/s600/parse-or-tryparse.png" class="postImage" alt="Parse or TryParse? Which one should I use?" title="Parse or TryParse? Which one should I use?"/></p>
<p>&#160;</p>
<p>It's a common interview question to ask a developer the difference between the <font color="brown"><strong>int.Parse</strong></font> and <font color="brown"><strong>int.TryParse</strong></font> methods. In most of the cases, I noticed that the developers get confused while answering this question. I often seen, while reviewing the code, people uses the <font color="brown">int.Parse</font> as it directly returns the value. But, there could be cases when the said method will fail and throw <font color="brown"><strong>Exception</strong></font>. Let's discuss in more detail.</p>
<p>&#160;</p>
<p>As the name itself says that the <font color="brown">Parse</font> method parses the string to return you the value, whereas the <font color="brown">TryParse</font> first tries to parse it and returns the original value if it succeeds. First one takes a single parameter as string and the other takes two parameters: one as an input string and the other as the out value. If <font color="brown">TryParse</font> succeeds, it returns true and provides you an option to check whether the parsing was successful.</p>
<h2>Let's learn about int.Parse(...)</h2>
<p>It's a common tendency to call the <font color="brown"><b>int.Parse(...)</b></font> method to parse a string to an integer. But wait! Did you ever check what happens when you pass a <font color="brown">null</font>, any invalid string or a large number? Let's discuss each one of them, so that, you can get a clear understanding.</p>
<p>&#160;</p>
<p>When you pass a <font color="brown">null</font> string as input parameter to <font color="brown">int.Parse(...)</font>, it will throw you an <font color="brown"><strong>ArgumentNullException</strong></font>:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="kwrd">null</span>;</pre>
<pre><span class="kwrd">int</span> outValue = <span class="kwrd">int</span>.Parse(value); <span class="rem">// throws ArgumentNullException</span></pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>When you pass a correct integer value as string, it will parse it and return you the value:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"999"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = <span class="kwrd">int</span>.Parse(value); <span class="rem">// works fine, returns 999</span></pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>When you pass a double value as string, instead of an integer, the outcome of it is a <font color="brown"><strong>FormatException</strong></font>:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"999.99"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = <span class="kwrd">int</span>.Parse(value); <span class="rem">// throws FormatException</span></pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>When it is unable to parse the string (like the below text) to integer, a <font color="brown"><strong>FormatException</strong></font> will trigger:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"kunal"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = <span class="kwrd">int</span>.Parse(value); <span class="rem">// throws FormatException</span></pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>When you pass a very large integer value as string to the method, it will throw <font color="brown"><strong>OverflowException</strong></font> as it can't parse it to integer:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"9999999999999999"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = <span class="kwrd">int</span>.Parse(value); <span class="rem">// throws OverflowException</span></pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<h2>Let's learn about int.TryParse(..., ...)</h2>
<p>Unlike the <font color="brown">Parse</font> method, <font color="brown"><b>int.TryParse(..., ...)</b></font> does not directly return you the value. Instead, it returns whether the parsing was successful or not. The second parameter passed to this method is an out parameter, that gets filled by the method with the parsed value.</p>
<p>&#160;</p>
<p>When you pass a null value to <font color="brown">TryParse</font>, instead of throwing <font color="brown"><b>ArgumentNullException</b></font>, it returns false and fills the out value to '0' (zero):</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="kwrd">null</span>;</pre>
<pre><span class="kwrd">int</span> outValue = 0;</pre>
<pre class="alt"><span class="kwrd">bool</span> status = <span class="kwrd">int</span>.TryParse(value, <span class="kwrd">out</span> outValue); <span class="rem">// outValue = 0</span></pre>
<pre>Console.WriteLine(<span class="str">"Status: {0}, Value: {1}"</span>, status, outValue);</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>When you pass a correct integer value as string, it returns true and fills the out value with the parsed result:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"999"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = 0;</pre>
<pre class="alt"><span class="kwrd">bool</span> status = <span class="kwrd">int</span>.TryParse(value, <span class="kwrd">out</span> outValue); <span class="rem">// outValue = 999</span></pre>
<pre>Console.WriteLine(<span class="str">"Status: {0}, Value: {1}"</span>, status, outValue);</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>Passing a double, does not throw <font color="brown"><b>FormatException</b></font>. Rather, it returns false and fills the out value with '0' (zero):</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"999.99"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = 0;</pre>
<pre class="alt"><span class="kwrd">bool</span> status = <span class="kwrd">int</span>.TryParse(value, <span class="kwrd">out</span> outValue); <span class="rem">// outValue = 0</span></pre>
<pre>Console.WriteLine(<span class="str">"Status: {0}, Value: {1}"</span>, status, outValue);</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>Similarly, if you pass a non-integer value, it returns false and fills out value with '0' (zero):</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"kunal"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = 0;</pre>
<pre class="alt"><span class="kwrd">bool</span> status = <span class="kwrd">int</span>.TryParse(value, <span class="kwrd">out</span> outValue); <span class="rem">// outValue = 0</span></pre>
<pre>Console.WriteLine(<span class="str">"Status: {0}, Value: {1}"</span>, status, outValue);</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>When you pass a large integer number as string, which it can't parse, will return false instead of throwing <font color="brown"><b>OverflowException</b></font> and will fill the out value with '0' (zero):</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> value = <span class="str">"9999999999999999"</span>;</pre>
<pre><span class="kwrd">int</span> outValue = 0;</pre>
<pre class="alt"><span class="kwrd">bool</span> status = <span class="kwrd">int</span>.TryParse(value, <span class="kwrd">out</span> outValue); <span class="rem">// outValue = 0</span></pre>
<pre>Console.WriteLine(<span class="str">"Status: {0}, Value: {1}"</span>, status, outValue);</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>Based on the returned value, you can check whether the parsing was successful. If succeeded, you can use the out value in subsequent lines of code. A point to note that, you need to initialize the out value before passing it to the <font color="brown">TryParse</font> method.</p>
<h2>End Note</h2>
<p>I hope that, you understood the difference between <font color="brown">Parse</font> and <font color="brown">TryParse</font> methods from the above post. Which one do you prefer now while writing code to parse a numeric string to number? It's <font color="brown"><b>TryParse</b></font> method, for sure! Do let me know, if you still have any doubts/queries.</p>
<p>&#160;</p>
<p>Another point to note that, it's applicable to all conversion from string to integer, double, long etc. For example: if you want to parse a string to double, call <font color="brown">double.TryParse(..., ...)</font>; to convert a string to long, call <font color="brown">long.TryParse(..., ...)</font> similarly.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com4tag:blogger.com,1999:blog-2452629445557820138.post-24714957145638229742017-07-31T08:00:00.000+05:302017-07-31T08:00:12.957+05:30What's the difference between null string and string.Empty?<p>Let's continue our 'Back to Basics' series. It's often an interview question to get an idea of the basic knowledge of a candidate. This is one of the simple question that an interviewer may ask during an interview and you should also know this while writing your code.</p>
<p>&#160;</p>
<p>In this post, we are again going to discuss on the basics and this time we will learn the difference between null string and empty string.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-7gtaBktKrMk/WXi9W1HSkxI/AAAAAAAAS1E/ud6wCbNFkMwMeOidCD6BbLjxokNIORSygCLcBGAs/s600/null-string-empty.png" class="postImage" alt="What's the difference between null string and string.Empty? (www.kunal-chowdhury.com)" title="What's the difference between null string and string.Empty? (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>&#160;</p>
<p>When you set the value of a string variable to '<b>null</b>', it defines itself as non-initialized variable. As a result, you can't call any of its methods or properties as calling anything on top of a null value will always throw '<font color="brown"><strong>NullReferenceException</strong></font>' and you must be already familiar to that.</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> nullString = <span class="kwrd">null</span>;</pre>
</div></p>
<p>&#160;</p>
<p>On the other hand, an empty string contains zero characters in a valid instance of the <strong>System.String</strong> class. You can create an empty string either by assigning a text value having no character in it (for example, "") or by directly setting '<font color="brown"><strong>string.Empty</strong></font>' as its value.</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">string</span> emptyString1 = <span class="str">""</span>;</pre>
<pre><span class="kwrd">string</span> emptyString2 = <span class="kwrd">string</span>.Empty;</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>The value of '<font color="brown"><strong>string.Empty</strong></font>' field, defined under '<b>System</b>' namespace, is the zero-length string i.e. "". In code, use this field whenever you want to assign or initialize a string variable to an empty string. In a very rare case, you may need to initialize a string variable as '<b>null</b>'.</p>
<p>&#160;</p>
<p>Was the post helpful? Do let us know below in the comments section. Until the next post, checkout the other posts that I already published. Have a great day!</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-26981845464859919262017-07-27T21:44:00.000+05:302017-07-28T07:42:25.072+05:30Book on Mastering Visual Studio 2017 has been published and available!<p>It gives me immense pleasure to announce that, my book titled '<a href="https://www.packtpub.com/application-development/mastering-visual-studio-2017" target="_blank">Mastering Visual Studio 2017</a>' has been published today. It was a great journey, with months of efforts. Thanks to Packt Publisher for the opportunity to write for them. Sincere thanks to the editorial team and the reviewer.</p>
<p>&#160;</p>
<p>By reading this book, you will learn not only what Visual Studio 2017 offers, but also what it takes to put it to work for your project.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-jE_beIbOans/WXoL3il7d6I/AAAAAAAAS1k/mArzeALAaZA5SZ_wyM8ebLg3-reBQWAyQCLcBGAs/s600/mastering-visual-studio-2017-book-cover.png" class="postImage" alt="Book on Mastering Visual Studio 2017 has been published and available! (www.kunal-chowdhury.com)" title="Book on Mastering Visual Studio 2017 has been published and available! (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>Visual Studio 2017 is the all-new IDE released by Microsoft for developers, targeting Microsoft and other platforms to build stunning Windows and web apps. Learning how to effectively use this technology can enhance your productivity while simplifying your most common tasks, allowing you more time to focus on your project. With this book, you will learn not only what VS2017 offers, but also what it takes to put it to work for your projects.</p>
<p>&#160;</p>
<p>Visual Studio 2017 is packed with improvements that increase productivity, and this book will get you started with the new features introduced in Visual Studio 2017 IDE and C# 7.0. Next, you will learn to use XAML tools to build classic WPF apps, and UWP tools to build apps targeting Windows 10. Later, you will learn about .NET Core and then explore NuGet, the package manager for the Microsoft development platform. Then, you will familiarize yourself with the debugging and live unit testing techniques that comes with the IDE. Finally, you'll adapt Microsoft's implementation of cloud computing with Azure, and the Visual Studio integration with Source Control repositories.</p>
<p>&#160;</p>
<p class="infoGreen"><font size="+1">You can buy the book from: <a href="https://www.packtpub.com/application-development/mastering-visual-studio-2017" target="_blank"><b>Packt Publisher</b></a>, <a href="http://amzn.to/2uFTRy8" target="_blank"><b>Amazon (US)</b></a>, <a href="http://amzn.to/2vbnXwu" target="_blank"><b>Amazon (IN)</b></a></font></p>
<h2>What You Will Learn</h2>
<ul>
<li>Learn what's new in the Visual Studio 2017 IDE, C# 7.0, and how it will help developers to improve their productivity</li>
<li>Learn the workloads and components of the new installation wizard and how to use the online and offline installer</li>
<li>Build stunning Windows apps using Windows Presentation Foundation (WPF) and Universal Windows Platform (UWP) tools</li>
<li>Get familiar with .NET Core and learn how to build apps targeting this new framework</li>
<li>Explore everything about NuGet packages</li>
<li>Debug and test your applications using Visual Studio 2017</li>
<li>Accelerate cloud development with Microsoft Azure</li>
<li>Integrate Visual Studio with most popular source control repositories, such as TFS and GitHub</li>
</ul>
<h2>What this book covers (chapter wise)</h2>
<p><b>Chapter 1: <i>What's new in Visual Studio 2017 IDE</i></b>, focuses on the new IDE specific changes incorporated in Visual Studio 2017 and how these will help the developers to improve their productivity. Starting from installation, it will cover various workloads and components part of the installer and then guide you to sync your IDE settings, followed by the new features.</p>
<p>&#160;</p>
<p><b>Chapter 2: <i>What's new in C# 7.0</i></b>, provides in depth knowledge to help you learn the latest changes part of C# 7.0. This chapter will guide you through a no. of simple code snippets to help you to learn quickly and become proficient to deliver your code.</p>
<p>&#160;</p>
<p><b>Chapter 3: <i>Building applications for Windows using XAML Tools</i></b>, focuses on XAML based WPF (Windows Presentation Foundation) applications for Windows. This will help you to learn the WPF architecture, XAML syntax, various layouts, data bindings, converters, triggers and guide you through building professional applications from scratch.</p>
<p>&#160;</p>
<p><b>Chapter 4: <i>Building applications for Windows 10 using UWP Tools</i></b>, provides a deeper insight to build XAML based applications targeting Universal Windows Platform (UWP). This is the latest technology platform from Microsoft and the base for Windows 10 specific devices (mobile, PC, Xbox, IoT etc.). This chapter will guide you to learn the generic design principles of UWP apps, followed by designing and styling applications. Later in the chapter, it will guide you to prepare apps to publish to Windows Store.</p>
<p>&#160;</p>
<p><b>Chapter 5: <i>Building application with .NET Core</i></b>, gives you a quick lap around the new Framework and guide you to create, build, run and publish .NET Core applications. This chapter will cover in depth knowledge on Framework Dependent Deployments and Self-Contained Deployments. Later, it will guide you to publish ASP.NET Core application to Windows Azure.</p>
<p>&#160;</p>
<p><b>Chapter 6: <i>Managing NuGet packages</i></b>, focuses on the NuGet package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers. Here we will learn how to create NuGet package, publish to a gallery and test it.</p>
<p>&#160;</p>
<p><b>Chapter 7: <i>Debugging applications with Visual Studio 2017</i></b>, focuses on giving you in depth understanding on the different debugging tools present inside Visual Studio. It's the core part of every code development. The much you are comfortable with code debugging, the best code that you can write/maintain. This chapter will help you to learn the debugging process with Visual Studio 2017.</p>
<p>&#160;</p>
<p><b>Chapter 8: <i>Testing applications with Visual Studio 2017</i></b>, provides a deeper insight to Live Unit Testing, which is a new module in Visual Studio 2017. It automatically runs the impacted unit tests in the background as you edit code and then visualizes the results with code coverage, live in the editor. This chapter will help you to get proficiency in building live unit testing with Visual Studio 2017.</p>
<p>&#160;</p>
<p><b>Chapter 9: <i>Accelerate cloud development with Windows Azure</i></b>, will help you to easily understand the cloud computing basics, that includes Microsoft Azure which is an open, flexible, enterprise-grade cloud computing platform. It basically delivers IaaS (Infrastructure as a Service), PaaS (Platform as a Service) and SaaS (Software as a Service). This chapter will guide you to create Azure websites and Mobile app services and then integrating it to a Windows application.</p>
<p>&#160;</p>
<p><b>Chapter 10: <i>Working with source controls</i></b>, will demonstrate you the steps to manage your code with versioning support in a source control repository. Source Control is a component of software configuration management, source repository and version management system. If you are building enterprise level applications in a distributed environment, you must use it to keep your code in a safe vault. This chapter will guide you to learn how easy it is to use Git and TFS managing your code, directly from Visual Studio.</p>
<p>&#160;</p>
<p class="infoGreen"><font size="+1">You can buy the book from: <a href="https://www.packtpub.com/application-development/mastering-visual-studio-2017" target="_blank"><b>Packt Publisher</b></a>, <a href="http://amzn.to/2uFTRy8" target="_blank"><b>Amazon (US)</b></a>, <a href="http://amzn.to/2vbnXwu" target="_blank"><b>Amazon (IN)</b></a></font></p>
<p>&#160;</p>
<p>I hope, you will enjoy reading the book. Please share your reviews/feedback.</p>
<p>&#160;</p>
<p style="display:none;visible:false;"><img src="https://3.bp.blogspot.com/-v-S87dl_RhE/WXoLtgBiFqI/AAAAAAAAS1g/4Ub6-6_oemgFDjXJcBBBgLXyKKOSjFKBQCLcBGAs/s600/mastering-visual-studio-2017.png" class="postImage" alt="Book on Mastering Visual Studio 2017 has been published and available! (www.kunal-chowdhury.com)" title="Book on Mastering Visual Studio 2017 has been published and available! (www.kunal-chowdhury.com)" style="display:none;visible:false;"/></p>
<p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-30913938605261281062017-07-27T00:02:00.000+05:302017-07-27T00:02:07.834+05:30Windows 10 Insiders Preview Build 16251 got some new improvements<p>Microsoft, today announced a new PC build 16251 for the Windows Insiders in the Fast Ring, from the RS3 (Redstone 3) development branch. And thus, moving towards one step forward to the Windows 10 Fall Creators Update, which is expected to release within few months.</p>
<p>&#160;</p>
<p>Along with this new PC build, they have also announced a new build 15235 for mobile devices. In this post, we are going to list the new features that you can see in the new PC build.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-bVG-0umro1w/WXjX_Ha3K4I/AAAAAAAAS1U/kBK-6fodsNIk8hGq6uTj91OxNNdoamlpgCLcBGAs/s600/windows-10-build-16251.png" class="postImage" alt="Windows 10 Insiders Preview Build 16251 got some new improvements (www.kunal-chowdhury.com)" title="Windows 10 Insiders Preview Build 16251 got some new improvements (www.kunal-chowdhury.com)"/></p>
<h2>What's new and improved in PC build 16251:</h2>
<p>In the new PC build (16251) for fast ring Windows Insiders, you are going to see the following new key improvements:</p>
<ul>
<li>With this new build (16251), you will be able to link your phone to your PC, which is currently available for Android phones. Support for Android devices are going to come soon.</li>
<li>Once you link your phone to the PC, you will be able to continue your current session from your phone to the connected PC.</li>
<li>After you link your phone, just go to your phone and start browsing the web. When you are at a website which you want to view on your PC, simply invoke the native share experience on your phone and share the website to the '<font color="brown">Continue on PC</font>" option.</li>
<li>Now you can view the results that Cortana has for you without launching the web browser.</li>
<li>Now you can use Cortana to turn off, restart, lock, or sign-out Windows. Just use your voice and try out the followings: "Hey Cortana, restart PC", "Hey Cortana, turn off PC", "Hey Cortana, sign out" and "Hey Cortana, lock PC".</li>
<li>You can now use sign-in info to apply settings after a restart or update. Under the Privacy section of the Sign-in options page of your Settings, you can disable and re-enable using the option.</li>
</ul>
<p>Apart from the above new improvements, you will find a bunch of fixes part of this build 16251. Checkout the original '<a href="https://blogs.windows.com/windowsexperience/2017/07/26/announcing-windows-10-insider-preview-build-16251-pc-build-15235-mobile" target="_blank">Release Notes</a>', shared by Microsoft to get the list of other changes and fixes.</p>
<h2>Known Issues in PC build 16251:</h2>
<p>As it is from developer branch, and the Windows team is still working hard on the new changes and fixes, there exists few 'Known and Unknown Issues'. So, before installing this build, make sure that you read all the known issues that has been already reported by Microsoft. Here you can find the known issues, part of the release notes:</p>
<ul>
<li>If you installed Builds 16226-16237 and upgrade to this build, Storage Spaces will not work correctly. While Build 16241 contained a fix for the general reported issue with Storage Spaces in that build range, we discovered that the fix only applies for computers not already in the bad state, and need to do some extra work to return those already impacted to the good state. Special thanks to the Insiders that have helped us investigate this!</li>
<li>Trying to use the dictation hotkey (WIN + H) in UWP apps won’t work – you’ll see the UI come up and immediately dismiss. If you’d still like to use dictation, the microphone in the touch keyboard will work. You can right-click the Taskbar for an option to show the touch keyboard button if it’s not already visible.</li>
<li>We’re investigating your reports that after upgrading to the latest Insider Preview builds, some network settings are lost and revert to default settings. Static IP address configuration is reverted to DHCP. Networks which were marked as private are reverted to public. After the upgrade you will need to manually readjust your network settings back to your preferred settings.</li>
<li>Start, Action Center and notification toasts may at times have a background that is 100% transparent. A fix will be available in later flight – for now, if you encounter this issue, try ending ShellExperienceHost.exe via Task Manager or rebooting to resolve the issue.</li>
<li>Connecting to a VPN using a solution downloaded from the Windows Store may result in a system crash.</li>
<li>The battery flyout might show unexpected text for the % charged (specifically “%1!s!%2!s!% until fully charged”).</li>
</ul>
<p>&#160;</p>
<p><font color="gray" size="-1">Source: </font><a href="https://blogs.windows.com/windowsexperience/2017/07/26/announcing-windows-10-insider-preview-build-16251-pc-build-15235-mobile" target="_blank"><font size="-1">Release Notes, published by Microsoft</font></a></p>
<p>&#160;</p><p>&#160;</p><div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-55483080002347846382017-07-25T08:00:00.000+05:302017-07-25T08:00:14.349+05:30Have you heard about StringCollection class in .NET?<p><strong>StringCollection</strong> class is a spcialized collection type present in .NET Framework class libraries. The name itself represents it as a collection of strings. It exposes common methods and properties to manage string collection.</p>
<p>&#160;</p>
<p>If you do not know about this class, in this post we are going learn about it's properties, methods and learn how to use it.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-epIMAnsJ4R0/WXTRe69NS-I/AAAAAAAAS0Q/UAKB4yXqQ3sq087lKxZmJQVfCVc_nKUWQCLcBGAs/s600/dotnet-stringcollection.png" class="postImage" alt="Have you heard about StringCollection class in .NET? (www.kunal-chowdhury.com)" title="Have you heard about StringCollection class in .NET? (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>The class '<font color="brown"><strong>StringCollection</strong></font>' is defined in the '<font color="brown"><strong>System.Collections.Specialized</strong></font>' namespace of the .NET Framework class library. It implements <strong>IList</strong>, <strong>ICollection</strong> and <strong>IEnumerable</strong> interfaces to provide common set of collection APIs.</p>
<p>&#160;</p>
<p>Here is the definition of the '<font color="brown"><strong>StringCollection</strong></font>' class, that exposes few additional properties and methods to perform add/remove operations to it:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">namespace</span> System.Collections.Specialized</pre>
<pre>{</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">class</span> StringCollection : IList, ICollection, IEnumerable</pre>
<pre> {</pre>
<pre class="alt"> <span class="kwrd">public</span> StringCollection();</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">string</span> <span class="kwrd">this</span>[<span class="kwrd">int</span> index] { <span class="kwrd">get</span>; <span class="kwrd">set</span>; }</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="preproc">#region</span> Public Properties</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">int</span> Count { <span class="kwrd">get</span>; }</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">bool</span> IsReadOnly { <span class="kwrd">get</span>; }</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">bool</span> IsSynchronized { <span class="kwrd">get</span>; }</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">object</span> SyncRoot { <span class="kwrd">get</span>; }</pre>
<pre class="alt"> <span class="preproc">#endregion</span> Public Properties</pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="preproc">#region</span> Public Methods</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">int</span> Add(<span class="kwrd">string</span> value);</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">void</span> AddRange(<span class="kwrd">string</span>[] value);</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">void</span> Clear();</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">bool</span> Contains(<span class="kwrd">string</span> value);</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">void</span> CopyTo(<span class="kwrd">string</span>[] array, <span class="kwrd">int</span> index);</pre>
<pre class="alt"> <span class="kwrd">public</span> StringEnumerator GetEnumerator();</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">int</span> IndexOf(<span class="kwrd">string</span> value);</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">void</span> Insert(<span class="kwrd">int</span> index, <span class="kwrd">string</span> value);</pre>
<pre> <span class="kwrd">public</span> <span class="kwrd">void</span> Remove(<span class="kwrd">string</span> value);</pre>
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">void</span> RemoveAt(<span class="kwrd">int</span> index);</pre>
<pre> <span class="preproc">#endregion</span> Public Methods</pre>
<pre class="alt"> }</pre>
<pre>}</pre>
<pre class="alt">&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>Just like other collections, you can perform add/insert to this collection type. For an addition of a single element, you can call the '<b>Add</b>' method; but to perform addition an entire string array, you can call the '<b>AddRange</b>' method. You can also call '<b>Insert</b>' method to insert any string element at a specific index position of the collection.</p>
<p>&#160;</p>
<p>To remove an element from the collection, you can either call the Remove/RemoveAt method. The '<b>Remove</b>' method removes the first occurance of the given string, whereas the '<b>RemoveAt</b>' method removes a string specified at the given index location. To remove all the elements from the collection, call the '<b>Clear</b>' method.</p>
<p>&#160;</p>
<p>Here is a code snippet of the simple examples to perform basic operations like add/insert/remove/clear on the <font color="brown"><strong>StringCollection</strong></font> class:</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="kwrd">var</span> stringCollection = <span class="kwrd">new</span> StringCollection();</pre>
<pre>&nbsp;</pre>
<pre class="alt">stringCollection.Add(<span class="str">"1"</span>);</pre>
<pre>stringCollection.Add(<span class="str">"2"</span>);</pre>
<pre class="alt">stringCollection.Add(<span class="str">"3"</span>);</pre>
<pre>PrintValues(stringCollection);</pre>
<pre class="alt">&nbsp;</pre>
<pre><span class="kwrd">var</span> stringArray = <span class="kwrd">new</span> <span class="kwrd">string</span>[] { <span class="str">"4"</span>, <span class="str">"5"</span>, <span class="str">"6"</span> };</pre>
<pre class="alt">stringCollection.AddRange(stringArray);</pre>
<pre>PrintValues(stringCollection);</pre>
<pre class="alt">&nbsp;</pre>
<pre>stringCollection.Remove(<span class="str">"4"</span>);</pre>
<pre class="alt">PrintValues(stringCollection);</pre>
<pre>&nbsp;</pre>
<pre class="alt">stringCollection.Insert(3, <span class="str">"4"</span>);</pre>
<pre>PrintValues(stringCollection);</pre>
<pre class="alt">&nbsp;</pre>
<pre>stringCollection.Clear();</pre>
<pre class="alt">PrintValues(stringCollection);</pre>
<pre>&nbsp;</pre>
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> PrintValues(StringCollection stringCollection)</pre>
<pre>{</pre>
<pre class="alt"> Console.WriteLine();</pre>
<pre> Console.WriteLine();</pre>
<pre class="alt"> <span class="kwrd">foreach</span> (<span class="kwrd">var</span> stringValue <span class="kwrd">in</span> stringCollection)</pre>
<pre> {</pre>
<pre class="alt"> Console.Write(stringValue + <span class="str">" "</span>);</pre>
<pre> }</pre>
<pre class="alt">}</pre>
<pre>&nbsp;</pre>
</div></p>
<p>&#160;</p>
<p>I hope that the post was clear and easy to understand. Did you learn something new today? Do share with us. Sharing is caring. So, don't forget to share this post in your channel and help your friend or colleague to learn something new.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com8tag:blogger.com,1999:blog-2452629445557820138.post-47119841314650357502017-07-22T00:16:00.001+05:302017-07-23T21:18:58.280+05:30Solution for NPOI only supports BIFF8 format exception<p>In last few articles we have discussed about NPOI libraries for .NET. There could be some cases, while reading Excel files, you may get an exception with '<u>The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format</u>' as message.</p>
<p>&#160;</p>
<p>In this quick tip, we are going to discuss about this issue, the way to handle it and the way to read the same Excel workbook content.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-ucUHmPveM9k/WXJKzOEnfqI/AAAAAAAASzw/S0i3HXBVeZQDwnBaezCRLnw34ltBxxEjwCLcBGAs/s800/npoi-supports-biff8-format.png" class="postImage" alt="Solution for 'NPOI only supports BIFF8 format' exception (www.kunal-chowdhury.com)" title="Solution for 'NPOI only supports BIFF8 format' exception (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>This case may arise when you are trying to read an Excel document content using either of the <a href="/2017/07/npoi-excel-2007.html" target="_blank">'<b>XSSFExcelExtractor</b>' for Excel 2007</a> format or <a href="/2017/07/npoi-excel-97-2003.html" target="_blank">'<b>ExcelExtractor</b>' for Excel 97-2003</a> format. The root cause behind this would be an older Excel document that you are trying to read and the POI library does not support reading this file type. In such case, it will return the following exception message: '<font color="brown"><u><i>The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)</i></u></font>'.</p>
<p>&#160;</p>
<p><font color="Red" size="+1"><b>You may like to read:</b></font></p>
<hr/>
<ul>
<li><a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank"><b>How to read Excel document using C#/.NET (COM APIs)?</b></a></li>
<li><a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>How to read Excel 2007 document (XLSX) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-97-2003.html" target="_blank"><b>How to read Excel 97-2003 document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95.html" target="_blank"><b>How to read Excel 95 or older document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95-biff5.html" target="_blank"><b>Solution for 'POI only supports BIFF8 format' exception</b></a></li>
</ul>
<hr/>
<p>&#160;</p>
<p>The stack trace for the above exception will look similar to the below snippet, with an exception object '<strong>OldExcelFormatException</strong>':</p>
<p>&#160;</p>
<p><pre class="csharpcode">
<font color="gray"><b><i>NPOI.HSSF.OldExcelFormatException:<br/>The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format.<br/>POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)</i></b><i>
at NPOI.HSSF.UserModel.HSSFWorkbook.GetWorkbookDirEntryName(DirectoryNode directory)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, Boolean preserveNodes)
at NPOI.HSSF.UserModel.HSSFWorkbook..ctor(POIFSFileSystem fs)
at NPOI.HSSF.Extractor.ExcelExtractor..ctor(POIFSFileSystem fs)</i></font></pre></p>
<p>&#160;</p>
<p>If you face this, you will have to handle this. If you are using NPOI library, it provides a different API class to read such older Excel documents (BIFF5 format). You will have to use the '<a href="/2017/07/npoi-excel-95.html" target="_blank"><b>OldExcelExtractor</b></a>' class, which is present in the '<b>NPOI.HSSF.Extractor</b>' namespace. We have already discussed about it, in the last post, which you can read over here: <a href="/2017/07/npoi-excel-95.html" target="_blank"><b>How to read Excel 95 or older document (XLS) using NPOI libraries?</b></a>. Point to note that, this will not able to read all the content from that Excel file due to technical limitation.</p>
<p>&#160;</p>
<p>Do let me know, if you are facing any other difficulties. I would be happy to help you. Don't forget to share your views/comments on this.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-76148412806969339002017-07-19T08:00:00.000+05:302017-07-23T21:19:10.064+05:30Here's how to read Excel 95 or older document (XLS) using NPOI libraries<p>In the last two articles, we have learned how to use the NPOI library to read <a href="/2017/07/npoi-excel-2007.html" target="_blank">Excel 2007 (.xlsx)</a> and <a href="/2017/07/npoi-excel-97-2003.html" target="_blank">Excel 97-2003 (.xls)</a> file format. We have also discussed more about the APIs and shared the code snippet for you to understand it easily.</p>
<p>&#160;</p>
<p>In this article, we will learn how to read Excel 95 and older workbooks easily using the free Apache NPOI libraries in your C#/.NET applications.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-c7fYiiQPBoE/WWeaI0BbshI/AAAAAAAASzA/WmEiBabRxYI3YHcFwE4eokgNpgvAA7eCACLcBGAs/s1600/npoi-excel-95.png" class="postImage" alt="Here's how to read Excel 95 or older document (XLS) using NPOI libraries (www.kunal-chowdhury.com)" title="Here's how to read Excel 95 or older document (XLS) using NPOI libraries (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<h2>Basic concepts about NPOI library</h2>
<p>Before starting with the code, you should have the basic knowledge about the NPOI library. <strong>NPOI is the .NET version of POI Java project</strong>, originally hosted at <a href="http://poi.apache.org" target="_blank">http://poi.apache.org</a>. It is a free, open source project which can help you to read/write Word, Excel, PowerPoint document files. You can find the source code of NPOI project hosted at <a href="https://github.com/tonyqus/npoi" target="_blank">https://github.com/tonyqus/npoi</a>. The libraries can be downloaded from NuGet from this URL: <a href="https://www.nuget.org/packages/NPOI" target="_blank">https://www.nuget.org/packages/NPOI</a>.</p>
<p>&#160;</p>
<p><font color="Red" size="+1"><b>You may like to read:</b></font></p>
<hr/>
<ul>
<li><a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank"><b>How to read Excel document using C#/.NET (COM APIs)?</b></a></li>
<li><a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>How to read Excel 2007 document (XLSX) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-97-2003.html" target="_blank"><b>How to read Excel 97-2003 document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95.html" target="_blank"><b>How to read Excel 95 or older document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95-biff5.html" target="_blank"><b>Solution for 'POI only supports BIFF8 format' exception</b></a></li>
</ul>
<hr/>
<p>&#160;</p>
<h2>Reading Excel 95 and older document format using NPOI</h2>
<p>In previous posts we have seen that, we need to use the <a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>NPOI.XSSF.Extractor.XSSFExcelExtractor</b></a> class to read 'Excel 2007' format and we need to use the <a href="/2017/07/npoi-excel-97-2003.html" target="_blank"><b>NPOI.HSSF.ExcelExtractor</b></a> class to read 'Excel 97-2003' file format. But for 'Excel 95 and older' file formats, the API class is different. In this case, we will have to use <b>NPOI.HSSF.Extractor.OldExcelExtractor</b> class from the NPOI library. The exposed property '<b>Text</b>' provides you the document content that includes all the sheets.</p>
<p>&#160;</p>
<p>The API 'OldExcelExtractor' takes an input of type <b>System.IO.FileStream</b>. To read the content of the Excel 95 or older workbooks (Excel 5.0 or older), first create the instance of the FileStream passing the file path as input. Then create the instance of OldExcelExtractor and pass the file stream to it. Then, call the property '<b>Text</b>' to get the content of the document. Here's the code for your easy reference. You may have to handle the exceptions that you may encounter while accessing/reading the file.</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="rem">/// &lt;summary&gt;Gets the text from 95 format excel file.&lt;/summary&gt;</span></pre>
<pre><span class="rem">/// &lt;param name="filePath"&gt;The file path of the Excel sheet.&lt;/param&gt;</span></pre>
<pre class="alt"><span class="rem">/// &lt;returns&gt;The text contents of the Excel sheets&lt;/returns&gt;</span></pre>
<pre><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetTextFromExcel95Format(<span class="kwrd">string</span> filePath)</pre>
<pre class="alt">{</pre>
<pre> FileStream fileStream = <span class="kwrd">null</span>;</pre>
<pre class="alt"> OldExcelExtractor excelExtractor = <span class="kwrd">null</span>;</pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="kwrd">try</span></pre>
<pre> {</pre>
<pre class="alt"> <span class="kwrd">using</span> (fileStream = <span class="kwrd">new</span> FileStream(filePath, FileMode.Open))</pre>
<pre> {</pre>
<pre class="alt"> excelExtractor = <span class="kwrd">new</span> OldExcelExtractor(fileStream);</pre>
<pre> <span class="kwrd">return</span> excelExtractor.Text;</pre>
<pre class="alt"> }</pre>
<pre> }</pre>
<pre class="alt"> <span class="kwrd">catch</span></pre>
<pre> {</pre>
<pre class="alt"> <span class="rem">// handle the exception</span></pre>
<pre> }</pre>
<pre class="alt"> <span class="kwrd">finally</span></pre>
<pre> {</pre>
<pre class="alt"> <span class="kwrd">if</span> (excelExtractor != <span class="kwrd">null</span>)</pre>
<pre> {</pre>
<pre class="alt"> excelExtractor.Close();</pre>
<pre> excelExtractor = <span class="kwrd">null</span>;</pre>
<pre class="alt"> }</pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="kwrd">if</span> (fileStream != <span class="kwrd">null</span>)</pre>
<pre> {</pre>
<pre class="alt"> fileStream.Close();</pre>
<pre> fileStream.Dispose();</pre>
<pre class="alt"> fileStream = <span class="kwrd">null</span>;</pre>
<pre> }</pre>
<pre class="alt"> }</pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="kwrd">return</span> <span class="kwrd">string</span>.Empty;</pre>
<pre>}</pre>
</div></p>
<p>&#160;</p>
<p>I hope that the post was as useful as the previous posts. Also, I hope that the code shared above was clear and easy to understand. If you are facing any further issue, do let me know below. Don't forget to check my other posts published in this blog. Have a great day! Cheers!!!</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com2tag:blogger.com,1999:blog-2452629445557820138.post-13167445719811607622017-07-17T08:00:00.000+05:302017-07-23T21:19:22.277+05:30Here's how to read Excel 97-2003 document (XLS) using NPOI libraries<p>In the last article, we have discussed about the NPOI library and then learned <a href="/2017/07/npoi-excel-2007.html" target="_blank">how to read Excel 2007 file formats using the free, open sourced NPOI library</a>. I hope, the code snippet was clear and easy to understand.</p>
<p>&#160;</p>
<p>In this article, we will learn how to read Excel 97-2003 workbooks easily using the free Apache NPOI libraries in your C#/.NET applications.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-0xUdRU6mQWw/WWeUGb1mRgI/AAAAAAAASy4/wQWlsAmQNTk8G4Gz07D0RxAZTrK-Vu2_gCLcBGAs/s800/npoi-excel-97-2003.png" class="postImage" alt="Here's how to read Excel 97-2003 document (XLS) using NPOI libraries (www.kunal-chowdhury.com)" title="Here's how to read Excel 97-2003 document (XLS) using NPOI libraries (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<h2>Basic concepts about NPOI library</h2>
<p>Before starting with the code, you should have the basic knowledge about the NPOI library. <strong>NPOI is the .NET version of POI Java project</strong>, originally hosted at <a href="http://poi.apache.org" target="_blank">http://poi.apache.org</a>. It is a free, open source project which can help you to read/write Word, Excel, PowerPoint document files. You can find the source code of NPOI project hosted at <a href="https://github.com/tonyqus/npoi" target="_blank">https://github.com/tonyqus/npoi</a>. The libraries can be downloaded from NuGet from this URL: <a href="https://www.nuget.org/packages/NPOI" target="_blank">https://www.nuget.org/packages/NPOI</a>.</p>
<p>&#160;</p>
<p><font color="Red" size="+1"><b>You may like to read:</b></font></p>
<hr/>
<ul>
<li><a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank"><b>How to read Excel document using C#/.NET (COM APIs)?</b></a></li>
<li><a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>How to read Excel 2007 document (XLSX) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-97-2003.html" target="_blank"><b>How to read Excel 97-2003 document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95.html" target="_blank"><b>How to read Excel 95 or older document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95-biff5.html" target="_blank"><b>Solution for 'POI only supports BIFF8 format' exception</b></a></li>
</ul>
<hr/>
<p>&#160;</p>
<h2>Reading Excel 97-2003 document format using NPOI</h2>
<p>In earlier post, related to 'Excel 2007' format, we learned about <a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>NPOI.XSSF.Extractor.XSSFExcelExtractor</b></a> class, which was used to extract the workbook content of that file type. But for the 'Excel 97-2003' file format, having file extension of .xls, the API is different. To read this type of workbooks, you will need to use the <b>NPOI.HSSF.ExcelExtractor</b> class. It extends base <b>POIOLE2TextExtractor</b> and inherits <b>IExcelExtractor</b> interface. The exposed property '<b>Text</b>' provides you the document content that includes all the sheets.</p>
<p>&#160;</p>
<p>The API 'ExcelExtractor' takes an input of type <b>NPOI.POIFS.FileSystem.POIFSFileSystem</b>, which again takes an inut of type <b>System.IO.FileStream</b>. To read the content of the Excel workbook, first create the instance of the FileStream passing the file path as input. Then create the instance of POIFSFileSystem and pass it to the ExcelExtractor. Then, call the property '<b>Text</b>' to get the content of the document. Here's the code for your easy reference. You may have to handle the exceptions that you encounter while accessing/reading the content.</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="rem">/// &lt;summary&gt;Gets the text from 97-2003 format excel file.&lt;/summary&gt;</span></pre>
<pre><span class="rem">/// &lt;param name="filePath"&gt;The file path of the Excel sheet.&lt;/param&gt;</span></pre>
<pre class="alt"><span class="rem">/// &lt;returns&gt;The text contents of the Excel sheets&lt;/returns&gt;</span></pre>
<pre><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetTextFromExcel97To2003Format(<span class="kwrd">string</span> filePath)</pre>
<pre class="alt">{</pre>
<pre> FileStream fileStream = <span class="kwrd">null</span>;</pre>
<pre class="alt"> POIFSFileSystem fileSystem = <span class="kwrd">null</span>;</pre>
<pre> ExcelExtractor excelExtractor = <span class="kwrd">null</span>;</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">try</span></pre>
<pre class="alt"> {</pre>
<pre> <span class="kwrd">using</span> (fileStream = <span class="kwrd">new</span> FileStream(filePath, FileMode.Open))</pre>
<pre class="alt"> {</pre>
<pre> fileSystem = <span class="kwrd">new</span> POIFSFileSystem(fileStream);</pre>
<pre class="alt"> excelExtractor = <span class="kwrd">new</span> ExcelExtractor(fileSystem);</pre>
<pre> excelExtractor.IncludeBlankCells = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre class="alt"> excelExtractor.IncludeCellComments = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre> excelExtractor.IncludeHeaderFooter = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre class="alt"> excelExtractor.IncludeSheetNames = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="kwrd">return</span> excelExtractor.Text;</pre>
<pre> }</pre>
<pre class="alt"> }</pre>
<pre> <span class="kwrd">catch</span></pre>
<pre class="alt"> {</pre>
<pre> <span class="rem">// handle the exception</span></pre>
<pre class="alt"> }</pre>
<pre> <span class="kwrd">finally</span></pre>
<pre class="alt"> {</pre>
<pre> <span class="kwrd">if</span> (excelExtractor != <span class="kwrd">null</span>)</pre>
<pre class="alt"> {</pre>
<pre> excelExtractor.Close();</pre>
<pre class="alt"> excelExtractor = <span class="kwrd">null</span>;</pre>
<pre> }</pre>
<pre class="alt">&nbsp;</pre>
<pre> fileSystem = <span class="kwrd">null</span>;</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">if</span> (fileStream != <span class="kwrd">null</span>)</pre>
<pre class="alt"> {</pre>
<pre> fileStream.Close();</pre>
<pre class="alt"> fileStream.Dispose();</pre>
<pre> fileStream = <span class="kwrd">null</span>;</pre>
<pre class="alt"> }</pre>
<pre> }</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">return</span> <span class="kwrd">string</span>.Empty;</pre>
<pre class="alt">}</pre>
</div></p>
<p>&#160;</p>
<p>Was the post helpful? Do let us know. In the next post, we will learn how to read Excel 95 format (<b>BIFF5 format</b>) using the free, open source NPOI library. Don't forget to read and share the post that I publish. Have a great day!</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com2tag:blogger.com,1999:blog-2452629445557820138.post-58902443332113064522017-07-14T00:01:00.000+05:302017-07-13T23:38:15.074+05:30Windows 10 PC build 16241 rolls out to insiders in the Fast ring<p>Windows 10 Insider Preview build 16241 is being rolled out to Windows Insiders in the fast ring. It includes a no. of new improvements to the Windows Shell. Apart from that, Windows 10 Mobile Insider Preview build 15230, has been also released.</p>
<p>&#160;</p>
<p>Check this post to know the latest improvements, fixes in this new PC build 16241. Don't forget to checkout the known issues before downloading this build.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-paVQMErt99Y/WWeujXgUR3I/AAAAAAAASzI/IHjpEZdm_HMlELm8vPZoyuJIixyWr_cygCLcBGAs/s800/windows-10-build-16241.png" class="postImage" alt="Windows 10 PC build 16241 rolls out to insiders in the Fast ring (www.kunal-chowdhury.com)" title="Windows 10 PC build 16241 rolls out to insiders in the Fast ring (www.kunal-chowdhury.com)"/></p>
<h2>Shell Improvements</h2>
<p><ul>
<li>You can now recover your pin and password from the lock screen. If you’re using an AADP or MSA account and you find yourself stuck at the login screen, you can now reset your password and PIN straight from here. Just click the 'Reset password' (for password) / 'I forgot my PIN' (for PIN) link and you’ll be prompted to go through the AAD or MSA flow to reset it.</li>
<li>The noise layer of Acrylic Material in XAML based apps has been softened.</li>
</ul></p>
<h2>Gaming Improvements</h2>
<p><ul>
<li>Fixed an issue preventing profile cards in the Xbox Live in-game experience from working.</li>
<li>Fixed an issue causing Game bar to crash while broadcasting.</li>
</ul></p>
<h2>Task Manager Improvements</h2>
<p><ul>
<li>Some design changes to the GPU section of Performance tab.</li>
<li>The GPU name is now shown on the left-hand side of the Performance tab for each GPU.</li>
<li>It is now by default set to the multi-engine view, which shows performance monitors for the four most active GPU engines.</li>
<li>There is now a total GPU memory text counter next to the dedicated and shared text counters at the bottom of the Performance tab.</li>
<li>The Direct X version now also contains the highest supported DX feature level.</li>
</ul></p>
<h2>Delivery Optimization Improvements</h2>
<p><ul>
<li>Now you can <a href="/2017/07/windows-10-delivery-optimization.html" target="_blank"><b>control the upload/download bandwidth of the Windows 10</b></a> updates using the Delivery Optimization.</li>
<li>Using the new <a href="/2017/07/windows-10-delivery-optimization.html" target="_blank"><b>Activity Monitor</b></a>, you can see the overall bandwidth used in downloads of OS Updates, including Feature and Quality updates, as well as Store App downloads and updates on your device.</li>
</ul></p>
<p>Apart from these core feature updates, the build also has many other improvements, fixes and changes. Checkout the <a href="https://blogs.windows.com/windowsexperience/2017/07/13/announcing-windows-10-insider-preview-build-16241-pc-build-15230-mobile" target="_blank">original blog post</a>, published by Windows Insiders chief Dona Sarkar, to read the entire 'Release Notes'.</p>
<p>&#160;</p>
<p>As it is from development branch, it contains few Known Issues. Don't forget to read them first before installing any new upgrade bits.</p>
<p>&#160;</p>
<p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-79273235442955592412017-07-13T00:05:00.000+05:302017-07-23T21:19:31.668+05:30Here's how to read Excel 2007 document (XLSX) using NPOI libraries<p>Recently, we have learned <a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank">how to read Excel workbooks using the Microsoft Office COM APIs</a>. As you may already know that the COM APIs are slow while performing operation, we will see another way to read the content which is faster.</p>
<p>&#160;</p>
<p>In this article, we will learn how to read Excel 2007 workbooks using the Apache NPOI libraries which is available freely to use in your application.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-bwJVS7NUpnw/WWZOJD-VHRI/AAAAAAAASyc/pcNrXxUj_z0-7zzrflzKmc4jusBUsQ0KACLcBGAs/s800/npoi-excel-2007.png" class="postImage" alt="Here's how to read Excel 2007 document (XLSX) using NPOI libraries (www.kunal-chowdhury.com)" title="Here's how to read Excel 2007 document (XLSX) using NPOI libraries (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<h2>Basic concepts about NPOI library</h2>
<p>Before starting with the code, you should have the basic knowledge about the NPOI library. <strong>NPOI is the .NET version of POI Java project</strong>, originally hosted at <a href="http://poi.apache.org" target="_blank">http://poi.apache.org</a>. It is a free, open source project which can help you to read/write Word, Excel, PowerPoint document files. You can find the source code of NPOI project hosted at <a href="https://github.com/tonyqus/npoi" target="_blank">https://github.com/tonyqus/npoi</a>. The libraries can be downloaded from NuGet from this URL: <a href="https://www.nuget.org/packages/NPOI" target="_blank">https://www.nuget.org/packages/NPOI</a>.</p>
<p>&#160;</p>
<p><font color="Red" size="+1"><b>You may like to read:</b></font></p>
<hr/>
<ul>
<li><a href="/2017/02/how-to-read-microsoft-excel-document.html" target="_blank"><b>How to read Excel document using C#/.NET (COM APIs)?</b></a></li>
<li><a href="/2017/07/npoi-excel-2007.html" target="_blank"><b>How to read Excel 2007 document (XLSX) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-97-2003.html" target="_blank"><b>How to read Excel 97-2003 document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95.html" target="_blank"><b>How to read Excel 95 or older document (XLS) using NPOI libraries?</b></a></li>
<li><a href="/2017/07/npoi-excel-95-biff5.html" target="_blank"><b>Solution for 'POI only supports BIFF8 format' exception</b></a></li>
</ul>
<hr/>
<p>&#160;</p>
<h2>Reading Excel 2007 document format using NPOI</h2>
<p>To read the 'Excel 2007' file format, i.e. the file having extension of .xlsx, you will need to use the <b>NPOI.XSSF.Extractor.XSSFExcelExtractor</b> class. It extends base <b>POIXMLTextExtractor</b> and inherits <b>IExcelExtractor</b> interface. The exposed property '<b>Text</b>' provides you the document content that includes all the sheets.</p>
<p>&#160;</p>
<p>To read the content of the said Excel file, create an instance of <b>XSSFExcelExtractor</b> by passing the file path to the constructor. Optionally you can include or exclude cell comments, header and footer information, sheet names to the output result. Now, call the <b>Text</b> property of the instance to read the file text. Code has been shared below, for easy reference. You may have to handle the exceptions that you encounter while accessing/reading the content.</p>
<p>&#160;</p>
<p><div class="csharpcode">
<pre class="alt"><span class="rem">/// &lt;summary&gt;Gets the text from extended excel file (Excel 2007 Format).&lt;/summary&gt;</span></pre>
<pre><span class="rem">/// &lt;param name="filePath"&gt;The file path of the Excel sheet.&lt;/param&gt;</span></pre>
<pre class="alt"><span class="rem">/// &lt;returns&gt;The text contents of the Excel sheets&lt;/returns&gt;</span></pre>
<pre><span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetTextFromExcel2007Format(<span class="kwrd">string</span> filePath)</pre>
<pre class="alt">{</pre>
<pre> XSSFExcelExtractor excelExtractor = <span class="kwrd">null</span>;</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">try</span></pre>
<pre class="alt"> {</pre>
<pre> excelExtractor = <span class="kwrd">new</span> XSSFExcelExtractor(filePath);</pre>
<pre class="alt"> excelExtractor.IncludeCellComments = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre> excelExtractor.IncludeHeaderFooter = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre class="alt"> excelExtractor.IncludeSheetNames = <span class="kwrd">false</span>; <span class="rem">// optional</span></pre>
<pre>&nbsp;</pre>
<pre class="alt"> <span class="kwrd">return</span> excelExtractor.Text;</pre>
<pre> }</pre>
<pre class="alt"> <span class="kwrd">catch</span></pre>
<pre> {</pre>
<pre class="alt"> <span class="rem">// handle the exception</span></pre>
<pre> }</pre>
<pre class="alt"> <span class="kwrd">finally</span></pre>
<pre> {</pre>
<pre class="alt"> <span class="kwrd">if</span> (excelExtractor != <span class="kwrd">null</span>)</pre>
<pre> {</pre>
<pre class="alt"> excelExtractor.Close();</pre>
<pre> excelExtractor = <span class="kwrd">null</span>;</pre>
<pre class="alt"> }</pre>
<pre> }</pre>
<pre class="alt">&nbsp;</pre>
<pre> <span class="kwrd">return</span> <span class="kwrd">string</span>.Empty;</pre>
<pre class="alt">}</pre>
</div></p>
<p>&#160;</p>
<p>I hope that the above code was helpful for you to read the Excel 2007 file format. In the next post, we will learn <b>how to read Excel 97-2003 format</b> using the free, open source NPOI library. Don't forget to read and share the post that I publish. Have a great day!</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-84349570545812463952017-07-11T23:57:00.000+05:302017-07-11T23:57:55.413+05:30Windows 10 most likely to allow control over update bandwidth<p>Windows 10 Update delivery works better by creating a peer network to send/receive updates within LAN and/or internet. But till date, there was no control over it's upload/download bandwidth and thus, there was a need for it.</p>
<p>&#160;</p>
<p>Though this feature is not yet announced in Release Notes, but a separate settings page has been seen in <a href="http://www.kunal-chowdhury.com/2017/07/windows-10-build-16237.html" target="_blank">recent version of Insiders Preview build</a>, which we are going to discuss in this post.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-_PBUPRkQHMY/WWUKKbjTpdI/AAAAAAAASyI/90xqsz4SlyM9P3v_djMTcnGCdK9Hh8SfwCLcBGAs/s800/windows-10-fall-creators-update-update-delivery-optimization.png" class="postImage" width="100%" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>In a most recent version of Windows 10 Insiders Preview build for Fall Creators Update, a new page has been observed in the Windows Update settings which allows you to control the bandwidth of Windows Update using the delivery optimization. Though this is not published in any of the release notes, but it is expected to see in forthcoming insiders update. As it is still under development, the functionality may or may not work properly.</p>
<p>&#160;</p>
<p>If you are a Windows Insiders in the fast ring, and have installed the <a href="http://www.kunal-chowdhury.com/2017/07/windows-10-build-16237.html" target="_blank"><b>latest Insiders Preview build</b></a>, you can now control the bandwidth from the Windows Update settings page. Open the Windows 10 settings page and navigate to '<font color="green"><b>Update &amp; security</b></font>'. Now, click on the '<font color="green"><b>Advanced options</b></font>' as shown in the below screenshot:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-wvIBriIwUvI/WWT8zpd-IRI/AAAAAAAASyA/kRehKteTLUQSleH_SSwe2BQv2_XV4GvTQCLcBGAs/s800/windows-10-update-settings-page.png" class="postImage" style="width:80% !important;" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>This will open the Windows Update Advanced options page. As shown below, scroll down to find another link that says '<font color="green"><b>Delivery Optimization</b></font>'.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-VdNCjF18Whg/WWT8yC_irzI/AAAAAAAASxs/bdpOMFHSSAk3qsT6NrJm09o1vi8BsQlfwCLcBGAs/s800/windows-10-advance-update-settings-page.png" class="postImage" style="width:80% !important;" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>In the '<font color="green"><b>Delivery Optimization</b></font>' page, turn ON the '<font color="green"><b>Allow downloads from other PCs</b></font>' option to speed up the download process. But note that, it will also upload updates from your PC to other PCs based on the selection that you made. Now, click on the '<font color="green"><b>Advanced options</b></font>' link present in the same page as shown below:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-Z5ZOiaCOKL0/WWT8zv0ognI/AAAAAAAASx8/zjP-Ha0_eygy2fFmFwOHqpsWn0rt3jaZwCLcBGAs/s800/windows-10-update-delivery-optimization-page.png" class="postImage" style="width:60% !important;" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>In the advanced options page, it provides you to optimize the amount of bandwidth your device uses to both download and upload updates. But you can set a limit if you are worried about data usage. To limit it, check the option and move the slider left or right based on your choice.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-kk1f5i5qARA/WWT8yZbTCRI/AAAAAAAASxw/JwDKv1xBrhk3lMuEOPhJAmQ5NHBjkByHQCLcBGAs/s800/windows-10-advance-delivery-optimization.png" class="postImage" style="width:60% !important;" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>A dashboard page is also available to help you to monitor the usages. You can go to this page by clicking on '<font color="green"><b>Activity monitor</b></font>' link present in the previous '<font color="green"><b>Delivery Optimization</b></font>' page. It looks similar to this:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-2O-mo0zAZfo/WWT8zHZcjDI/AAAAAAAASx4/yyrb-diBpKYP0Bh1SGeYxLqe1EXj15v1QCLcBGAs/s800/windows-10-update-delivery-monitoring-page.png" class="postImage" style="width:60% !important;" alt="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to allow Update delivery optimization (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>Did you like this feature? Do let us know, how you feel. Please keep posting your suggestions and issues to Microsoft via the Feedback Hub app.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com1tag:blogger.com,1999:blog-2452629445557820138.post-32240893980438602312017-07-08T10:26:00.000+05:302017-07-08T11:44:28.540+05:30Windows 10 preview build 16237 is now available, here's what's new<p>After the last <a href="http://www.kunal-chowdhury.com/2017/06/windows-10-build-16232.html" target="_blank">Windows Insiders Preview build 16232</a>, which was released on 28th June, Microsoft came up with a new build 16237 for the insiders. If you are in the fast ring, enjoy your weekend exploring the new improvements part of it.</p>
<p>&#160;</p>
<p>This new build mainly focuses improvements to Microsoft Edge, Windows Shell including the Action Center, Emoji Panel, handwriting panel and many more.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-FOQuCBCUiSs/WWBWjUuQ_iI/AAAAAAAASw8/p_licxpZE24G23I-lcPLR6u3tZGx8IEcACLcBGAs/s690/windows-10-build-16237.png" class="postImage" width="100%" alt="Windows 10 Insiders preview build 16237 is now available for fast ring PC users (www.kunal-chowdhury.com)" title="Windows 10 Insiders preview build 16237 is now available for fast ring PC users (www.kunal-chowdhury.com)"/></p>
<p>&#160;</p>
<p>With the new insiders build 16237, for PCs, Microsoft again pushed up a bunch of new changes and improvements for you to try in the weekend. Here is the list of key changes that you might be interested to know:</p>
<h2>Microsoft Edge Improvements and Fixes</h2>
<ul>
<li>Read aloud feature is coming to Microsoft Edge, which will allow you to read aloud the text for all websites and PDF documents opened through Edge. This will also include word and line highlighting.</li>
<li>If you click Share in Microsoft Edge, the Share UI will now match the Microsoft Edge theme if it is different from the rest of the system.</li>
<li>Share UI will also now launch under the Share button, rather than in the center of Microsoft Edge.</li>
<li>When you add a favorite, you will get a delightful animation now that indicates where users can find their most important websites in the future.</li>
<li>Fixed an issue where copying double byte characters out of Microsoft Edge and pasting into another app wouldn’t show the characters correctly in the second app.</li>
<li>Fixed a Microsoft Edge issue from the previous flight where opening links in a new tab might cause a new window to open with the link instead.</li>
<li>Fixed an issue from recent flights where the Print dialog in Microsoft Edge would show a blank preview page and lead to printing a blank page.</li>
<li>Fixed an issue resulting in the Microsoft Edge context menu not showing up on pen barrel button tap.</li>
<li>Fixed an issue when returning to Edge after a crash. Your tabs will be automatically restored for you.</li>
</ul>
<h2>Windows Shell Improvements and Fixes</h2>
<ul>
<li>Prior to this build, you had to log out from the system to resolve the blurred desktop apps issue. Microsoft has fixed this in build 16237 and now you don't have to log out. Just relaunching the app will fix this issue now.</li>
<li>In this build, Microsoft has changed the way Windows provides DPI related information to the desktop applications.</li>
<li>Adjustments have been made to notification buttons to span across the bottom of the notification, rather than being right-justified.</li>
<li>It will be now easier for you to take action on your notifications by auto-expanding the first notification in each notification group in the Action Center.</li>
<li>In response to the feedback Microsoft received about the X to “dismiss” notifications, they have now adjusted it to be an arrow to make it more clear that the notification is actually being pushed to the Action Center to be reviewed later.</li>
<p><img src="https://3.bp.blogspot.com/-P1k7xjACKxI/WWB2ckhcf2I/AAAAAAAASxI/PEEBP-K7D1E_4C4rZ10VM9tdzfcaocT1QCPcBGAYYCw/s690/windows-10-build-16237-action-center-notification.png" class="postImage" width="100%" alt="Windows 10 Insiders preview build 16237 is now available for fast ring PC users (www.kunal-chowdhury.com)" title="Windows 10 Insiders preview build 16237 is now available for fast ring PC users (www.kunal-chowdhury.com)"/></p>
<li>Fixed an issue from recent flights where if you received 20 notifications from a specific app, then received more, ShellExperienceHost would start crashing repeatedly in the background.</li>
<li>Fixed a recent issue where tapping on the chevron of an expanded notification in the Action Center wouldn’t collapse the notification.</li>
<li>Fixed an issue from recent flights where opening the Action Center might not clear the badge on the Action Center icon, leading one to later believe there were new notifications when there weren’t any.</li>
<li>Fixed an issue where Notifications and Actions Settings might have unexpectedly had a number of unnamed apps listed at the top in recent flights.</li>
<li>Fixed an issue where Windows Defender notifications might include unparsed parameters.</li>
<li>My People improvements includes notification badges for people pinned to the taskbar, which will now be consistent with the color of your theme if you’ve opted into showing color in Start, Action Center and other places on the system.</li>
<li>When you receive emoji from people pinned to the taskbar, it will now refer to this as a "pop". </li>
</ul>
<h2>Input Improvements and Fixes</h2>
<ul>
<li>Type to search with the new Emoji Panel now supports emoji 5.0!</li>
<li>If you hover your mouse over any of the emoji in the Emoji Panel, you’ll now see a handy showing you the exact Unicode character name.</li>
<li>Microsoft also added tooltips to the categories so they’re no longer a mystery.</li>
<li>Fixed an issue for our dark theme lovers where the X to close out the Emoji Panel was black on black.</li>
<li>Fixed an issue where the touch keyboard was passing the wrong window size information when shapewriting with the one-handed keyboard.</li>
<li>As you type with the touch keyboard, you will now hear a sound with each key press.</li>
<li>Fixed some issues in learning your typing style, so you should find text predictions improved.</li>
<li>Improved the reliability of the Japanese one-handed 10-key Kana touch keyboard.</li>
<li>Fixed an issue from recent flights where the touch keyboard and handwriting panel would unexpectedly appear sometimes.</li>
<li>Fixed an issue where the text candidates would appear using unexpectedly small font.</li>
<li>Fixed an issue where only the one-handed keyboard was available on PCs with small screens.</li>
<li>Fixed an issue where if the text in the handwriting panel shifted while you were inking, it could result in an unintentional ink stroke across the panel.</li>
<li>Fixed an issue where a word might be inserted twice if you dismissed the panel by changing focus to somewhere else on the screen.</li>
</ul>
<h2>Other Improvements and Fixes</h2>
<ul>
<li>PC Gaming Improvement includes updated the Game Mode icon on the Game bar.</li>
<li>Microsoft has now made a few small changes in this build to the GPU performance tracker in Task Manager. It now includes more details like DirectX version and the physical location of your GPU. Only hardware GPUs show up in the list, and the software-only basic display adapter is hidden.</li>
<li>You will now see a new "virtual machine gallery" under quick create in Hyper-V Manager. Though the gallery is not yet includes anything, but includes an option to choose local installation source.</li>
<li>Fixed an issue from the last flight where doing a PC reset via Settings > Update &amp; security > Recovery and choosing "Remove everything" might put your device into a reboot loop. It is now safe to use this option again.</li>
<li>Fixed an issue from recent flights resulting in the Photos, Groove Music, and certain other app’s live tiles not working.</li>
<li>Fixed a high hitting crash impacting Start and Cortana in recent flights.</li>
<li>Fixed a recent issue where you’d find two Connect apps in Start.</li>
<li>There exists some more fixes in this build, which you can read from the <a href="https://blogs.windows.com/windowsexperience/2017/07/07/announcing-windows-10-insider-preview-build-16237-pc" target="_blank">original release notes</a>.</li>
</ul>
<p><font size="+2" color="red"><b>DON'T FORGET</b></font> to checkout the "<b>Known Issues</b>" currently present in this build, before going to download and upgrade your system. Though there are no major known issues, but it's still advisable to check the list.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-67271735125187664142017-07-04T09:00:00.000+05:302017-07-04T09:00:10.953+05:30Here's how to change Codelens Indicator style in Visual Studio<p>Code lens is a feature, first introduced in Visual Studio 2013, which helps you to understand important aspects about your code without leaving your favorite editor. It tells us the code changes in a fantastic way, within the code editor.</p>
<p>&#160;</p>
<p>In this small tips & tricks post on Visual Studio, we will learn how to change the font and color settings of Code Lens.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-PSY0oT7XCxI/WVpprxsdUmI/AAAAAAAASwY/MGkMR0MLFM4V2qf23WfBxoNqvOjK1gD_ACLcBGAs/s1600/visual-studio-codelens.png" alt="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" title="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>Using '<strong>Code Lens</strong>', you will have a deep focus on your code. It will tell you about reference history, changes in your code, author of the code, unit test status, bugs/tasks associated with an item and commit/change history in a trackable manner.</p>
<p>&#160;</p>
<p>You can change the style of the Code Lens information from Visual Studio '<strong>Options</strong>', that includes fonts, size, color etc. In general, the default font set to it is '<font color="green"><strong>Calibri</strong></font>' of Size: 8 and decorated in light gray. When you hover on it, the color changes to bluish as shown below:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-xcpm6hZhvcw/WVppqmnseaI/AAAAAAAASwI/Pdwc0sFVm_UT3qGMxHJoK1ivhGHONMJigCLcBGAs/s1600/1-visual-studio-codelens.png" alt="Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" title="Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>To change the font, color and size of Code Lens, open the Visual Studio '<font color="green"><strong>Options</strong></font>' from IDE menu '<font color="green"><strong>Tools</strong></font> | <font color="green"><strong>Option</strong></font>' and then navigate to '<font color="green"><strong>Fonts and Colors</strong></font>'. The following dialog will popup in the screen. To change the code lens formatting, select '<font color="green"><strong>CodeLens</strong></font>' from the dropdown labeled '<font color="green"><strong>Show settings for</strong></font>'.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-atUACNvTURc/WVpprA6iOoI/AAAAAAAASwQ/TqFOca49PTEvrf2cu8MyO7u_WRkpWdOfwCLcBGAs/s1600/2-visual-studio-codelens.png" alt="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" title="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>You can set the Font family and the size. You can also set it's color. There are five categories of color indicators available: <font color="green"><strong>Indicator Text</strong></font>, <font color="green"><strong>Indicator Text (Hovered)</strong></font>, <font color="green"><strong>Indicator Text (Selected)</strong></font>, <font color="green"><strong>Indicator Text (Disabled)</strong></font> and <font color="green"><strong>Indicator Separator</strong></font>.</p>
<p>&#160;</p>
<p>Choose the one that you want to change and from the '<font color="green"><strong>Item foreground</strong></font>' dropdown, select the appropriate color. You can also click the '<font color="green"><strong>Custom...</strong></font>' button to select a custom color, not part of the dropdown list.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-5dLtf5tbIHY/WVppq98Cb1I/AAAAAAAASwM/j2sWpjEG5CgbGjRGHL7VHaarNh9oGA0DwCLcBGAs/s1600/3-visual-studio-codelens.png" alt="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" title="How to change Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>Once done, click '<font color="green"><strong>OK</strong></font>' button to apply the changes. It will apply immediately, but in few case you may have to restart Visual Studio for the settings to take effect.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-5B95rfZU7io/WVppraIzzjI/AAAAAAAASwU/p_-4wZLoawsQw0Ci9P0iFYGapCA2XX2QgCLcBGAs/s1600/4-visual-studio-codelens.png" alt="Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" title="Codelens Indicator style in Visual Studio (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>This is applicable to both <strong>Visual Studio 2013</strong>, <strong>Visual Studio 2015</strong> and <strong>Visual Studio 2017</strong>. Was the post helpful? Do let us know below in the comment section.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com1tag:blogger.com,1999:blog-2452629445557820138.post-11798120117820606142017-07-01T09:00:00.000+05:302017-07-01T09:00:10.049+05:30Microsoft Word returns Error 800A175D - Could Not Open Macro Storage<p>If you are using Microsoft Word Automation or COM Components to read a MS Word document, you may notice the following error message for few word documents "<u><i>Error 800A175D - Could Not Open Macro Storage</i></u>".</p>
<p>&#160;</p>
<p>This is caused by the user account, whose "user hive" is not loaded when Microsoft Word started. Continue reading to know more about the issue and solution.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-X_Tjq4rsQtY/WVKoGwwzeKI/AAAAAAAASuQ/mxzr05E6GCUhZHrlWCHvByOaP8vPkDwwACLcBGAs/s1600/error_code_800A175D.png" alt="Microsoft Word returns Error 800A175D - Could Not Open Macro Storage (www.kunal-chowdhury.com)" title="Microsoft Word returns Error 800A175D - Could Not Open Macro Storage (www.kunal-chowdhury.com)" style="postImage" width="100%"/></p>
<p>&#160;</p>
<p>If you open Microsoft Word under a user account and try to read any word documents for which the "user hive" is not loaded, you may notice the error "<font color="brown"><strong>Could Not Open Macro Storage</strong></font>". By default, only the interactive user and services running from a user account have their User Registry hive loaded. In such case, you must identify under what user account Word is running and in what context you are developing.</p>
<p>&#160;</p>
<p>To avoid the error, you should either start the Word as an Interactive User or administrative rights. Alternatively, you can load the user hive for the user account programmatically or have a dummy service that runs under the user account.</p>
<p>&#160;</p>
<p><u>As per the <a href="https://support.microsoft.com/en-us/help/224338/error-message-in-word-800a175d---could-not-open-macro-storage" target="_blank">Microsoft KB article (KB224338)</a>:</u></p>
<p>You must identify under what user account Word is running, and in what context you are developing. For example, if you are automating from a Microsoft Transaction Server (MTS) package, the default user account is <font color="brown"><strong>IWAM_MachineName</strong></font>.</p>
<p>&#160;</p>
<p>In this scenario, you can change the user to "Interactive User" in the Internet Service Manager Microsoft Management Console. You need to right-click on your package, click the Identity tab and then click Interactive User.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com1tag:blogger.com,1999:blog-2452629445557820138.post-71812667821774073032017-06-30T09:00:00.000+05:302017-06-30T09:00:21.626+05:30Windows 10 Fall Creators Update to introduce Controlled folder access in Windows Defender<p>Along with <a href="http://www.kunal-chowdhury.com/2017/06/windows-10-build-16232.html" target="_blank">Windows 10 Insiders Preview build 16232</a>, Microsoft to introduce a new feature called 'Controlled folder access' in Windows 10 Fall Creators Update. This will make it easier for you to protect valuable data from malicious apps and threats.</p>
<p>&#160;</p>
<p>In this post, we are going to preview this new feature that's going to introduce in Windows Defender in the next major build of Windows 10.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-eN4LLMWOVxU/WVUOWOP2aXI/AAAAAAAASvs/VhqsLJBvI7MJayHo6N3q4FNoa-Zcw5ugQCLcBGAs/s1600/windows-10-build-16232-windows-defender.png" alt="Windows 10 Fall Creators Update to introduce Controlled folder access in Windows Defender (www.kunal-chowdhury.com)" title="Windows 10 Fall Creators Update to introduce Controlled folder access in Windows Defender (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>When your system is connected to internet, it's not at all secure. Like the way we observed two major cyber attack in recent past, with two Ransomware's named <a href="http://www.kunal-chowdhury.com/2017/06/petya-ransomware-attack.html" target="_blank"><b>WannaCry/WannaCrypt</b></a> and <a href="http://www.kunal-chowdhury.com/2017/05/wannacry-ransomware.html" target="_blank"><b>Petya/NotPetya</b></a>, it's always better to keep your system data protected from such malicious attacks.</p>
<p>&#160;</p>
<p>Thus, the giant company was forced to think of a new feature to keep their users system and/or the data protected from Ransomwares and other malwares. With the insiders preview build 16232, they have introduced '<strong>Controlled folder access</strong>', which is still under development. When this feature is enabled, will improve the protection done by Windows Defender Security Center.</p>
<p>&#160;</p>
<p>To enable this feature, open the <strong>Windows Defender Security Center</strong> and navigate to it's settings page as shown in the below screenshot:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-yXQnL9sxYEQ/WVUOUucfsWI/AAAAAAAASvc/_ZYx0zmvZrAO0MVQlPrUV1UqoN7L0YYlQCLcBGAs/s1600/1-virus-and-threat-protection-settings.png" alt="Virus and Threat Protection Settings in Windows Defender (www.kunal-chowdhury.com)" title="Virus and Threat Protection Settings in Windows Defender (www.kunal-chowdhury.com)" class="postImage" style="width:80% !important;"/></p>
<p>&#160;</p>
<p>As shown in the below screenshot, from the settings page, navigate to the <strong>Virus & threat protection settings</strong> page where you will be able to control the folder access:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-_kZd2uspOXU/WVUOUgRkD5I/AAAAAAAASvY/VzdpYUSwqnAW_MlZ5V_vVPVgZrgImadZQCLcBGAs/s1600/2-virus-and-threat-protection-settings.png" alt="Virus and Threat Protection Settings in Windows Defender (www.kunal-chowdhury.com)" title="Virus and Threat Protection Settings in Windows Defender (www.kunal-chowdhury.com)" class="postImage" style="width:80% !important;"/></p>
<p>&#160;</p>
<p>To protect your files and folders from unauthorized changes made by unfriendly applications, switch ON this feature. You will be able to control the protection of folders by clicking the '<b>Protected folders</b>' link:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-xlyogNj1p7U/WVUOUvF6dnI/AAAAAAAASvg/3Zz3vYugbu82AdpKSK2AwRMxj0ypLGANwCLcBGAs/s1600/3-controlled-folder-access.png" alt="Controlled folder access (www.kunal-chowdhury.com)" title="Controlled folder access (www.kunal-chowdhury.com)" class="postImage" style="width:80% !important;"/></p>
<p>&#160;</p>
<p>Controlled folder access monitors the changes that apps make to files in certain protected folders. If an app attempts to make a change to these files, and the app is blacklisted by the feature, you’ll get a notification about the attempt.</p>
<p>&#160;</p>
<p>Windows system folders are by default protected but if you want to protect additional folders, you can do so by adding them one by one here in this screen:</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-bvhmZEUpxdA/WVUOVe_BmJI/AAAAAAAASvk/lAJk8MLubM4XaoAxiYiREBPc3Q9Pvq_gACLcBGAs/s1600/4-protected-folders.png" alt="Protected Folders settings in Windows Defender (www.kunal-chowdhury.com)" title="Protected Folders settings in Windows Defender (www.kunal-chowdhury.com)" class="postImage" style="width:80% !important;"/></p>
<p>&#160;</p>
<p class="infoGreen"><b><u>Please note:</u></b><br/><br/>You can add additional folders to the list of protected folders, but you cannot alter the default list, which includes folders such as Documents, Pictures, Movies and Desktop.</p>
<p>&#160;</p>
<p>Allowing apps can be useful if you’re finding a particular app that you know and trust is being blocked by the Controlled folder access feature. Click Allow an app through Controlled folder access and locate and add the app you want to allow.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-YqM4k0BIgeM/WVUOVVsL7BI/AAAAAAAASvo/gd9n9AwJpTksyc4KoEvTEIrxAEDpG044gCLcBGAs/s1600/5-controlled-folder-access.png" alt="Controlled folder access (www.kunal-chowdhury.com)" title="Controlled folder access (www.kunal-chowdhury.com)" class="postImage" style="width:80% !important;"/></p>
<p>&#160;</p>
<p>You can also enter network shares and mapped drives, but environment variables and wildcards are not supported. Hope that the information shared above was easy to understand. Don't forget to check out the other new features that got introduced in <a href="http://www.kunal-chowdhury.com/2017/06/windows-10-build-16232.html" target="_blank"><strong>Windows 10 Insiders Preview build 16232</strong></a>. If you are an insider in the fast ring, check it out and share your feedback to Microsoft.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com1tag:blogger.com,1999:blog-2452629445557820138.post-31017765956220804852017-06-29T10:35:00.001+05:302017-06-29T10:45:58.595+05:30Windows 10 build 16232 released to PCs in Fast ring<p>A new Windows 10 PC build (16232) is now available to the fast ring insiders, along with Mobile Build 15228. This new PC build includes a no. of new security enhancements to Windows Defender, many other improvements and fixes.</p>
<p>&#160;</p>
<p>Don't forget to read the 'Known Issues' first, before downloading as there is a possibility of update failure in this build.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-mLZ2WGRAZXo/WVSJnHSRNtI/AAAAAAAASvI/aMzAU7NN3uEIC47icr6Ebbkmqgesh9YgwCLcBGAs/s1600/windows-10-build-16232.png" alt="Windows 10 build 16232 released to PCs in Fast ring (www.kunal-chowdhury.com)" title="Windows 10 build 16232 released to PCs in Fast ring (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>Moving forward to the Windows 10 Fall Creators Update, Microsoft has released another PC build for Windows Insiders in the fast ring to try and provide early feedback to build a better ecosystem. This new build 16232 majorly focused to new security features added to Windows Defender and here is a list of them:</p>
<ul>
<li>Once you enable Windows Defender Application Guard (WADG), data such as your favorites, cookies and saved passwords will be persisted across Application Guard sessions. The persisted data will not be shared to the host, but it will be available for future in Application Guard sessions.<br/><img src="https://3.bp.blogspot.com/-Y5y968auRgc/WVSJTekk0kI/AAAAAAAASvE/XLzcZqWw3k04Q4TNfBXROIUWv9Z4bAMcACLcBGAs/s1600/application-guard.png" alt="Windows Defender Application Guard (www.kunal-chowdhury.com)" title="Windows Defender Application Guard (www.kunal-chowdhury.com)" class="postImage" width="100%"/>If you have enable Data Persistence using Group Policy for Application Guard, the site you saved to your Favorites will be available for later use, with Microsoft Edge in Application Guard, even after reboots as well as build to build upgrades of Windows.<br/><br/></li>
<li>You can enable Data Persistence for Microsoft Edge in Application Guard using Group Policy. To enable it, close all Microsoft Edge windows and update the Windows Components > Windows Defender Application Guard.<br/><br/></li>
<li>Starting with this build you can now audit, configure, and manage Windows system and application exploit mitigation settings right from the Windows Defender Security Center! You don’t need to be using Windows Defender Antivirus to take advantage of these settings.<br/><br/></li>
<li>In this build, it's now easier for you to protect valuable data from malicious apps and threats, such as ransomware. To enable the feature, search for and open the Windows Defender Security Center from Start. Then go to the 'Virus & threat protection' settings section and set the switch to ON.<br/><br/></li>
</ul>
<p>Apart from all these new changes, there are a bunch of improvements and fixes available in this PC build. Check out the original <a href="https://blogs.windows.com/windowsexperience/2017/06/28/announcing-windows-10-insider-preview-build-16232-pc-build-15228-mobile" target="_blank">Release Notes</a>, shared by Microsoft. There exists a bunch of 'Known Issues' too. Don't forget to read them before installing this build.</p>
<p>&#160;</p>
<p class="infoRed">As a major known issue, your PC may fail to update to this build with an <b>0x80070643</b> and will rollback to the previous build. Microsoft is investigating on that.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-30064667655813662932017-06-28T21:41:00.000+05:302017-06-29T00:01:11.636+05:30A massive cyber attack named '#Petya' is spreading across the world<p>In a month of two, after the attack of '<a href="http://www.kunal-chowdhury.com/2017/05/wannacry-ransomware.html" target="_blank">WannaCry</a>', a new Ransomware named 'Petya' started spreading across the world. It's a massive cyber attack that paralyzed firms, airports, banks and government departments that uses unpatched old Windows operating system.</p>
<p>&#160;</p>
<p>Starting with Ukraine, it already spread many countries like UK, Spain and India. Check this post to know how to take precaution from such attacks.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-mePCgQyi9XE/WVPUHaLRlaI/AAAAAAAASuw/z9iYNN4hT-AfJIwDBg3MjKBm9V4l60umACLcBGAs/s1600/petya_ransomware.png" alt="A massive cyber attack named 'Petya' is spreading across the world (www.kunal-chowdhury.com)" title="A massive cyber attack named 'Petya' is spreading across the world (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>As per the news, the said malware was first launched at Ukraine and Russia at the same time and paralyzed the systems of many firms, airports, POS, Banks, ATMs, government departments. Then it started spreading across other countries.</p>
<p>&#160;</p>
<p>Victims of the malware were asked to pay a ransom, in the form of BitCoins, worth $300 after their hard drive is encrypted. Petya attack causes more havoc on machines than the <a href="http://www.kunal-chowdhury.com/2017/05/wannacry-ransomware.html" target="_blank"><strong>WannaCry ransomware</strong></a>, which released in the month of May, and attacks hard drives rather than individual files and then it demands the ransom to unlock it.</p>
<p>&#160;</p>
<p>Security experts stated that the ransomware released on Tuesday is using Eternal Blue to exploit the spread. According to the experts, if one of the computer out of a hundred didn't patch the Eternal Blue exploit, which was released by Microsoft, it can spread across the entire network and infect the unpatched systems within that LAN.</p>
<h2>What to do, if your system got infected?</h2>
<p>Good thing it, a flaw has been identified which may prevent your system from getting encrypted after it got affected. According to the security experts, <a href="http://www.kunal-chowdhury.com/2017/06/petya-ransomware-attack.html" target="_blank"><strong>Petya ransomware</strong></a> takes 1 hour after it infects the system and then automatically restarts the system with the following CHKDSK disk checking process screen.</p>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-0d-1rcstwJA/WVPUHUEh68I/AAAAAAAASus/-rdA4zvJy483CeOz-5xfzliioJnEtvaUwCLcBGAs/s1600/petya_ransomware_screen.png" alt="A massive cyber attack named 'Petya' is spreading across the world (www.kunal-chowdhury.com)" title="A massive cyber attack named 'Petya' is spreading across the world (www.kunal-chowdhury.com)" class="postImage" width="100%"/></p>
<p>&#160;</p>
<p>If machine reboots and you see the message, immediately turn OFF the system. This is the encryption process that Petya is performing. If you do not power ON, the files will remain safe and you are good to go to take the backup of your files before formatting the drive.</p>
<p>&#160;</p>
<p>When the malware infects your system, it <b>demands BitCoin worth $300</b> and show you an email address to communicate to the hacker for the key to decrypt your drive. The email address has been already blocked and thus you won't be able to reach to the attackers. If your system got encrypted, don't pay any ransom to the BitCoin address specified in the screen as you won't get any decrypt keys.</p>
<h2>How to prevent your system from such attacks?</h2>
<p>Last but not least, upgrade to latest version of the Windows operating system and keep your system always patched as and when a update is available. This will reduce the chance of such attacks on your computer. Also, don't open or click any suspicious links that might be vulnerable to the system. Put a good antivirus software always running on your system. If you follow such precautions, you will stay safe.</p>
<p>&#160;</p>
<p>Security Researcher Amit Serper found a way to vaccinate your system, so that, it won't get affected by the Petya ransomware. Just create a file named <b>perfc</b> without any extension and place it in the <b>C:\Windows</b> directory. When the ransomware runs and if it finds the specified file, it will stop immediately without affecting your hard drive files.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0tag:blogger.com,1999:blog-2452629445557820138.post-5276662076526080092017-06-27T09:00:00.000+05:302017-06-27T09:00:22.586+05:30Extracting text with iTextSharp throws an InvalidCastException<p>If you are using 'iTextSharp' library to read/write PDF files in your application and faced an InvalidCastException with the message "<i><u>Unable to cast object of type 'iTextSharp.text.pdf.PdfLiteral' to type 'iTextSharp.text.pdf.PdfString'</u></i>", this post will help you to know the root cause of the issue. Continue reading to learn more about it.</p>
<a name='more'></a>
<p>&#160;</p>
<p><img src="https://3.bp.blogspot.com/-lTTmBdcNC6M/WUlV6jPFv7I/AAAAAAAASrw/feYrT5wERY4aP_eF0n9yJt2vZwaqhPXQQCLcBGAs/s1600/iTextSharp-throws-invalidcastexception.png" alt="Extracting text with iTextSharp throws an InvalidCastException (www.kunal-chowdhury.com)" target="Extracting text with iTextSharp throws an InvalidCastException (www.kunal-chowdhury.com)" width="100%" class="postImage"/></p>
<p>&#160;</p>
<p>'<strong>iTextSharp</strong>' is a very popular 3rd party library to read/write PDF documents using C#. It also has supported library for Java. If you are using the library in your application, you already know the power of it.</p>
<p>&#160;</p>
<p>While processing/reading few PDF documents, the library may through the following <font color="brown"><strong>InvalidCastException</strong></font>, that states the message: "<strong>Unable to cast object of type 'iTextSharp.text.pdf.PdfLiteral' to type 'iTextSharp.text.pdf.PdfString'</strong>" with the following Stack Trace:</p>
<p><pre class="csharpcode">
Message :Unable to cast object of type <span class="str">'iTextSharp.text.pdf.PdfLiteral'</span>
to type <span class="str">'iTextSharp.text.pdf.PdfString'</span>.
Source :itextsharp
Stack Trace : at iTextSharp.text.pdf.DocumentFont.FillMetrics(Byte[] touni, IntHashtable widths, Int32 dw)
at iTextSharp.text.pdf.DocumentFont.ProcessType0(PdfDictionary font)
at iTextSharp.text.pdf.DocumentFont.Init()
at iTextSharp.text.pdf.DocumentFont..ctor(PRIndirectReference refFont)
at iTextSharp.text.pdf.CMapAwareDocumentFont..ctor(PRIndirectReference refFont)
at iTextSharp.text.pdf.parser.PdfContentStreamProcessor.GetFont(PRIndirectReference ind)
at iTextSharp.text.pdf.parser.PdfContentStreamProcessor.SetTextFont.Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List`1 operands)
at iTextSharp.text.pdf.parser.PdfContentStreamProcessor.InvokeOperator(PdfLiteral oper, List`1 operands)
at iTextSharp.text.pdf.parser.PdfContentStreamProcessor.ProcessContent(Byte[] contentBytes, PdfDictionary resources)
at iTextSharp.text.pdf.parser.PdfReaderContentParser.ProcessContent[E](Int32 pageNumber, E renderListener, IDictionary`2 additionalContentOperators)
at iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(PdfReader reader, Int32 pageNumber, ITextExtractionStrategy strategy)
</pre></p>
<p>The library parses the syntax of the PDF file to find specific PDF objects. When it detects some unidentifiable objects that doesnot fit into any of the defined PDF objects in the specification, it creates a PdfLiteral object from it.</p>
<p>&#160;</p>
<p>When those unidentifiable PdfLiteral object is expected to read as PdfString, the iTextSharp library throws the above <font color="brown"><strong>InvalidCastException</strong></font>. If you check the Stack Trace, you will notice that the internal code line <font color="brown"><b>iTextSharp.text.pdf.parser.PdfContentStreamProcessor.GetFont(PRIndirectReference ind)</b></font> actually triggered the Exception.</p>
<p>&#160;</p>
<p>As stated in <a href="https://stackoverflow.com/questions/26010284/extracting-text-with-itextsharp-throws-an-invalidcastexception" target="_blank">StackOverflow</a>, the PDF document, which threw the exception, contains a font 'Calibri' (which is a subset composite font) with the following ToUnicode map:</p>
<p><pre class="csharpcode">
/CIDInit /ProcSet findresource
begin
12 dict
begin
/CIDSystemInfo <span class="kwrd">&lt;&lt;/</span><span class="html">Ordering</span> (<span class="attr">UCS</span>) /<span class="attr">Registry</span> (<span class="attr">Adobe</span>) /<span class="attr">Supplement</span> <span class="attr">0</span> <span class="kwrd">&gt;&gt;</span> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<span class="kwrd">&lt;</span><span class="html">0000</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">ffffffffffffffff</span><span class="kwrd">&gt;</span> endcodespacerange
20 beginbfchar
<span class="kwrd">&lt;</span><span class="html">0003</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0020</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0012</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0043</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">0018</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0044</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0045</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">004e</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0059</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0051</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">005e</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0053</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0102</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0061</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0110</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0063</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">011a</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0064</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">011e</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0065</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">015d</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0069</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">0175</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">006d</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0176</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">006e</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">017d</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">006f</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">01ffffff89</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0070</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">01ffffff8c</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0072</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">01ffffff90</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0073</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">01ffffff9a</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0074</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">01ffffffb5</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0075</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">01ffffffc7</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">0079</span><span class="kwrd">&gt;</span> endbfchar
<font color="red"><b>100 beginbfchar</b>
<span class="kwrd"><b>&lt;</b></span><span class="html"><b>01ffffffcc</b></span><span class="kwrd"><b>&gt;</b></span> <span class="kwrd"><b>&lt;</b></span><span class="html"><b>007a</b></span><span class="kwrd"><b>&gt;</b></span> <b>endcmap</b></font>
CMapName
currentdict
/CMap defineresource
pop
end
end
ý
</pre></p>
<p>&#160;</p>
<p>If you observe the above sample unicode map, you could find a '<font color="green"><b>beginbfchar</b></font>' without a '<font color="green"><b>endbfchar</b></font>'. Instead, it ended with '<font color="green"><b>endcmap</b></font>' which caused the above exception to trigger (check the highlighted code above).</p>
<p>&#160;</p>
<p>If you faced this exception in your application, nothing wrong in your code. You just need to handle it properly so that, you can skip reading those PDF documents in the question for the InvalidCastException from iTextSharp library. Hope the post was helpful. Don't forget to ask your question, if any.</p>
<p>&#160;</p><p>&#160;</p>
<div class="blogger-post-footer"><br/><br/>
<b><u>Reference:</u></b> <a href="http://www.kunal-chowdhury.com">http://www.kunal-chowdhury.com</a>
<br/>You may like to follow me on twitter <a href="http://twitter.com/kunal2383">@kunal2383</a> or may like the Facebook page of my blog <a href="http://www.facebook.com/blog.kunal">http://www.facebook.com/blog.kunal</a>.</div>Kunal Chowdhuryhttps://plus.google.com/116466483881822301139noreply@blogger.com0