0

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 ?

2
  • The user executing the code doesn't have the ability to see checked out files possibly? Oct 2, 2012 at 22:49
  • But why does code fragment 2 work correctly, and code fragment 1 does not work ? It does not look permission related ? Oct 4, 2012 at 7:29

1 Answer 1

1

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());    
            }

        }

Your Answer

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

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