Monday 19 November 2012

Get Assembly location of the DLL added to SQL Server


SELECT 
    assembly = a.name, 
    path     = f.name
FROM sys.assemblies AS a
INNER JOIN sys.assembly_files AS f
ON a.assembly_id = f.assembly_id
WHERE a.is_user_defined = 1;

Thursday 8 November 2012

Get GridView Column Headers and Appropriate Row Values in Asp.Net

Get Gridview column header(s) text and Specific Row's Values on Row Command in asp.net. Below Method takes GridView control, Command Source Within the Row(LinkButton, Button, ImageButton, etc..), no of Columns to skip in from Start Column and from End Column as Parameters and returns List<KeyValuePair<headerText,Values>> as output.



private void SetDeleteDetails(GridView pGV, object pCmdSource, int pStartSkipColCount=0, int pEndSkipColCount=0)
        {
            List<KeyValuePair<string, string>> lkvp = new List<KeyValuePair<string, string>>();
            GridViewRow rw = (GridViewRow)((Control)pCmdSource).NamingContainer;

            for (int i = pStartSkipColCount; i < pGV.Columns.Count - pEndSkipColCount; i++)
                if (!string.IsNullOrEmpty(rw.Cells[i].Text))
                    lkvp.Add(new KeyValuePair<string, string>(pGV.Columns[i].HeaderText, rw.Cells[i].Text));
            //Session["DeleteDetails"] = lkvp;
        }

Wednesday 7 November 2012

Get Specific Property Name Using Expression


Hope the program explains all:

class Program
    {
        static void Main(string[] args)
        {
            SomeClass sc = new SomeClass();
            Console.WriteLine(sc.p1.GetType());

            //RemoteMgr.ExposeProperty(() => SomeClass.SomeProperty);
            MemberInfo member = RemoteMgr.GetMemberInfo((SomeClass p) => p.SomeProperty);
            Console.WriteLine(member.Name);
            Console.ReadKey();
        }
    }

    public class SomeClass
    {
        public string SomeProperty
        {
            get { return "Foo"; }
        }
    }

    public class RemoteMgr
    {
        public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T,U>> expression)
        {
            var member = expression.Body as MemberExpression;
            if (member != null)
                return member.Member;
            throw new ArgumentException("Expression is not a member access", "expression");
        }
    }