0

I would like to modify the Document Library for each users mysite during creation to include a custom content type. I figured a feature would solve this problem. However, when activating the features and looking at the list available "Documents" is not available.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

    using (SPSite site = (SPSite)properties.Feature.Parent)
    {

        foreach (SPWeb web in site.AllWebs)
        {
            web.AllowUnsafeUpdates = true;
            //THINGS FALL APART!
            SPList docs = web.Lists.TryGetList("Documents"); 

            //Add Custom Content Type to List
            //SPContentType contentType = web.ContentTypes["Custom Document Type"];
            //docs.ContentTypesEnabled = true;
            //docs.ContentTypes.Add(contentType);
            //docs.Update();
            web.AllowUnsafeUpdates = false;
            web.Update();
        }

    }

I have the feature scope set to site ... I can see that the lists available includes "User Photos".

Any suggestions?

  • Just for understanding: You are activating the feature on a my site, once the my site is up and running (not sometime during a creation process or something)? And you would like to ensure that the Documents library on each web (!) has this content type? I'm asking because you're using AllWebs and not every web might have a "Documents" list. On which web did you see the "User Photos" list you are mentioning? – PzYon Oct 15 '14 at 8:00
  • @Pzyon, Ideally I would like to have my new custom content type added to mysite document libraries as the default on site creation, but I am trying to do things one step at a time. I was debugging the feature activation using my Farm account and I navigated to mysites.domain.com > Site Settings > Site Collection Features > My Feature > Activate. I have continued my search and some say that the documents (personal and shared) are not available at site creation time. Any thoughts? – KidCoke Oct 15 '14 at 13:45
  • Ok. So have a my site (site collection) which you can access in the browser. Then you manually activate your feature which tries to add the content type to the list. Correct? Can you see the list in Site Cettings then? I mean in the browser, not while debugging. I am just asking because on my my site the list is there and I do not see, why it shouldn't be there for you. – PzYon Oct 15 '14 at 14:02
  • @Pzyon I think you are on to something. I was trying to add the feature at mysites.domain.com, When I go to Site Settings > Site Lists and Libraries I don't see documents. If I navigate to mysites.domain.com/personal/user I can see the Documents list. How to I change the solution to target the /personal site? – KidCoke Oct 15 '14 at 14:32
  • You said it's a site collection scoped feature, that would mean you simply need to activate it on mysites.domain.com/personal/user. Just be aware that you iterate over every web in that site collection and try to add to content type to the "Documents" list. Maybe it's enough to just do it on the RootWeb? It depends on your needs.. If you really want to do it on every web, then maybe you should check if the list is actually there.. – PzYon Oct 15 '14 at 15:07

Your Answer

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

Browse other questions tagged or ask your own question.