Below you will find pages that utilize the taxonomy term “SPWeb”
Posts
PowerShell: Copy an entire document library from SharePoint 2007 to disk
For a while ago I needed to copy all files from a document library within a SharePoint 2007 site to the hard drive. So I didn’t need to copy files from SharePoint to SharePoint so I couldn’t use the stsadm -o export command or Chris O’Brien’s nice SharePoint Content Deployment Wizard. I came across the SPIEFolder application which should work with SharePoint 2007 and 2010. It has a site on codeplex: spiefolder.
Posts
Add global navigation links in Powershell and Feature Receiver
I think, powershell is the best way to do configurations you have to do once. Adding some links to global (top) navigation is one of them:
asnp microsoft.sharepoint.powershell $w = get-spweb http://takana $l = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Smells like team spirit", "/pages/teamspirit.aspx") $w.Navigation.TopNavigationBar.AddAsLast($l) Feature receiver The alternative is to create a web scoped feature and provide properties:
public override void FeatureActivated(SPFeatureReceiverProperties properties) { var web = properties.Feature.Parent as SPWeb; var prop = properties.
Posts
Working with web.Properties
Sometimes one may need more properties to track on a SPWeb beside Title and Description. One of the possibilities is to create a custom list (maybe a hidden one) with keys and values (Title and Value). It works fine. The good thing with it is also the possibility to change the key-value pair directly in the web interface. Another approach is to use web.Properties which is a Dictionary with key-values pairs.
Posts
Do an unsafe update in a unified manner
Recently I talked about a WithWeb-pattern as described in Jonas Nilssons blog where you can isolate the disposal logic in one place. Another thing is to isolate unsafe updates:
public static class SPWebExtension { public static void UnsafeUpdate(this SPWeb web, Action<SPWeb> action) { try { Log.Info("Trying to do an unsafe update on a web: " + web.Title); web.AllowUnsafeUpdates = true; action(web); } catch (Exception e) { Log.Error(e); } finally { web.
Posts
TryGetList
How do we get a list? Perhaps like that:
var list = web.Lists\[listname"\]; ```But we must be aware of exceptions that can appear and we must handle them. A better way to get a list is to use [TryGetList](http://sharepoint.stackexchange.com/questions/18035/custom-webpart-being-rendered-twice-on-layout-page): var list = web.Lists.TryGetList(listname);
Posts
WithWeb-pattern of Jonas Nilsson
Jonas Nilsson shows an interesting approach for working with SPSite and SPWeb which must be disposed. Create a helper method WithWeb and send an Action parameter:
public void WithWeb(string uri, Action<SPWeb> action) { using (SPSite site = new SPSite(uri)) { using (SPWeb web = site.OpenWeb()) { action(web); } } } ```Here is my implementation of this pattern: public static class DisposalService { public static void WithWeb(string uri, Action action) { using (var site = new SPSite(uri)) { using (var web = site.
Posts
Uppdatera web med js
Här är ett litet exempel:
function updateTitle() { var ctx = new SP.ClientContext.get\_current(); this.web = ctx.get\_web(); web.set\_title('Examensarbete 2011'); this.web.update(); ctx.executeQueryAsync( Function.createDelegate(this, this.onUpdate), Function.createDelegate(this, this.onFail)); } function onUpdate(sender, args) { alert('title updated'); } function onFail(sender, args) { alert('failed to update title. Error:'+args.get\_message()); }
Posts
Ge andra rättigheter på default.aspx
Om man inte vill medlemmarna på SPWeb rättighet att redigera första sidan hur som helst, måste man bryta arvet på Sidor/default.aspx. Lätt att göra det manuellt (Site Actions - Show all Content - Pages - default.aspx - dokumenträttigheter). I koden kan man göra det så här:
//first find SPListItem defaultAspx //then find SPGroup members (perhaps via web.AssociatedMemberGroup defaultAspx.BreakRoleInheritance(true); defaultAspx.RoleAssignments.RemoveFromCurrentScopeOnly(members); SPRoleAssignment roles = new SPRoleAssignment(members); SPRoleDefinition perms = web.RoleDefinitions.GetByType(SPRoleType.Reader); roles.RoleDefinitionBindings.Add(perms); defaultAspx.RoleAssignments.Add(roles);
Posts
~masterurl/default.master & ~masterurl/custom.master
Läser “SharePoint 2010 as a Development Platform”. Kan verkligen rekommendera den. Idag har jag förståt vad default.master och custom.master innebär. De pekar på de master-filer som är inställda på web-nivå. Så det är ingen idé att ändra DynamicMasterUrl i @Page-direktivet till sin egen (om du inte vill ha någon helt annan master än i resten av portalen).