Monday, January 17, 2011

Group by query data based on 5 mins interval

Select count(id) from table_Name group by dateadd(minute,(datediff(minute,0,time_stamp)/5)*5,0)

Friday, March 5, 2010

Invoke private static method and assign static variable through reflection c#

I was working on current project and wanted to update some of the values of the fields which were private to the method and were being updated from one of the private methods.
The assembly which was being reference was not allowing any of the methods or fields, using which I could have updated the values runtime, so I end up using reflection.
Here is the code snippet for the same:

//Get the type of the class

Type typeToChangeValue = Assembly.GetAssembly("YourAssemblyName").GetType("TypeName");

//Get the static field to set the value

FieldInfo
fieldToSetValue =
typeToChangeValue.GetField("FieldName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField);
//Get the method of which output you want to assign to a variable
MethodInfo privateStaticMethod = typeToChangeValue.GetMethod("StaticMethodName", BindingFlags.NonPublic | BindingFlags.Static);
//Invoke the method

object
returnValue = privateStaticMethod.Invoke(typeToChangeValue, new object[] { "methodParams" });

//define class variable

TypeName classObject = new TypeName();

//Invoke reflection setvalue method to assign the returned value of the method

fieldToSetValue.SetValue(classObject, returnValue);

Thursday, March 12, 2009

How to find Table for a Column?

Use below query to find out Table for a Column.

SELECT * FROM SYSOBJECTS WHERE ID IN ( SELECT ID FROM SYSCOLUMNS WHERE NAME = 'COLUMN_NAME')
Find Columns of a table

SELECT * FROM SYSCOLUMNS WHERE ID in (SELECT ID FROM SYSOBJECTS WHERE name like 'TABLE_NAME')

Wednesday, December 17, 2008

Visual Studio AddIns

1. DPack

2. TFS Quick Search
http://www.codeplex.com/tfsquicksearch

3. Extended Immediate Window - Linq etc. in Debugging
http://www.codeplex.com/ExtendedImmediateWin

Wednesday, August 13, 2008

InfoPath Labs on Microsoft Site

Publishing an InfoPath 2007 Form Template to a Server Running InfoPath Forms Services
http://msdn.microsoft.com/en-us/library/bb267334.aspx

Deploying and Managing InfoPath 2007 Forms
http://msdn.microsoft.com/en-us/library/bb267337.aspx

Integrating InfoPath 2007 with the Data Connection Library
http://msdn.microsoft.com/en-us/library/bb267335.aspx

Enabling Digital Signatures in InfoPath 2007 Form Templates
http://msdn.microsoft.com/en-us/library/bb251748.aspx

Importing Word Forms into InfoPath 2007
http://msdn.microsoft.com/en-us/library/bb251744.aspx

Using InfoPath 2007 E-mail Forms
http://msdn.microsoft.com/en-us/library/bb251746.aspx

Restricting Permissions to InfoPath 2007 Forms and Form Templates
http://msdn.microsoft.com/en-us/library/bb251749.aspx

Using the InfoPath 2007 Object Model and Visual Studio Tools for Applications
http://msdn.microsoft.com/en-us/library/bb251747.aspx

Designing InfoPath 2007 Forms for Mobile Web Browsers
http://msdn.microsoft.com/en-us/library/bb251745.aspx

Creating and Inserting InfoPath 2007 Template Parts
http://msdn.microsoft.com/en-us/library/bb267331.aspx

Integrating InfoPath 2007 Forms in Web Sites Using Visual Studio
http://msdn.microsoft.com/en-us/library/bb267336.aspx

Tuesday, June 24, 2008

Retrieve Sharepoint ListItem from document URL

One of our SharePoint site has a webpart which lists links to the documents from different document libraries from different Sharepoint webs.
Now if we want to retrieve information about the document we don't have any other info on the page other than the URL for the document.
So how to retrieve additional info about the document?

Here's the solution:
1. Retrieve the web URL from the document URL.
2. Get the web object.
3. From web object retrieve the SPListItem object.

And you got the all info about the document!

string webUrl = documentURL.Substring(0, documentURL.LastIndexOf("/"));
SPWeb web = SPContext.Current.Site.OpenWeb(webUrl);
SPListItem fileListItem = web.GetListItem(documentURL);

This is also a good use if you are trying to get the list item info in HttpHandler while downloading the document in SharePoint.