0

I was wondering if it was possible to modify the default document library view "All Documents " to include the "Checked Out To" column.

I need this change to apply to any existing document libraries as well as any created in the future.

2 Answers 2

2

You could modify the default document library, but it's not a good idea to modify any of the standard files that ship with SharePoint as future updates may remove your customisations (or worse, your customisations may prevent future updates).

A better idea would be to either create your own custom library definition and deploy it as a Feature, or simply create and modify a Document Library to suit, save it as a Template in the List Template Gallery, and use that in future for all new libraries. Toni's code will update any existing libraries.

1
  • +1 for Brian: If you need to create for future doclibs it's much better to create a new template. Commented Jul 9, 2010 at 8:33
1

You could use the following code to make the desired changes. It worked for me with similar requirements. In case you have a large site collection you might wanna try to break this and do it site by site or something. AFAIK code approach is the only option.

The sample below is C# Console App, but you could modify it to work as PowerShell script or something.

using(SPSite siteCollection = new SPSite("http://your_sitecollection_url/"))
        {
            foreach (SPWeb web in siteCollection.AllWebs)
            {
                using (web)
                {
                    for (int i = 0; i < web.Lists.Count; i++)
                    {
                        SPList list = web.Lists[i];
                        if (list is SPDocumentLibrary && list.Fields.ContainsField("Checked Out To"))
                        {
                            foreach (SPView view in list.Views)
                            {
                                if (view.Title == "All Documents")
                                {
                                    if (!view.ViewFields.Exists("CheckoutUser"))
                                    {
                                        Console.WriteLine("Updating \"All Documents\" view for: {0}", list.DefaultViewUrl);

                                        SPField field = list.Fields["Checked Out To"];
                                        view.ViewFields.Add(field);
                                        view.Update();
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
1
  • I was hoping I could do this by editing an xml file so that this column automatically appears for newly created document libraries
    – Anonymous
    Commented Jul 9, 2010 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.