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 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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
+1 for Brian: If you need to create for future doclibs it's much better to create a new template. –  Toni Frankola Jul 9 '10 at 8:33
add comment

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;
                                }
                            }
                        }
                    }
                }
            }
        }
share|improve this answer
    
I was hoping I could do this by editing an xml file so that this column automatically appears for newly created document libraries –  Anonymous Jul 9 '10 at 0:49
add comment

Your Answer

 
discard

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