Categories
Coding Server

Hiding SharePoint WebParts via Code

Another note to myself…

When wanting to programmatically hide a WebPart, don’t try to set it’s Visible property to False. This will cause you lots of trouble and create errrors. The correct method is to set its Hidden property to True.

if (items.Count == 0)
{
   this.Hidden = true;
   return;
}

 

Categories
Server

Set Up Groups for this Site

Note to self: Once a site has been created within SharePoint 2010, the ‘Set Up Groups for this Site’ admin page is hidden away – but you can set access it via /_layouts/permsetup.aspx.

Categories
Server

SharePoint & Item-Level Permissions within Document Libraries

I have a love/hate relationship with SharePoint. Often the things that should be really simple, just aren’t. Take the “Item-level Permissions” option for instance. Every list appears to have this option (available via List Settings > Advanced Settings) except for document libraries. I’m sure the SharePoint Development Team at Microsoft have a very good reason for this…

Step forth PowerShell!

$web = Get-SPWeb http://mysharepointsite
$list = $web.Lists[“A Document Library”]
$list.ReadSecurity = 2
$list.WriteSecurity = 2
$list.Update()
$web.Dispose()

The ReadSecurity value can be one of the following:

1 = “Read all items”
2 = “Read items that were created by the user”

The “Create and Edit access” option can also be set by specifiying a value for WriteSecurity.

1 = “Create and edit all items”
2 = “Create items and edit items that were created by the user”
4 = “None”

Categories
Server

Hiding Fields in SharePoint 2010

This is a useful peice of PowerShell script to hide specific fields from the Edit form. ShowInEditForm can also be amended to ShowInNewForm.

$assignment = Start-SPAssignment
$web = Get-SPWeb http://mysharepointserver -AssignmentCollection $assignment
$field = $web.Lists["Announcements"].Fields["Body"]
$field.ShowInEditForm = $False
$field.Update()
Stop-SPAssignment $assignment

Categories
Server

SPListItem URLs

There seems to be no built-in function or property to quickly return the correct URL for a SharePoint list item. The obvious property, SPListItem.URL, always returns an invalid URL along the lines of http://sharepoint/Lists/MyList/155_.000. Not ideal.

To get around this and return a correctly formatted web address, you can use the following code:

item.Web.Url + "/" + item.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID

Categories
Server

Organising SharePoint Documents

I’ve been thinking about this for a while (how best to organise documents within a SharePoint website – whether to use document libraries or metadata) and have just stumbled across two blog posts, by Dustin Miller and Bil Simser, which seem to answers my queries.