Friday, October 26, 2012

How to get page name from URL in c#


this.GetType().Name.Split('_')[0]
Or
this.GetType().Name
or
public string GetCurrentPageName() 
{ 
    string sPath = Request.Url.AbsolutePath;
    System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
    string sRet = oInfo.Name; 
    return sRet; 
}

Thursday, October 25, 2012

How to clear Cache on logout in c#


Call this method on page load for clearing cache

 public void ClearApplicationCache()
    {
        List<string> keys = new List<string>();

        IDictionaryEnumerator enumerator = Cache.GetEnumerator();

        while (enumerator.MoveNext())
        {
            keys.Add(enumerator.Key.ToString());
        }

        for (int i = 0; i < keys.Count; i++)
        {
            Cache.Remove(keys[i]);
        }
    }

Monday, October 22, 2012

Caching in ASP.NET using c#

Caching is the ability to store page output and data in memory for the first time it is requested and later we can quickly retrieve them for multiple, repetitious client requests. It is like keeping a copy of something for later use, so we can reduce the load factor on Web servers and database servers by implementing caching on a Web application.

Add dataset to cache....

Cache.Add("dataset", dataset, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 60), System.Web.Caching.CacheItemPriority.Default, null);



Now how to use cache dataset in any page of application

DataSet ds = new DataSet();
ds = (DataSet) Cache["dataset"];

SQl Function for retuning values in tables from sql server


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER FUNCTION [dbo].[GetWarrantNotesDetails] (@WarrantID varchar(22))
   RETURNS @WarrantDetails Table
     (  Remarks     varchar(1000)
      , NoteDate  datetime
      , AddedBy varchar(36)
    )
 AS
   BEGIN
       INSERT INTO @WarrantDetails (Remarks, NoteDate, AddedBy)
        SELECT TOP(1) Remarks, NoteDate,[exec].cname
        FROM warrant_notes iNNER JOIN [exec] ON
       cast(warrant_notes.AddedBy as varbinary) = cast(dbo.[exec].cid as varbinary)    
      WHERE  WarrantID=@WarrantID AND AddedBy<>'Admin' ORDER BY NoteDate DESC
     RETURN
   END

Function for returning single scaler value in sql server


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author: Ajay Kumar
-- Create date: 22-10-2012
-- Description: This function used to get values for allocated users
-- =============================================
CREATE FUNCTION [dbo].[getAllocatedUsers]
(
-- Add the parameters for the function here
@CId varchar(20)
)
RETURNS varchar(20)
AS
BEGIN
-- Declare the return variable here
declare @AllocatedTo varchar(20)

-- Add the T-SQL statements to compute the return value here
SELECT @AllocatedTo=cname from [exec] where cid=@CId

-- Return the result of the function
RETURN @AllocatedTo
END

Friday, October 19, 2012

C# language versions


C# language versions

There are five significant language versions:

C# 1
C# 2, introducing generics, nullable types, anonymous methods, iterator blocks and some other more minor features
C# 3, introducing implicit typing, object and collection initializers, anonymous types, automatic properties, lambda expressions, extension methods, query expressions and some other minor features
C# 4, introducing dynamic typing, optional parameters, named arguments, and generic variance
C# 5, introducing asynchronous functions, caller info attributes, and a tweak to foreach iteration variable capture

Tuesday, October 16, 2012

how to add link in string in asp.net





string Link = "http://www.shnet.net/scollections/ViewReport.aspx?Writ=Writ&WarrantID=" + _warrantid + "";

string Reportlink = "<a href=\"" + Link + "\">RO Report</ID></a>";