views:

108

answers:

4

Hi all:

I'm currently creating a large number of SharePoint folders within a list (e.g. ~800 folders), with each folder containing a different number of items. The way it is currently done is that it programmatically reads off the content types, items, event listeners and the likes off the same folder from another web, then creates the same folder in the current web.

That ran reasonably fine and fast on a dev environment. However when it goes to an environment with WFEs and farms, it slowed down a lot. I have checked that there are no leaks in the code, and that the code follows SharePoint coding best practices.

At the moment I'm looking at it at the code level. From your experience, are there any efficient ways of creating a large number of SharePoint folders, lists and items?

EDIT: I'm currently using SharePoint API, but will be looking at moving to using Web Service in the future. I'm interested in looking at both options though. Code wise, its just the general reading of a folder and its content types plus items and their details, then create the same folder in the same list with the same content types, then copy over the items using patch update. I want to know whether there are more efficient ways of doing the above.

Thanks.

+1  A: 

This is how I would do it via SharePoint's API in PowerShell. This same method could be easily translated to C#.

[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null;
[array]$folders = "A","B","C","D","E","F","G";
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://intranet");
$OpenWeb = $SpSite.OpenWeb("/departments/Branding");
$OpenList = $OpenWeb.Lists["Test"];

foreach ($folder in $folders)
{
    $exists = $OpenList.Folders | Select-Object -Property Name | Where {$_.Name -eq $folder.ToString()}
    if ($exists.Name -eq $folder) { $folder + " already exists!"; }
    else
    {
        $item = $OpenList.Folders.Add("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folder);
        $item.Update();
        $folder + " Created!";
    }
}
$SPSite.Dispose();
Mitchell Skurnik
@Mitchell Skurnik: are there any ways to speed up the creation process? Currently I'm manually copying all the content types of every single folder, its permissions, etc, and that alone is already a very slow and tedious process.
BeraCim
What exactly are you copying? Are you duplicating something that already exists? I.E. are you creating something for each site?
Mitchell Skurnik
Some things on SharePoint take a long time to do. I have a process that imports every single user from Active Directory into SharePoint. To process 600 groups and 1400 users it takes about 3 hours. SharePoint has a bit of overhead when it comes to certain things. Now I have high end hardware and this happens. I was able to cut down this process from a 6 hour process to the current 3...so optimizaiton is possible. Please answer my previouse questions and I might be able to help you.
Mitchell Skurnik
@Mitchell Skurnik: I'm trying to copy folders I've created from one web to another. Every folder has its own security settings, content types, items, etc, so every tiny detail needs to be carefully copied. You can say it is like manually cloning something. There are potentially 800+ of folders to copy, and the process took quite a while to complete using standard method and SharePoint API. I also have lists and folders to copy at the Site level, and that's taken a while also. I've been looking out for ways to cut down the processing time, and coding is the first thing to look at. Thanks.
BeraCim
+2  A: 

You could use Batch Updating to create the folders and items. This is much faster as creating item by item.

To read the source folder structure you could increase performance with a CAML query.

Jason
A: 

Try this: In your document library, go to settings --> Site settings and click "Save document library as template" and choose include content. Now this will not keep your security settings but should get you half way there. From there try to programatically set the permissions.

Another thing you can try is to use http://www.sharepointproducts.com/products/default.aspx 's copy move. It will bulk move/copy anything and keep the user's permissions. I would run it from the service account, that way you may be able to programatically call it from the server. It only allows one person to do this in the free version. A small price to pay for a free program :).
-----EDIT-----

I found something else on CodePlex that might assist you: http://sprsync.codeplex.com/. Check out the source code as it might get you started

Mitchell Skurnik
A: 

Try doing an export of the source site and then an import into the new location. Are you trying to move just the folders and not any of the documents?

Kelly French
@Kelly French: I'm trying to programmatically copy folders and lists and their items/documents/content types/permissions to another web. Everything has to be done programmatically.
BeraCim