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've defined a Document Library named "Sales" on Sharepoint 2010. And I use the following code fragment to add all names who have checked out a file to a listbox:

lstCheckedOut.Items.Clear();

var docLib = SPContext.Current.Web.Lists["Sales"] as SPDocumentLibrary;

// Code fragment 1    
foreach (var doc in docLib.CheckedOutFiles) // No files are checked out ?
{
    lstCheckedOut.Items.Add(doc.CheckedOutBy.ToString());
}

// Code fragment 2
foreach (SPItem doc in docLib.Items)
{
    string name = doc["Checked Out To"] as string; // Just working fine ?

    if (!string.IsNullOrEmpty(name))
    {
        lstCheckedOut.Items.Add(name); 
    }
}

Why are no files present in the 'CheckedOutFiles' property ?

share|improve this question
    
The user executing the code doesn't have the ability to see checked out files possibly? –  PirateEric Oct 2 '12 at 22:49
    
But why does code fragment 2 work correctly, and code fragment 1 does not work ? It does not look permission related ? –  Stef Oct 4 '12 at 7:29
add comment

1 Answer

You can get all values of the file this way:

        lstCheckedOut.Items.Clear();

        var docLib = SPContext.Current.Web.Lists["Sales"] as SPDocumentLibrary;

        // Code fragment 1    
        foreach (SPListItem doc in docLib.Items)
        {
            if (doc.File.CheckedOutByUser!=null)
            {
                lstCheckedOut.Items.Add(doc.File.CheckedOutByUser.ToString() + " checked out " + doc.File.Name.ToString());    
            }

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