Wednesday, 24 December 2014

What are various types of directives in .NET?




@Page: Defines page-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .aspx files <%@ Page AspCompat="TRUE" language="C#" %>
 

@Control: Defines control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files. <%@ Control Language="VB" EnableViewState="false" %>
 

@Import: Explicitly imports a namespace into a page or user control. The Import directive cannot have more than one namespace attribute. To import multiple namespaces, use multiple @Import directives. <% @ Import Namespace="System.web" %>
 

@Implements: Indicates that the current page or user control implements the specified .NET framework interface.<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
 

@Register: Associates aliases with namespaces and class names for concise notation in custom server control syntax.<%@ Register Tagprefix="Acme" Tagname="AdRotator" src="AdRotator.ascx" %>
 

@Assembly: Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page. <%@ Assembly Name="MyAssembly" %><%@ Assembly src="MySource.vb" %>
 

@OutputCache: Declaratively controls the output caching policies of an ASP.NET page or a user control contained in a page<%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream | Server | None" Shared="True | False" VaryByControl="controlname" VaryByCustom="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" %>
 

@Reference: Declaratively indicates that another user control or page source file should be dynamically compiled and linked against the page in which this directive is declared.

What is Event Bubbling in c# asp.net?


When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row and so on) is quite tedious. The controls can bubble up their event handlers, allowing the main DataGrid event handler to take care of its constituents.

Friday, 5 December 2014

Create a Windows Event Log and Write Custom Message.



Here, I am posting this article about Windows event log API. When developers create a Windows based application, it may be an ActiveX component, any customized DLL library, a service application, etc.; it is a very common practice to write several types of information into the event log, which is generated by that particular application runtime so we can easily keep track of all the information.
For writing log in event log you can create a separate class for this.

Code is below:

/// <summary>
///  Method is used to create log.
/// </summary>
public bool CreateLog(string strLogName)
{
bool Result = false;

try
{
System.Diagnostics.EventLog.CreateEventSource(strLogName, strLogName);
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();

SQLEventLog.Source = strLogName;
SQLEventLog.Log = strLogName;

SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry("The " + strLogName + " was successfully initialize component.", EventLogEntryType.Information);

Result = true;
}
catch
{
Result = false;
}

return Result;
}


/// <summary>
/// Method is used to write event log.
/// </summary>
public void WriteToEventLog(string strLogName, string strSource, string strErrDetail)
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();

try
{
if (!System.Diagnostics.EventLog.SourceExists(strLogName)) this.CreateLog(strLogName);


SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource) + Convert.ToString(strErrDetail),
EventLogEntryType.Information);

}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("INFORMATION: ") + Convert.ToString(ex.Message),
EventLogEntryType.Information);
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}

For checking the Event Log please follow the below steps:

Go to Control Panel > Administrative Tools > Events Viewer > Search your Event Log name on left panel.

Create Setup File Using InstallShield LE From VS 2012.

I had created Windows Service in Visual Studio 2012. Now we need the installation file for the same to install on client machine. I faced lots of problem to create exe file in VS 2012. There is one option to install it using command prompt with the help of InstallUtil tools. But client was not technical so he would not be able to follows the steps to install the windows service.
                    I have worked on Window Service with Visual Studio 2010. There were simple process to create exe file for the same. For reference you can go through this URL.


URL for Create Setup File Using VS 2012:
http://cherupally.blogspot.in/2009/09/how-to-create-setup-project-to-install.html

                   After lots of r&d I found very good article on in c-sharpcorner Posted by -Jay Parekh. It was very awesome article which given all details step by step. I really appreciate "Jay Parekh" for their wonderful article.

URL for Create Setup File Using InstallShield LE From VS 2012:

http://www.c-sharpcorner.com/UploadFile/cb88b2/simple-steps-to-create-setup-file-using-install-shield-le-fr/