What is managed and unmanaged code

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags , with Leave a comment on What is managed and unmanaged code

What is managed and unmanaged code in .Net technology.

Visual Studio have made the life of developer very easy by providing the powerful interfaced IDE which helps to create the applications faster than any other technology. We all remember the coding in Turbo C compiler in which the output produced is “machine level language“.

Before Visual studio 2003, the output produced by the compilers were machine level language which can be pronounced as “UnManaged code“. Machine level language compiles and run on same machine or machine having same chip or configuration but it is not sure that it will run on another machine.

After Visual studio 2003, the output produced by the compilers of C# and VB were not “machine level language”, instead it was “Intermediate Language” with some metadata info which is executed by the “Common Language Runtime (CLR)“. so we can say that output produced by the compilers of C# and VB after Visual studio 2003 is “Managed Code“.

To read more on this topic, please refer below good articles:

  1. What is Managed Code ?
  2. Managed, Unmanaged, Native.

Logging made easy in .NET – log 4 net

Author posted by Jitendra on Posted on under category Categories c#, Microsoft and tagged as Tags , with 1 Comment on Logging made easy in .NET – log 4 net

How to use the log 4 net in .Net application. Example, demonstration and sourcecode

Logging is the part of development which is normally not included in Product / Software release but at the same time it is necessary to create the logging mechanism in your software module.

implement log4net in .net

Continue reading “Logging made easy in .NET – log 4 net”

Clear ASP page cache – Page_Load() firing multiple time in RadWindow Popup

How to prevent the multiple Page load event in case Telerik Rad Window Popup is used and Clear ASP page cache.

Setting ReloadOnShow property of RadWindow for Popup to true causes its Page_load to be executed multiple times hence redundant multiple database calls causing to some extent of performance hit.

ReloadOnShow needs to be  set to true since page_load/refresh of Popup wasn’t firing on subsequent opens.

Solution

We can set ReloadOnShow to false and use alternative code in page_load as following in C#:

below code will clear the cache of ASPX page and thus reloaded every time in browser.

Note : you should run these statement before sending any HTML to the user. If in doubt, use Respose.Buffer = True to buffer all html

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
Response.Expires = -1;
Response.CacheControl = "no-cache";

Find all possible solution at this URL

Get Week of the Year

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with Leave a comment on Get Week of the Year

get the Week Number of the year in C#

        /// <summary>
        /// Gets the week number of Year.
        /// </summary>
        /// <param name="dtPassed">The dt passed.</param>
        /// <returns></returns>
        private int GetWeekNumber(DateTime dtPassed)
        {
            CultureInfo ciCurr = CultureInfo.CurrentCulture;
            int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            return weekNum;
        }

Upload Files in ASP.NET at Production server

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , , , with Leave a comment on Upload Files in ASP.NET at Production server

In this article, i am going to demonstrate that how to upload the file in ASP.NET production server.

Most of the case, a developer created a code to upload the file and test it on his local machine. program runs smoothly, but as he forward the same code on production. He stuck in the file permission error as on the local he has the full permission whereas on development its not the case.

So i decided to write this tutorial for the beginners which will demonstrate lots of ASP.NET features.

First we need to create a folder in Server and share it with ASP.NET web server as described.

Right click on folder, select Web sharing tab and select the radio button “Share this folder”. One  window appear, give it alias name which will be used in coding.

After this, open Run box and type “inetmgr“. you will see that your web shared folder appears in the IIS.

Right click on folders property. one window will opened.

Select “Directory Security” tab then click on “Edit” button and then check “Anonymous access”. And because of this setting any body can access or download that file.

Now we are ready, to create a sample application which will demonstrate that how to upload the file and use it.

Create ASP.NET project in Visual Studio. Create a webpage with fileupload, hyperlink and button control.

<form id="form1" runat="server">
<asp:FileUpload ID="uploadFile" runat="server" /><br />
<asp:HyperLink ID="hypLink" runat="server" Visible="false" Target="_blank"></asp:HyperLink><br />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="btnUpload_Click" />
</form>

In web.config add two keys.  One for actual folder location in which we are going to upload the files and other its alias name. we can also hard code that, but its good practice to make it configurable at any time because in near future we may want to change the location.


<appSettings>

<add key="DemoAttachment" value="D:ShareDemoShare"></add>

<add key="DemoAttachmentVirtualPath" value="http://localhost/DemoShare/"></add>

</appSettings>

In DemoAttachmentVirtualPath key, value should like “http://machinename/” + Alias folder name.

On click event of button, write below code:

string strPath = ConfigurationManager.AppSettings["DemoAttachment"];
uploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));
hypLink.Visible = true;
string VirtualPath = ConfigurationManager.AppSettings["DemoAttachmentVirtualPath"];
hypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);
hypLink.NavigateUrl = VirtualPath + uploadFile.FileName;
string strPath = ConfigurationManager.AppSettings["DemoAttachment"];

uploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));
hypLink.Visible = true;
string VirtualPath = ConfigurationManager.AppSettings["DemoAttachmentVirtualPath"];

hypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);

hypLink.NavigateUrl = VirtualPath + uploadFile.FileName;

The output will look like:

Download Source code

For the file size limitation, please visit this article : http://JitendraZaa.com/blog/?p=125