3


I want to create a documentlibrary on the parent site of a bunch of subsites. All those subsites have their own documents. I want the parent documentlibrary to contain all those documents of the sub sites. How can I accomplish this.

Greets.

3

If you really really want to duplicate your SharePoint data twice then you can do something like this,

private IEnumerable<SPFile> AddDocuments()
{
    using(SPSite site = new site(URL Of Your Parent Site goes here))
    using(SPWeb web = site.OpenWeb())
    {
        foreach(SPWeb subweb in web.Webs)
        {
            foreach(SPList oList in subweb.lists)
            {
                if (oList.BaseType == SPBaseType.DocumentLibrary)
                {
                    return ExploreFolder(myDocLib.RootFolder);
                }
            }
        }
    }   
}

private IEnumerable<SPFile> ExploreFolder(SPFolder folder) 
{ 
    foreach(SPFile file in folder)
    {
        yield return file;
    }
    foreach(SPFolder subFolder in folder.SubFolders)
    {
        foreach(SPFile file in ExploreFolder(folder))
        {
            yield return file;
        }

    }
}

I developed this code on Note pad so there might be some compilation errors, other then that you can add more code to it so that you can add returned SPFile to your newly created document library.

Once above step is done, you can add event receivers to all of your sub web's document libraries so that if a new document is added you copy it to your parent doc library too.

But If you are using SharePoint 2010, you can use Document Repository or configure Send To settings.

1

A Document Library is a place to store documents, not a place to reference documents in other places. What it sounds like you want is some sort of index of all the documents in the subsites; for that, I believe the Content Query Web Part may fit the bill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.