🔍 Code Extractor

class CheckedOutFile

Maturity: 49

Represents a checked-out file in a SharePoint document library or workspace, providing methods to manage checkout state and access checkout metadata.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/checked_out_file.py
Lines:
8 - 49
Complexity:
moderate

Purpose

This class models a file that has been checked out in SharePoint, allowing operations like taking over a checkout from another user and accessing information about who checked out the file. It extends the Entity base class to provide SharePoint-specific functionality for managing file checkout states in document libraries and workspaces.

Source Code

class CheckedOutFile(Entity):
    """Represents a checked-out file in a document library or workspace."""

    def takeover_checkout(self):
        """Instructs the site that another user account is taking over control of a currently checked-out file."""
        qry = ServiceOperationQuery(self, "TakeOverCheckOut")
        self.context.add_query(qry)
        return self

    @property
    def checked_out_by_id(self):
        """Returns the user ID of the account used to check out the file.
        :rtype: int or None
        """
        return self.properties.get("CheckedOutById", None)

    @property
    def checked_out_by(self):
        """Returns the user name of the account used to check out the file."""
        return self.properties.get(
            "CheckedOutBy",
            User(self.context, ResourcePath("CheckedOutBy", self.resource_path)),
        )

    @property
    def property_ref_name(self):
        return "CheckedOutById"

    def get_property(self, name, default_value=None):
        if default_value is None:
            property_mapping = {"CheckedOutBy": self.checked_out_by}
            default_value = property_mapping.get(name, None)
        return super(CheckedOutFile, self).get_property(name, default_value)

    def set_property(self, name, value, persist_changes=True):
        super(CheckedOutFile, self).set_property(name, value, persist_changes)
        # fallback: create a new resource path
        if name == "CheckedOutById":
            self._resource_path = EntityPath(
                value, self.parent_collection.resource_path
            )
        return self

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: The SharePoint client context object that manages communication with the SharePoint server. Inherited from Entity base class.

resource_path: The resource path identifying this checked-out file entity in the SharePoint hierarchy. Inherited from Entity base class.

Return Value

Instantiation returns a CheckedOutFile object representing a specific checked-out file. The takeover_checkout() method returns self for method chaining. Properties return either primitive types (checked_out_by_id returns int or None) or complex objects (checked_out_by returns a User object).

Class Interface

Methods

takeover_checkout() -> CheckedOutFile

Purpose: Instructs SharePoint that the current user account is taking over control of a file currently checked out by another user

Returns: Returns self (the CheckedOutFile instance) to enable method chaining

@property checked_out_by_id() -> int | None property

Purpose: Returns the user ID of the account that checked out the file

Returns: Integer user ID if file is checked out, None otherwise

@property checked_out_by() -> User property

Purpose: Returns the User object representing the account that checked out the file

Returns: User object with details about the user who checked out the file

@property property_ref_name() -> str property

Purpose: Returns the reference property name used for identifying this entity

Returns: String 'CheckedOutById' which is the key property for this entity

get_property(name: str, default_value: Any = None) -> Any

Purpose: Retrieves a property value by name with fallback to default value and special handling for complex properties

Parameters:

  • name: The name of the property to retrieve
  • default_value: Optional default value to return if property is not found. If None, uses internal property mapping for complex objects

Returns: The property value, which may be a primitive type or complex object like User

set_property(name: str, value: Any, persist_changes: bool = True) -> CheckedOutFile

Purpose: Sets a property value and optionally persists changes. Special handling for CheckedOutById updates the resource path

Parameters:

  • name: The name of the property to set
  • value: The value to assign to the property
  • persist_changes: Whether to persist the change immediately (default True)

Returns: Returns self (the CheckedOutFile instance) to enable method chaining

Attributes

Name Type Description Scope
context ClientContext The SharePoint client context managing server communication (inherited from Entity) instance
properties dict Dictionary storing the entity's properties including CheckedOutById and CheckedOutBy (inherited from Entity) instance
_resource_path ResourcePath Internal resource path identifying this entity in SharePoint hierarchy, automatically updated when CheckedOutById changes (inherited from Entity) instance
parent_collection EntityCollection Reference to the parent collection containing this entity (inherited from Entity) instance

Dependencies

  • office365.runtime.paths.resource_path
  • office365.runtime.paths.v3.entity
  • office365.runtime.queries.service_operation
  • office365.sharepoint.entity
  • office365.sharepoint.principal.users.user

Required Imports

from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.paths.v3.entity import EntityPath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.principal.users.user import User

Usage Example

# Assuming you have a SharePoint context and a checked-out file reference
from office365.sharepoint.files.checked_out_file import CheckedOutFile

# Get a checked-out file instance (typically retrieved from a collection)
checked_out_file = context.web.get_file_by_server_relative_url('/sites/mysite/doc.docx')

# Access checkout information
user_id = checked_out_file.checked_out_by_id
user = checked_out_file.checked_out_by
print(f"File checked out by user ID: {user_id}")

# Take over the checkout from another user
checked_out_file.takeover_checkout()
context.execute_query()

# Chain method calls
checked_out_file.takeover_checkout().get_property('CheckedOutBy')
context.execute_query()

Best Practices

  • Always call context.execute_query() after takeover_checkout() to commit the operation to SharePoint
  • Check permissions before attempting to take over a checkout, as this requires appropriate SharePoint permissions
  • Use the checked_out_by_id property for quick checks, and checked_out_by when you need full user details
  • The takeover_checkout() method returns self, enabling method chaining for fluent API usage
  • When setting CheckedOutById property, the resource path is automatically updated to reflect the new entity path
  • Properties are lazily loaded from the internal properties dictionary, so ensure data is loaded before accessing
  • The class inherits from Entity, so all Entity methods and lifecycle patterns apply
  • Use get_property() and set_property() methods for dynamic property access with proper fallback handling

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class CheckedOutFileCollection 86.9% similar

    A collection class for managing checked-out files in SharePoint, providing methods to query and retrieve files that are currently checked out.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/checked_out_file_collection.py
  • class FileCollection 62.2% similar

    FileCollection is a class that manages a collection of File resources in SharePoint, providing methods to upload, add, and retrieve files from a folder or document library.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/collection.py
  • class DiscardCheckoutFacet 59.9% similar

    A client value class representing a SharePoint discard checkout facet, used to model the discard checkout operation in SharePoint activities.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/activities/facets/discard_checkout.py
  • class SharedWithMeDocument 57.4% similar

    Represents a shared document in SharePoint with metadata about authors, editors, modification dates, and document properties.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/userprofiles/sharedwithme/document.py
  • class FileVersionEvent 56.8% similar

    Represents an event object that occurred on a Microsoft SharePoint SPFile, providing access to event metadata such as type, editor, and sharing information.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/versions/event.py
← Back to Browse