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

<channel>
	<title>ASP.NET &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/category/programming/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Fri, 17 Apr 2020 18:23:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>ASP.NET &#8211; MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>Create an Excel file in C# without Microsoft Office or Third party plugins</title>
		<link>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/</link>
					<comments>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 18:07:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net-framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[epplus5]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel-cell]]></category>
		<category><![CDATA[excel-document]]></category>
		<category><![CDATA[excel-row]]></category>
		<category><![CDATA[excel-sheet]]></category>
		<category><![CDATA[excel-workbook]]></category>
		<category><![CDATA[excellibrary]]></category>
		<category><![CDATA[free-dll]]></category>
		<category><![CDATA[free-library]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[libre-office]]></category>
		<category><![CDATA[microsoft-excel]]></category>
		<category><![CDATA[microsoft-office]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[workbook]]></category>
		<category><![CDATA[xls]]></category>
		<category><![CDATA[xlsx]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=247</guid>

					<description><![CDATA[How to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed]]></description>
										<content:encoded><![CDATA[
<p>What I&#8217;m about to say seems paradoxical, but the reality is that in open environments (as in PHP for example) it is often easier and we have less problems in creating or converting files in proprietary systems, compared to what happens on frameworks such as Microsoft&#8217;s .Net; this is the case when we have to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed, without the right libraries in our project we will have several headaches. A quick solution is to use the open-source library <a href="https://github.com/gustafl/ExcelLibrary" class="aioseop-link">ExcelLibrary</a>. This looks to be a port of the PHP ExcelWriter, it&#8217;s very simple, small and easy to use.</p>



<p><strong>Using ExcelLibrary</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-csharp&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;C#&quot;,&quot;modeName&quot;:&quot;csharp&quot;}">Workbook workbook = new Workbook();
workbook.Open(&quot;Book1.xlsx&quot;);
Sheet sheet = workbook.Sheet(&quot;Sheet1&quot;);
Row row = sheet.Row(2);
Cell cell = row.Cell(3);
string text = cell.Value;</pre></div>



<p><strong>Main features</strong></p>



<ul><li>No dependencies except .NET Framework 4.5. Easy to include in other solutions.</li><li>Built and extendable with LINQ. Most collections in the library (e.g. <code>Workbook.Sheets</code> or <code>Row.Cells</code>) is of type <code>IEnumerable&lt;T&gt;</code>, which allows you to use LINQ queries to find exactly what you need.</li><li>Respects the visibility of sheets, rows and columns. Set the <code>IncludeHidden</code> option to <code>true</code>to return hidden objects.</li><li>Well-tested. The library is being developed using principles of Test-driven development (TDD). A large set of unit tests verifies that new bugs are not introduced on code changes.</li><li>Well-documented. A software library is only as useful as its documentation.</li></ul>



<p>Another valid alternative is <a href="https://github.com/EPPlusSoftware/EPPlus" class="aioseop-link">EPPLUS5</a>  however it has a new license model from version 5, it&#8217;s still free to use in some cases, but will require a commercial license to be used in a commercial business.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">247</post-id>	</item>
		<item>
		<title>Render a Section in a Partial View &#8211; ASP.Net MVC</title>
		<link>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/</link>
					<comments>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sun, 12 Apr 2020 15:34:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc-partial-view]]></category>
		<category><![CDATA[mvc-project]]></category>
		<category><![CDATA[mvc-view]]></category>
		<category><![CDATA[partial-view]]></category>
		<category><![CDATA[razor]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=231</guid>

					<description><![CDATA[Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with If you call the Partial View &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/" aria-label="Render a Section in a Partial View &#8211; ASP.Net MVC">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
	&lt;!-- some code here --&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;		&lt;/script&gt;
    @RenderSection(&quot;Scripts&quot;, false)
  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p>Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@Section Scripts
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.fix.js&quot;)&quot;&gt;&lt;/script&gt;  
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/localization/messages_de.js&quot;)&quot;&gt;&lt;/script&gt;      
End Section</pre></div>



<p>If you call the Partial View from a View like this…</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@ModelType MvcExample.MyModel
@Code
    ViewData(&quot;Title&quot;) = &quot;Test&quot;
End Code

@Html.Partial(&quot;ValidationScripts&quot;)

&lt;h2&gt;Just a Test&lt;/h2&gt;</pre></div>



<p>However the Section &#8220;Scripts&#8221; is not rendered on the page, and the output HTML will be&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
    
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;&lt;/script&gt;

  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p><strong>Solution</strong></p>



<p>To render the Section in the Partial View, you need to create a couple of Extension methods like this:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">public static class HtmlHelperExtensions
{
  private const string _jSViewDataName = &quot;RenderJavaScript&quot;;
  private const string _styleViewDataName = &quot;RenderStyle&quot;;

  public static void AddJavaScript(this HtmlHelper htmlHelper, 
                                   string scriptURL)
  {
    List&lt;string&gt; scriptList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      if (!scriptList.Contains(scriptURL))
      {
        scriptList.Add(scriptURL);
      }
    }
    else
    {
      scriptList = new List&lt;string&gt;();
      scriptList.Add(scriptURL);
      htmlHelper.ViewContext.HttpContext
        .Items.Add(HtmlHelperExtensions._jSViewDataName, scriptList);
    }
  }

  public static MvcHtmlString RenderJavaScripts(this HtmlHelper HtmlHelper)
  {
    StringBuilder result = new StringBuilder();

    List&lt;string&gt; scriptList = HtmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      foreach (string script in scriptList)
      {
        result.AppendLine(string.Format(
          &quot;&lt;script type=\&quot;text/javascript\&quot; src=\&quot;{0}\&quot;&gt;&lt;/script&gt;&quot;, 
          script));
      }
    }

    return MvcHtmlString.Create(result.ToString());
  }

  public static void AddStyle(this HtmlHelper htmlHelper, string styleURL)
  {
    List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     if (!styleList.Contains(styleURL))
     {
       styleList.Add(styleURL);
     }
   }
   else
   {
     styleList = new List&lt;string&gt;();
     styleList.Add(styleURL);
     htmlHelper.ViewContext.HttpContext
       .Items.Add(HtmlHelperExtensions._styleViewDataName, styleList);
   }
 }

 public static MvcHtmlString RenderStyles(this HtmlHelper htmlHelper)
 {
   StringBuilder result = new StringBuilder();

   List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
     .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     foreach (string script in styleList)
     {
       result.AppendLine(string.Format(
         &quot;&lt;link href=\&quot;{0}\&quot; rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; /&gt;&quot;, 
         script));
     }
   }

  return MvcHtmlString.Create(result.ToString());
  }
}</pre></div>



<p>So, on any View or Partial View or Display/Edit Template you simply add what you need:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@{
  Html.AddJavaScript(&quot;http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js&quot;);
}</pre></div>



<p>Then, in your Layouts you render it where you want it! Like this markup&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
  @Html.RenderStyles()
  @Html.RenderJavascripts()</pre></div>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">231</post-id>	</item>
		<item>
		<title>C# code to VB.NET free online converter</title>
		<link>https://www.maxvergelli.com/c-sharp-code-to-vb-net-free-online-converter/</link>
					<comments>https://www.maxvergelli.com/c-sharp-code-to-vb-net-free-online-converter/#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sun, 01 Mar 2020 16:31:43 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=86</guid>

					<description><![CDATA[Simply paste your C# code and this free online utility will automatically convert it to its equivalent in VB.NET. This utility now support .NET 3.5 syntax: http://www.developerfusion.com/tools/convert/csharp-to-vb/ You can reverse code from VB.NET to C# too. 🙂]]></description>
										<content:encoded><![CDATA[<p>Simply paste your C# code and this free online utility will automatically convert it to its equivalent in VB.NET. This utility now support .NET 3.5 syntax:</p>
<p><a href="http://www.developerfusion.com/tools/convert/csharp-to-vb/">http://www.developerfusion.com/tools/convert/csharp-to-vb/</a></p>
<p>You can reverse code from VB.NET to C# too.</p>
<p>🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/c-sharp-code-to-vb-net-free-online-converter/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">86</post-id>	</item>
		<item>
		<title>New Associative Array Class for VB.NET / ASP.NET and C#</title>
		<link>https://www.maxvergelli.com/new-associative-array-class-for-vb-net-asp-net-and-c-sharp/</link>
					<comments>https://www.maxvergelli.com/new-associative-array-class-for-vb-net-asp-net-and-c-sharp/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Wed, 26 Feb 2020 16:30:19 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MS Access]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=84</guid>

					<description><![CDATA[I have coded the  &#8220;Associative Array Class&#8221; also for VB.NET and ASP.NET so You can add this class to your .NET projects; Download the VB.NET/ASP.NET Associative Array Class from: https://sourceforge.net/projects/vbnetassocarray/ You will find a tutorial inside the archive.]]></description>
										<content:encoded><![CDATA[<p>I have coded the  &#8220;Associative Array Class&#8221; also for VB.NET and ASP.NET so You can add this class to your .NET projects;</p>
<p>Download the VB.NET/ASP.NET Associative Array Class from:</p>
<p><a href="https://sourceforge.net/projects/vbnetassocarray/">https://sourceforge.net/projects/vbnetassocarray/</a></p>
<p>You will find a tutorial inside the archive.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/new-associative-array-class-for-vb-net-asp-net-and-c-sharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">84</post-id>	</item>
		<item>
		<title>vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem</title>
		<link>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/</link>
					<comments>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 14 Jan 2020 15:47:04 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dispose]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=74</guid>

					<description><![CDATA[Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/" aria-label="vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not able to move or delete that image file through the file system.</p>
<p>This is a known problem and it occurs when we declare and instantiate a Bitmap object and destruct that like in the following code:</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release all Bitmap object resources<br />
                myBitmap.Dispose()</p>
<p>[/sourcecode]</p>
<p>The above code it is formally correct, however in same circumstances the .net garbage collector cannot recognize bitmap&#8217;s disposing; Dispose() method leaves the image file in an unusable state, then as <a href="http://msdn.microsoft.com/en-us/library/8th8381z.aspx">MSDN</a> said, we MUST release explicitly any reference after a Dispose() call;</p>
<p>with the following code, You will not encounter any problem, and after Dispose() You can edit, move, delete the image file by the filesystem functions&#8230;</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release image reference<br />
                While myBitmap IsNot Nothing<br />
                    myBitmap.Dispose()<br />
                    myBitmap = Nothing  &#8216;&lt;&#8211; tells .net garbage collector to release resources<br />
                End While</p>
<p>[/sourcecode]</p>
<p>Happy image editing! 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">74</post-id>	</item>
		<item>
		<title>How to draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)</title>
		<link>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/</link>
					<comments>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Thu, 09 Jan 2020 15:41:16 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[backcolor]]></category>
		<category><![CDATA[background-color]]></category>
		<category><![CDATA[bitamp-library]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmap-effect]]></category>
		<category><![CDATA[bitmap-fx]]></category>
		<category><![CDATA[bitmap-manipulation]]></category>
		<category><![CDATA[bitmap-processing]]></category>
		<category><![CDATA[bitmap-programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[digital-image-processing]]></category>
		<category><![CDATA[draw]]></category>
		<category><![CDATA[draw-bitmap]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[drop-shadow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[graphic-manipulation]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[image-filter]]></category>
		<category><![CDATA[image-fx]]></category>
		<category><![CDATA[image-height]]></category>
		<category><![CDATA[image-library]]></category>
		<category><![CDATA[image-manipulation]]></category>
		<category><![CDATA[image-manipulation-algorithm]]></category>
		<category><![CDATA[image-matrix]]></category>
		<category><![CDATA[image-processing]]></category>
		<category><![CDATA[image-processing-algorithm]]></category>
		<category><![CDATA[image-width]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[matrix-manipulation]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shadow]]></category>
		<category><![CDATA[shadow-effect]]></category>
		<category><![CDATA[thread-safe]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=72</guid>

					<description><![CDATA[I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230; Normal black shadow to the bottom right corner Red shadow to the bottom right corner Shadow &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/" aria-label="How to draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230;</p>
<table>
<tbody>
<tr>
<td>Normal black shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_01_black_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Red shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_02_red_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the bottom left corner</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_04_d_bottomleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top left corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_05_d_topleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top right corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_06_d_topright.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_07_opacity.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221; and Softness: &#8220;8&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_08_opacityandsoftness.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;, Softness: &#8220;8&#8221; and Distance: &#8220;10&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_09_opacitysoftnessanddistance.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow without rounded edges</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_10_noroundededges.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
</tbody>
</table>
<p>Copy and paste my following vb.net code in your application. it does all the hard job&#8230;</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>    &#8216;ShadowDirection:<br />
    &#8216;       TOP_RIGHT = 1<br />
    &#8216;       BOTTOM_RIGHT = 2<br />
    &#8216;       BOTTOM_LEFT = 3<br />
    &#8216;       TOP_LEFT = 4<br />
    &#8216;ShadowOpacity: from 0 to 255<br />
    &#8216;ShadowSoftness: from 1 to 30<br />
    &#8216;ShadowDistance: from 1 to 50<br />
    &#8216;ShadowRoundedEdges: True or False</p>
<p>    &#8216;Note:<br />
    &#8216;If You set &quot;transparent&quot; as background color, this is replaced with white color.</p>
<p>    Public Enum ShadowDirections As Integer<br />
        TOP_RIGHT = 1<br />
        BOTTOM_RIGHT = 2<br />
        BOTTOM_LEFT = 3<br />
        TOP_LEFT = 4<br />
    End Enum</p>
<p>    &lt;STAThread()&gt; _<br />
    Public Sub DropShadow(ByRef SourceImage As Drawing.Bitmap, _<br />
                            ByVal ShadowColor As Drawing.Color, _<br />
                            ByVal BackgroundColor As Drawing.Color, _<br />
                            Optional ByVal ShadowDirection As ShadowDirections = _<br />
                                                  ShadowDirections.BOTTOM_RIGHT, _<br />
                            Optional ByVal ShadowOpacity As Integer = 190, _<br />
                            Optional ByVal ShadowSoftness As Integer = 4, _<br />
                            Optional ByVal ShadowDistance As Integer = 5, _<br />
                            Optional ByVal ShadowRoundedEdges As Boolean = True)<br />
        Dim ImgTarget As Bitmap = Nothing<br />
        Dim ImgShadow As Bitmap = Nothing<br />
        Dim g As Graphics = Nothing<br />
        Try<br />
            If SourceImage IsNot Nothing Then<br />
                If ShadowOpacity &lt; 0 Then<br />
                    ShadowOpacity = 0<br />
                ElseIf ShadowOpacity &gt; 255 Then<br />
                    ShadowOpacity = 255<br />
                End If<br />
                If ShadowSoftness &lt; 1 Then<br />
                    ShadowSoftness = 1<br />
                ElseIf ShadowSoftness &gt; 30 Then<br />
                    ShadowSoftness = 30<br />
                End If<br />
                If ShadowDistance &lt; 1 Then<br />
                    ShadowDistance = 1<br />
                ElseIf ShadowDistance &gt; 50 Then<br />
                    ShadowDistance = 50<br />
                End If<br />
                If ShadowColor = Color.Transparent Then<br />
                    ShadowColor = Color.Black<br />
                End If<br />
                If BackgroundColor = Color.Transparent Then<br />
                    BackgroundColor = Color.White<br />
                End If</p>
<p>                &#8216;get shadow<br />
                Dim shWidth As Integer = CInt(SourceImage.Width / ShadowSoftness)<br />
                Dim shHeight As Integer = CInt(SourceImage.Height / ShadowSoftness)<br />
                ImgShadow = New Bitmap(shWidth, shHeight)<br />
                g = Graphics.FromImage(ImgShadow)<br />
                g.Clear(Color.Transparent)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                Dim sre As Integer = 0<br />
                If ShadowRoundedEdges = True Then sre = 1<br />
                g.FillRectangle(New SolidBrush(Color.FromArgb(ShadowOpacity, ShadowColor)), _<br />
                                      sre, sre, shWidth, shHeight)<br />
                g.Dispose()</p>
<p>                &#8216;draw shadow<br />
                Dim d_shWidth As Integer = SourceImage.Width + ShadowDistance<br />
                Dim d_shHeight As Integer = SourceImage.Height + ShadowDistance<br />
                ImgTarget = New Bitmap(d_shWidth, d_shHeight)<br />
                g = Graphics.FromImage(ImgTarget)<br />
                g.Clear(BackgroundColor)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                g.DrawImage(ImgShadow, New Rectangle(0, 0, d_shWidth, d_shHeight), _<br />
                                        0, 0, ImgShadow.Width, ImgShadow.Height, GraphicsUnit.Pixel)<br />
                Select Case ShadowDirection<br />
                    Case ShadowDirections.BOTTOM_RIGHT<br />
                        g.DrawImage(SourceImage, _<br />
                            New Rectangle(0, 0, SourceImage.Width,SourceImage.Height), _<br />
                               0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.BOTTOM_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipX)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                             New Rectangle(ShadowDistance, 0, SourceImage.Width, SourceImage.Height), _<br />
                                    0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.Rotate180FlipNone)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                                      New Rectangle(ShadowDistance, ShadowDistance, _<br />
                                                        SourceImage.Width, SourceImage.Height), _<br />
                                      0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_RIGHT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipY)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                           New Rectangle(0, ShadowDistance, SourceImage.Width, SourceImage.Height), _<br />
                                  0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                End Select</p>
<p>                g.Dispose()<br />
                g = Nothing<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing</p>
<p>                SourceImage = New Bitmap(ImgTarget)<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If</p>
<p>        Catch ex As Exception<br />
            If g IsNot Nothing Then<br />
                g.Dispose()<br />
                g = Nothing<br />
            End If<br />
            If ImgShadow IsNot Nothing Then<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing<br />
            End If<br />
            If ImgTarget IsNot Nothing Then<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If<br />
        End Try</p>
<p>    End Sub<br />
[/sourcecode]</p>
<p>Besides, You can use this sub as in the following example (take a look at the comments&#8230;) :</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
        Dim file_input As String = &quot;c:myfile.jpg&quot;<br />
        Dim file_output As String = &quot;c:myfilewithshadow.jpg&quot;</p>
<p>        &#8216;get bitmap&#8230;<br />
        Dim sourceImage As System.Drawing.Image = System.Drawing.Image.FromFile(file_input)<br />
        Dim format As System.Drawing.Imaging.ImageFormat = sourceImage.RawFormat<br />
        Dim bmpOut As System.Drawing.Bitmap = New Bitmap(sourceImage)</p>
<p>        &#8216;release any reference to the original file&#8230;<br />
        While sourceImage IsNot Nothing<br />
            sourceImage.Dispose()<br />
            sourceImage = Nothing<br />
        End While</p>
<p>        &#8216;drop black shadow on new bitmap with white background&#8230;<br />
        DropShadow(bmpOut, Color.Black, Color.White)</p>
<p>        &#8216;save file&#8230;<br />
        If bmpOut IsNot Nothing Then<br />
            bmpOut.Save(file_output, format)<br />
            bmpOut.Dispose()<br />
            bmpOut = Nothing<br />
        End If<br />
[/sourcecode]</p>
<p>PS:<br />
The subroutine executes only in &#8220;STAThread&#8221; so it&#8217;s thread-safe drawing.</p>
<p>Happy coding&#8230;</p>
<p>Max 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">72</post-id>	</item>
	</channel>
</rss>
