3

I want to check in file which is check in/check out before and currently checked out by some another user. I have tried SPCheckedOutFile but this will return files which are checked out but never checked in before but in my case some files are checked in before and currently check out by some other user. I don't want to user RunWithElevatedPrivileges as i want to check in file user current user account.

I have write below code which is not working for files which are published at least one time.

using (SPSite site = new SPSite("SiteURL"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPDocumentLibrary list = web.Lists[documentLibraryName] as SPDocumentLibrary;

        IList<SPCheckedOutFile> files = list.CheckedOutFiles;
        foreach (SPCheckedOutFile file in files)
        {
            file.TakeOverCheckOut();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.