Posts

Showing posts from March, 2011

SharePoint Edit Page and Personalize page using Javascript

I had to dig deep to find out what are the javascript functions called when we click the Edit Page button the SharePoint ribbon. I had to hide the ribbon for one of my client's requirements and i had to provide links for Edit Page, Personalize page and Save page. I have used three hyperlinks for each of these functionalities. This is how we can do it in SharePoint. <a href="javascript:ChangeLayoutMode(false);">Edit</a> <a href="javascript:ChangeLayoutMode(true);">Personalize</a> <a href="javascript:ChangeLayoutMode(null,true);">Save</a> These functions are available in a Javascript file which SharePoint includes by default. So you just have to place this html on your page and there you go.

Config file for SharePoint custom timer jobs

Image
SharePoint timer jobs run under the OWSTIMER.exe process. This process has a configuration file associated with it. We can use this config file to specify the configuration settings that are to be used in custom timer jobs. Open the OWSTIMER.EXE.CONFIG and add the <appSettings> tag to it. Then add your key value pairs under this appSettings tag For this you have to add a reference to System.Configuration Then you can use the  System.Configuration. ConfigurationManager .AppSettings[ key ]  to retrieve the values for a key from the config file. Example:  string dept = System.Configuration. ConfigurationManager .AppSettings[ "Department" ];

Create User Profiles using SharePoint Object Model

In this post i will show you how you can use the SharePoint object model to create User Profiles programmatically. For the code to work make sure you have a User Profile Service application created and associated to your web application. You have to add references to two assemblies which will be available in the 14 hive/ISAPI Microsoft.Office.Server Microsoft.Office.Server.UserProfiles You have to get the ServiceContext first and then get the UserProfileManager from the service context. The UserProfileManager provides ways to add and edit profile to your SharePoint. string  socialDataStatsSite = "http://servename:port/" ; using ( SPSite siteColl = new SPSite (socialDataStatsSite)) { SPServiceContext serviceContext = SPServiceContext .GetContext(siteColl); UserProfileManager userProfileManager = new UserProfileManager (serviceContext); UserProfile profile = null ; bool existingUser = userProfileManager.UserExists(AccountName); if (existingUser) { profile = userPr