Wednesday, 26 January 2011

Add/remove sharepoint group using power shell

#Add a sharepoint group using power shell

#Create a sharepoint custom permission using Power shell

$web = get-SPWeb "http://sitecollectionName"
$member = $web.AllUsers["domain\username"]
$CustomPermission ="Permission Name"
$CustomRoleRoledef = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$CustomRoleRoledef.Name = "$CustomPermission"
$CustomRoleRoledef.Description = "Custom permission level for Site Owners"
$CustomRoleRoledef.BasePermissions =

# Create custom group
$CustomGroup ="My Custom Group"
$web.SiteGroups.Add("$CustomGroup", $member, $null,"Custom Group ")

#Assign Permission to the Group
$customPermission = $web.RoleDefinitions["$CustomRoleRoledef "]
# If you don't want to use custom permission, you can directly give existing permission name i.e "Full Control/Contributor/Design/Visitor"
#$existingPermission = $web.RoleDefinitions["Design"]
$customPermissionAssignment = New-Object "Microsoft.SharePoint.SPRoleAssignment" -ArgumentList $web.SiteGroups["$CustomGroup"]

#Remove a sharepoint group using power shell

#Remove Groups if already exist
$GroupName ="Custom Group"
$objSiteGroup = $web.SiteGroups["$GroupName"]
if ($objSiteGroup)

Note: you can save above script in .ps1 extension file and execute in power shell

Monday, 24 January 2011

The Server Returned a non-specific error when trying to get data from the data source

This issue occurs when you do backup restore of the site/site collection. Due to this you can not see the page in design mode due to some reference changes and will not be able to add any new data sources on the page.

To resolve this issue follow below steps.

1. Go to Insert - New Item Form
2. Click on Custom List Form
3. Choose your custom list.
4. Choose form type (new/edit/display).
5. Select the "DataSources" section of the newly created dataformwebpart.
6. Now replace the existing "Datasources" section with selected one.
7. Remove the old DataFormweb part.

Just after saving the form mentioned error should go and you should be able to see all the controls with existing binding.

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...