Paul Lee

Sharepoint bumps and bruises

  Home  |   Contact  |   Syndication    |   Login
  11 Posts | 0 Stories | 7 Comments | 0 Trackbacks

News

Archives

Post Categories

I have been involved in a huge public folder migration project for my company. One particular folder I migrated had a hierarchy of 1500 subfolders. The migration tool was nice enough to migrate the permissions for me for each folder into sharepoint. Cool, right? Yes until my manager told me he just wanted to manage the parent folder in sharepoint and have the subfolders inherit everything.  There is nothing in sharepoint out-of-the-box that lets you do this in one shot.  Now there are probably many 3rd party sharepoint admin tools that will do this.  But here is the poor man's way.  Simple IronPython script.

import clr

clr.AddReference("Microsoft.SharePoint")
from Microsoft.SharePoint import SPSite

siteurl = '<url to site>'
url= '<url to doclib>'

site = SPSite(siteurl)
web = site.OpenWeb()

docLib = web.GetList(url)

myfolders = docLib.Folders

for furl in myfolders:
    furl.ResetRoleInheritance()

That's it!  Took me only 10 minutes to write...without knowing much about the sharepoint API.  The first 3 lines is the key here that lets you hook into the .NET framework and the sharepoint API. 

Please read my original post for a guide on installing (if you can call it that) IronPython. 

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Friday, May 01, 2009 3:02 PM

Feedback

# re: Make a subfolder hierarchy inherit from parent 8/17/2009 11:39 AM christopher bermingham
I like to see that more people are interacting w/ Sharepoint using IronPython. 1 question- did you leave off a dispose statement for your site object? In C# a using statement would suffice, but since that isn't available in IP in I have seen mention of replacing it with a try...finally... block or just explicitly calling dispose to avoid the dreaded Sharepoint memory leak.

# re: Make a subfolder hierarchy inherit from parent 8/17/2009 7:25 PM Paul Lee
Hi Christopher,

Thanks for the feedback. Excuse my ignorance on this but I thought that since the script ends immediately that I would not need a dispose statement. Am I wrong? Where would the memory leak come from if the IP program is done?

I do like IronPython alot but have been debating whether I should get into PowerShell instead for my scripting needs. Microsoft seems to use it extensively in 2010 for administration so I figure I should probably learn it.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: