Geeks With Blogs
Paul Lee Sharepoint bumps and bruises

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

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:

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. 


Posted on Friday, May 1, 2009 3:02 PM Iron Python and Sharepoint | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Make a subfolder hierarchy inherit from parent

# re: Make a subfolder hierarchy inherit from parent
Requesting Gravatar...
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.
Left by christopher bermingham on Aug 17, 2009 11:39 AM

# re: Make a subfolder hierarchy inherit from parent
Requesting Gravatar...
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.
Left by Paul Lee on Aug 17, 2009 7:25 PM

Your comment:
 (will show your gravatar)

Copyright © Paul Lee | Powered by: