In code below, at mentioned line I am getting this error: How I fix this?

SPList docLib = WSweb.GetList(WSweb.ServerRelativeUrl + "/Documents");
//SPList docLib = WSweb.Lists.TryGetList("Documents");
if (docLib != null) {

    SPDocumentLibrary docs = (SPDocumentLibrary) docLib;
    SPQuery checkedOutDocs = new SPQuery();
    checkedOutDocs.Query = @"<Where><IsNotNull>
         <FieldRef Name='CheckoutUser' />
          </IsNotNull></Where>
           <QueryOptions>
            <ViewAttributes Scope='RecursiveAll' />
            </QueryOptions>";
    checkedOutDocs.ViewFields = "<FieldRef Name='ID' />";
    checkedOutDocs.ViewFieldsOnly = true;
    SPListItemCollection items = docs.GetItems(checkedOutDocs);

    foreach(SPFile file in items) // At this line i am getting error
    {
        if (docmanager.getFileExtension(file.Item) == ".pdf") {
            if (file.LockId != null) {
                file.CheckIn("Checked in programatically!");
            }
        }

    }
}
有帮助吗?

解决方案

SPListItemCollection is a collection of SPListItem. Get File object from SPListItem. Example:

foreach (SPListItem item in items)
{
   SPFile file = item.File;
}

其他提示

Instead of using SPFile object use the SPListItem in foreach loop. And within the loop we can use the File property of SPListItem to get the SPFile object.

Try the below code...

foreach (SPListItem item in items){
SPFile file = item.File;
    if(docmanager.getFileExtension(item) == ".pdf"){
                if (file.LockId != null){
            file.CheckIn("Checked in programatically!");
                 }
        }
}
许可以下: CC-BY-SA归因
scroll top