Friday, February 20, 2015

Abstract Class in C#

If we don't want a class object to be created define the class as abstract. An abstract class can have abstract and non abstract classes. If a method in abstract id defined as abstract , it must be implemented in derived class. For example , in the classes given below , method DriveType is defined as abstract. 

abstract class Car
{
public Car()
{
Console.WriteLine("Base Class Car");
}
public abstract void DriveType();
}

class Ford : Car
{
public void DriveType()
{
Console.WriteLine("Right Hand ");
}
}

Method Hiding in C#

If the derived class doesn't want to use methods in base class , derived class can implement the same method in derived class with same signature. For example in the classes given below, DriveType() is implemented in the derived class with same signature. This is called Method Hiding.

class Car
{
public void DriveType()
{
Console.WriteLine("Right Hand Drive");
}
}

class Ford : Car
{
public void DriveType()
{
Console.WriteLine("Right Hand ");
}
}

Monday, February 16, 2015

Javascript How to get unique values in a array

var a = ["1", "1", "2", "3", "3", "1"];
var unique = a.filter(function(item, i, ar){ return ar.indexOf(item) === i; });

asp.net access values from dictionary

IDictionary<string, object> keyValueCollection //- Dictionary variable

KeyValuePair<string, object> escalateres;


         escalateres = keyValueCollection.Where(x => x.Key.ToLower().Trim() == "escalateres" &&
                   null != x.Value && x.Value.ToString() != "All").FirstOrDefault(); //access values of key "escalateres"

 List<object> lstEscalatersDetails = null; //define list variable

  lstEscalatersDetails = escalateres.Value as List<object>;

  foreach (object lstEscalatersDetail in lstEscalatersDetails)
                {
                    IDictionary<string, object> keyValueCollectionHelpDeskEcalatorTime = new Dictionary<string, object>();
                 
                    keyValueCollectionHelpDeskEcalator = lstEscalatersDetail as IDictionary<string, object>;

                    FormatEscalateTime = Convert.ToString(keyValueCollectionHelpDeskEcalator["Hrs"]) + ":" + Convert.ToString(keyValueCollectionHelpDeskEcalator["Mins"]);

                    KeyValuePair<string, object> EscalateTime = new KeyValuePair<string, object>("EscalateTime", FormatEscalateTime);

                    keyValueCollectionHelpDeskEcalatorTime.Add(EscalateTime);
                    keyValueCollectionHelpDeskEcalatorTime.Add("HelpDeskSLAId", id);
                    Save(keyValueCollectionHelpDeskEcalatorTime, "HelpDeskEscalators");

                }

Friday, February 13, 2015

ASP.NET Remove value from Dictionary

  keyValueCollection.Remove("ResolvedHrs");
                keyValueCollection.Remove("ResolvedMin");

Thursday, February 12, 2015

ASP.NET access value from Dictionary and format it and add value again in dictionary

   FormatResolvedHrsMins = Convert.ToString(keyValueCollection["ResolvedHrs"]) + ":" + Convert.ToString(keyValueCollection["ResolvedMin"]);
                KeyValuePair<string, object> ExpectedClosure = new KeyValuePair<string, object>("ExpectedClosure", FormatResolvedHrsMins);
                keyValueCollection.Add(ExpectedClosure);

Wednesday, February 11, 2015

SharePoint disable loopback check (DisableLoopbackCheck dword in registry)

Ive found this very handy.. recently, I was working on a server and we were trying to access the local SharePoint site http://127.0.0.1 or http://nameoflocalserver/pages/default.aspx and I was constantly prompted for the username and password. In SharePoint 2010, it can really annoy you by not accepting your username password credentials in the popup window.
Its a ‘feature’ on the server that you need to disable as a workaround (if you are an Admin/Developer) on a DEVELOPMENT and PREPROD environment.
Caution: Microsoft Best practices is out of scope in this article. Do your own research on this topic.
There are two methods to do this:
1.  Specify the host names in the registry – BackConnectionHostNames (more secure and recommended for PRODUCTION servers). Refer http://support.microsoft.com/kb/896861
2. Disable the loopback check – DisableLoopbackCheck (less secure and recommended for DEVELOPMENT environments). Read on to use this method 2 and add via an easy powershell cmd.
You would need to create a DWORD registry key in the registry called DisableLoopbackCheckand set it to 1.
Follow these steps:
Option 1: Add this registry entry by PowerShell
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword
Option 2: Add this registry entry manually
Click Start, click Run, type regedit, and then click OK
In Registry Editor, locate the following registry key:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Right-click Lsa, point to New, and then click DWORD Value. (In Win 2008, its DWORD 32bit)
Type DisableLoopbackCheck, and then press ENTER.
Right-click DisableLoopbackCheck, and then click Modify.
In the Value data box, type 1 and then click OK.
Quit Registry Editor.
You may need to restart your server.
For more information about this, click the following article number to view the article in the Microsoft Knowledge Base: 281308 (http://support.microsoft.com/kb/281308/ ) Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name.