7/14/08

SIMPLE SHARE POINT TOOLS - 2

Release 2 Release date: 07/14/2008

2) SPFarm Auditing Tool v0.1: The purpose of this tool is to create a complete list of Share point Farm Features. This tool helps Administrators to keep track of Share Point installation Tool performs audits using SPServiceCollection objects and displays the list of services, features etc installed on a Share Point farm. This list can be exported to a Text file for future reference. Tool was developed using C#, and Share Point SDK.


Codeplex download

7/11/08

Simple Share Point Tools

A collection of simple Share Point tools for share point developers and administrators. I have about 7 tools designed and developed and shall be uploading them one by one in Codeplex
1) User Auditing Tool v0.1 - This is a simple GUI utility developed using C#, and Share Point SDK. The purpose of this tool is to enable Administrators/help desk personnel to keep track of Share Point users and perform user Audit The tool performs user audit through Application/Site collections and Websites and displays the list of group(s) owned by the user and list of group(s) he/she is member of. The tool also dumps the audit result to a text file.

http://www.codeplex.com/SpSimpleTools

6/12/08

Dynamic Share Point Custom Feature Receiver

My idea was to add few Custom Feature Receivers [menu items] to make my life easy with SharePoint. I wanted to add links to routine tasks like Share point central admin, Features management etc.

Hence my first step to make this happen is Google!
---------------- Cut here ------------------------------------------------------
1998: If you are coding less than 500 lines a day you are a poor developer
2008: If you are coding more than 50 lines, it means you don’t Google enough.
--------------------------------------------------------------------------------

On Goggling I found few very good examples which I could have used but the menus were brutally hardcoded. If I had to add new one, I had to recompile/redeploy the solution. This raised a question - how about reading the menu items from a XML file? Will share point refresh when I make changes to the Xml? -- Yes it does
“XMLMenuFeatureReceiver” was the answer.

You can download the source or the WSP solution file from Codeplex.
http://www.codeplex.com/xmlFeatureReceiver/

Share point Work Flow and the AD pattern

Like most modern developers or solution evangelists or preachers or Code Voodoo masters, I started to mess around with Microsoft Workflows foundation. I dived deeply into the ill fated tool that was once called as Front Page and now renamed as the Share Point designer. In no time I leant Visual Studio is the best tool to develop workflows for Share Point.

The work flow are of two types
Microsoft calls them as Sequential and State Machine.
I call it,
a. Type Z - the one that could Work with mammoth effort,
b. Type Y - the one that would Never Work regardless of your best efforts.

now over to Share Point list and the AD pattern.

Step 0: Create a share point List, add 2 new columns
a) Requestor: (Person or Group) Make sure the display field is Email.
b) Manager: (Text field)
Step 1: Code a method to read the AD.
Ingredients: the LDAP url, login with appropriate permission and pwd.
Our Input : Email [This need not be email, you if you read the following code carefully you will find a way to change it]

public static string getManager(string userName)
{
string domain = "ldap://yourcompanyLdap.company.com";
string login = "[a speical admin account designated for this purpose]";
string password = "[pwd]";
string searchFor = userName;
string returnValue = "unable to find Manager";
string metaType = "Mail"; // ...

DirectoryEntry Root = new DirectoryEntry(domain, login, password, AuthenticationTypes.Delegation);
using (Root)
{
DirectorySearcher dsearcher = new DirectorySearcher(Root);
dsearcher.Filter = metaType + "=" + searchFor;
dsearcher.SearchScope = SearchScope.Subtree;
SearchResult searchresult = dsearcher.FindOne();
if (searchresult != null)
{
DirectoryEntry myDirectoryEntry = searchresult.GetDirectoryEntry();
string strManagerAlias = myDirectoryEntry.Properties["manager"].Value.ToString().Trim();
DirectoryEntry managerEntry = new DirectoryEntry(domain +"/" + strManagerAlias, login, password, AuthenticationTypes.Delegation);

//domainname\samAccount , is need for the Share point Task
returnValue = Root.Properties["name"].Value.ToString() + "\\" +managerEntry.Properties["sAMAccountName"].Value.ToString();
}
}
return returnValue;
}

Step 2:
1) Go ahead and create a new Sequential Work flow using Visual Studio
2) Drag and Drop a “OnWorkFlowActivated” Task
3) Do the Initial rituals of assigning Correlation token etc.
4) Assign a variable for Work-Flow [my code calls it “WorkflowProperties”]
5) Add an Event and code to the code Block.
//Visual Studio should add the below line automatically [Step 4/5]
public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties WorkflowProperties = new
Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();

The above represents the initial properties of the workflow instance when it kicks in, this contains details like workflow user, the list and item to which the workflow was tied to.

The following is the event handler code to the work flow activated activity.

public string _requestor =””;
public string _manager=””;

private void OnWorkActivated(object sender, ExternalDataEventArgs e)
{
//populate the Automatic Fields
if (WorkflowProperties.Item["Requestor"] != null)
{
_requestor = WorkflowProperties.Item["Requestor"].ToString();
_requestor = _requestor.Remove(0, _requestor.IndexOf('#') + 1);
//the above ritual is a must ,thanks to share point.
// Autopopulate the Fields.
_manager= getManager(_requestor)
WorkflowProperties.Item["Manager"] = _manager;
WorkflowProperties.Item.Update();
}
}

Step 3: compile and build and deploy it as feature. , enable the feature
Step 4, Add the workflow to the list.

9 of 10 times the above should work and my is disclaimer that this is not the only method, you are welcome to post your ideas.