Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.


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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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