Showing posts with label Codeplex. Show all posts
Showing posts with label Codeplex. Show all posts

Saturday, August 29, 2009

Checking if user belongs to a group

Scenario:
Often we need to do some action depending upon as if user is part of certain sharepoint group or not.

Solution:
Simple function did the trick

Code:

public bool DoesUserExistInGroup(SPWeb web, SPUser user,string groupName)
{
//Retrieving all the user groups in the site/web
SPGroupCollection userGroups = user.Groups;

foreach (SPGroup group in userGroups)
{
//Checking the group
if (group.Name.Contains(groupName))
{
return true;
}
}
return false;
}

Friday, June 5, 2009

SPCore on Codeplex

Project Description
This project is a utility project and will help *Developers* and *Administrators* to code faster some of the most common tasks in sharepoint.

Download

Utility includes methods for :
Alerts , Web.Config , WebParts , Audit ,OOTBFile ,Timer , Navigation , Migration , Features and many more...

-- Add a webpart to a page
-- Add a custom security group
-- Add a custom permission level
-- Web Config modification for Net 3.5
-- many more...

How to use
download the binary and reference it in your project. Also you need to use the namespace in your classes.

_using SKN;_

Want to contribute
- code
- documentation
- usage samples
- input validation & robust error handling

please leave me a comment here : subject SPCore contribution

Follow on Twitter

Sharepoint Merge Web Config on Codeplex

Project Description:
This utility is great for merging the web.config files for sharepoint based web applications.

Limitations:
-- This will only work for SharePoint web applications ( WSS and MOSS )
-- This need to be executed on all the Web Front ends ( I know painful , but SPWebConfigModification class is buggy and unreliable ). I have tested it on Single Server Farm so far
-- This utility can be run only one time per web application
-- To run it again on same web application [ no recommended for Production ] , all the GUIDs for the merge file need to be renewed. Check the sample merge xml file

Advantage:
-- This can merge many files from the mergefile location

Download

Usage
1. Download the sample merge file and change it according to requirement

2. Download SPMergeWebConfig.exe and run the following command with proper parameters

SPMergeWebConfig.exe -file 'C:\Inetpub\wwwroot\wss\VirtualDirectories\80\' -mergefile 'C:\Inetpub\wwwroot\wss\VirtualDirectories\80\'

Note : -file parameter takes a location value where you web.config file reside
-mergefile paramter takes a location value for the merge file you downloaded , utility can accept more than one files with the file name pattern as +webconfig.*.xml+

Follow on Twitter

Tuesday, June 2, 2009

Adding webpart to a page using webpart file name

Scenario:
Adding webpart to a page using webpart file name

Code:

 public static void AddWebPartUsingFileName(SPWeb web, string pageName, string dwpFileName, string zoneID)
{
string errorMessage;

using (SPSite site = web.Site)
{
using (SPWeb rootWeb = site.RootWeb)
{
string url = rootWeb.Url + "/_catalogs/wp/" + dwpFileName;
XmlTextReader reader = new XmlTextReader(new StringReader(rootWeb.GetFileAsString(url)));
SPLimitedWebPartManager wpMgr = web.GetLimitedWebPartManager(pageName, PersonalizationScope.Shared);
WebPart webPart = (WebPart)wpMgr.ImportWebPart(reader, out errorMessage);
wpMgr.AddWebPart(webPart, zoneID, 1);
wpMgr.Web.Dispose();
}
}
}
Download :
This method is also a part of SPCore now ( http://spcore.codeplex.com )