जगदीश खोलिया: 2013

Monday, August 19, 2013

Undo Changes (Remove lock) in another User's Workspace in TFS

To undo another user's lock

  1. Click Start, click All Programs, click Microsoft Visual Studio 2008/10, click Visual Studio Tools, and then click Visual Studio Command Prompt.
  2. Type the following command and replace the arguments with the appropriate parameter information for your needs:
    tf undo /workspace:OtherUser'sWorkspace;OtherUser $/TeamProject/File.cs /s:http://YourTFSServer:8080

    eg: tf undo /workspace:II-SW-DSK-009;CORP\Jagdish.Kholiya $/BimaExpress/BimaExpress_V1.0/BimaExpress/BimaExpress.Services/BimaExpress.Services.csproj /s:http://ii-srv-dev-03:8080/tfs

Tuesday, July 9, 2013

Find table row id (inside HeaderTemplate) in a DataList control

Below is the code for finding table row id inside a datalist control:
protected void datalistData_ItemDataBound(object sender, DataListItemEventArgs e)
{
      if (e.Item.ItemType == ListItemType.Header)
     {
          HtmlControl trTableRow = e.Item.FindControl("trOffline") as HtmlControl;
         //where trOffline is row id
     }
}

Monday, April 29, 2013

Extension Methods

Extension methods allow you to easily extend a type, such as an integer or string, without re-compiling or modifying the type or Extension methods enable you to "add" methods to existing types without creating a new derived type. Extension methods are a special kind of static method (shared in vb) , but they are called as if the method is native to the type.
One important thing to extension methods is if that you create an extension method with the same name as another method in that type, the compiler will bind the method call to the native method, not any extension. An extension method is only called when there is no native method found.

Steps To Create Extension Methods?
  1. Create a public static class. e.g. :  public static class Extensions{  }
  2. Define functions. 
     public static class Extensions
     {
      public string GetFirstThreeCharacters(String str)
      {
        if(str.Length < 3)
        {
            return str;
        }
        else
        {
            return str.Substring(0,3);
        }
      }
    }
  3. Make the functions an extension method.
To make our C# version of our function, we need an extension method to mark the function as static (so that it can be accessed at any time without the need for declaring anything) and secondly, mark the first parameter with the this keyword. This keyword basically tells the CLR that when this extension method is called, to use "this" parameter as the source. See the following:
 public static class Extensions
 {
    public static string GetFirstThreeCharacters(this String str)
    {
        if(str.Length < 3)
        {
            return str;
        }
        else
        {
            return str.Substring(0,3);
        }
      }
  }

Monday, March 4, 2013

Delay signing

During development process you will need strong name keys to be exposed to developer which is not a good practice from security point of view.In such situations you can assign the key later on and during development you can use delay signing.
Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.  
More you can find out in this link:
http://msdn.microsoft.com/en-us/library/t07a3dye.aspx

Wednesday, February 27, 2013

Finding duplicate records from a table in sql server

 By using row_number() function :
;with dup as(select customer_id, firstname,lastname,row_number() over(partition by firstname,
lastname order by customer_id desc) as numOfDup from customer_details)
select * from dup where numOfDup > 1 order by customer_id

 By using dense_rank() function :
;with dup as(select customer_id,firstname,lastname,dense_rank() over(partition by firstname,lastname
order by customer_id desc) as numOfDup from customer_details)
select * from dup where numOfDup > 1 order by customer_id


 By using rank() function :
;with dup as(select customer_id,firstname,lastname,rank() over(partition by firstname,lastname
order by customer_id desc) as numOfDup from customer_details)
select * from dup where numOfDup > 1 order by customer_id

 By using self join()
select distinct cd1.customer_id,cd1.firstname,cd1.lastname from customer_details cd1
join customer_details cd2
on cd1.firstname=cd2.firstname
and cd1.lastname=cd2.lastname
and cd1.customer_id > cd2.customer_id order by cd1.customer_id

 By using sub query
SELECT * FROM customer_details
    WHERE customer_id NOT IN (SELECT MIN(customer_id)
    FROM customer_details
    GROUP BY FirstName, LastName)

Tuesday, February 12, 2013

Control 'grid 1' of type 'GridView' must be placed inside a form tag with runat=server.

Because calling GridView.RenderControl(htmlTextWriter)raises 
an exception that aserver control was rendered outside of a form.
We can avoid this exception byoverriding VerifyRenderingInServerForm
 
public override void VerifyRenderingInServerForm(Control control)
{
  /* Confirms that an HtmlForm control is rendered
     for the specified ASP.NET
     server control at run time. */
} 
 
*Note that there is nothing inside the function. 
 

Thursday, January 31, 2013

WCF Sessions

WCF sessions are different than the session object in ASP.NET , support different behaviors, and are controlled in different ways.WCF sessions are very different from ASP.NET Sessions. In short,

ASP.NET Sessions are:
  1. Always server-initiated.
  2. Implicitly unordered.
  3. Provide a way to preserve data across multiple requests.There is unique session id generated at the server and passed back and forth between client and server via URL or cookies.
WCF Sessions are:
  1. Initiated and terminated by the calling application (WCF Client).
  2. Ordered message delivery.
  3. Sessions correlate a group of messages into a conversation.This correlation depdending upon the binding can be taken care at message or transport level.
  4. No data storage is involved with WCF Session.

To configure sessions in WCF, one should know the following three elements:

  1. Binding – Because all bindings do not support sessions. Only WS-*, NetTcpBinding and NetNamedPipeBinding have session support so selection of appropriate binding is necessary.
  2. SessionMode – This service contract specifies service’s possible expectation for session from incoming client request. It has three self describing values:
    *)Allowed – Service can accept sessionful clients as well as sessionless.
    *)Required – Service will entertain only those clients who have session, sessionless client cannot    connect to service.
    *)NotAllowed – Service can interact only with sessionless clients. Just opposite to Required.
  3. InstanceContextMode – This is a service behavior that controls instantiation of actual service class. It has the following values:
    *)PerCall – Each request made to server will be served by a new instance of service class.
    *)PerSession – A Session will have its dedicated service instance and all requests pertaining to the session will be served by that instance only. All sessions will have their individual dedicated service instances.
    *)Single –All requests to the service will be served by a single unique instance of service class.  
There are 3 things to remember for WCF session:
1) Sessionful binding. 
      (
          <endpoint address="http://localhost:750" binding="wsHttpBinding" 
           contract="wcfservice.Iservice" name="wcfSessionTest"/>
       )
2) SessionMode service contract.
   ( 
      [ServiceContract(SessionMode = SessionMode.Allowed)]
      public interface Iservice 
      {
         //some code…
      }
   ) 
3) InstanceContextMode service behavior. 
      (
          [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
            public class serviceclass : Iservice
           { // some code… }
       )