class FileVersionEvent
Represents an event object that occurred on a Microsoft SharePoint SPFile, providing access to event metadata such as type, editor, and sharing information.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/versions/event.py
8 - 34
simple
Purpose
This class encapsulates event data for file operations in Microsoft SharePoint. It provides read-only access to event properties including the event type, the user who initiated the event, and sharing-related information (shared by user and shared with users). It inherits from Entity, which likely provides base functionality for SharePoint entities. The class is designed to be instantiated with event data and queried for specific event attributes through property accessors.
Source Code
class FileVersionEvent(Entity):
"""Represents an event object happened on a Microsoft.SharePoint.SPFile."""
@property
def event_type(self):
# type: () -> Optional[str]
"""Returns the type of the event."""
return self.properties.get("EventType", None)
@property
def editor(self):
# type: () -> Optional[str]
"""Returns the name of the user who initiated the event."""
return self.properties.get("Editor", None)
@property
def shared_by_user(self):
"""Returns the shared by user Information in sharing action for change log."""
return self.properties.get("SharedByUser", SharedWithUser())
@property
def shared_with_users(self):
# type: () -> ClientValueCollection[SharedWithUser]
"""Returns the array of users that have been shared in sharing action for the change log."""
return self.properties.get(
"SharedWithUsers", ClientValueCollection(SharedWithUser)
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
__init__: The constructor is inherited from the Entity base class. Typically, Entity classes in the office365 library are instantiated with a context object and optionally a resource path. The exact parameters depend on the Entity base class implementation, but generally include: context (ClientContext) - the SharePoint client context for API operations, and resource_path (Optional[ResourcePath]) - the path to the SharePoint resource.
Return Value
Instantiation returns a FileVersionEvent object that represents a SharePoint file event. The class provides four property accessors: event_type returns Optional[str] indicating the type of event; editor returns Optional[str] with the name of the user who initiated the event; shared_by_user returns SharedWithUser object (or default empty instance) containing information about who shared the file; shared_with_users returns ClientValueCollection[SharedWithUser] containing an array of users the file was shared with.
Class Interface
Methods
@property
event_type(self) -> Optional[str]
property
Purpose: Returns the type of the event that occurred on the SharePoint file
Returns: Optional[str] - The event type string if available, None otherwise. Examples might include 'Modified', 'Shared', 'Renamed', etc.
@property
editor(self) -> Optional[str]
property
Purpose: Returns the name of the user who initiated the event
Returns: Optional[str] - The username or display name of the user who triggered the event, None if not available
@property
shared_by_user(self) -> SharedWithUser
property
Purpose: Returns information about the user who shared the file in a sharing action
Returns: SharedWithUser - An object containing information about the user who performed the sharing action. Returns an empty SharedWithUser instance if not present in the change log
@property
shared_with_users(self) -> ClientValueCollection[SharedWithUser]
property
Purpose: Returns the collection of users that the file was shared with in a sharing action
Returns: ClientValueCollection[SharedWithUser] - A collection of SharedWithUser objects representing all users the file was shared with. Returns an empty collection if no sharing occurred
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
dict | Inherited from Entity base class. Stores the raw property data retrieved from SharePoint API, accessed by property methods using get() with default values | instance |
Dependencies
office365typing
Required Imports
from office365.sharepoint.files.versions.event import FileVersionEvent
from office365.runtime.client_value_collection import ClientValueCollection
from office365.sharepoint.entity import Entity
from office365.sharepoint.sharing.shared_with_user import SharedWithUser
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.versions.event import FileVersionEvent
# Authenticate to SharePoint
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite').with_credentials(
UserCredential('username@domain.com', 'password')
)
# Typically obtained from a file's version history
file = ctx.web.get_file_by_server_relative_url('/sites/yoursite/documents/file.docx')
versions = file.versions
ctx.load(versions)
ctx.execute_query()
# Access event information (events would be part of version data)
for version in versions:
# Assuming version has events property
if hasattr(version, 'events'):
for event in version.events:
if isinstance(event, FileVersionEvent):
print(f'Event Type: {event.event_type}')
print(f'Editor: {event.editor}')
print(f'Shared By: {event.shared_by_user}')
print(f'Shared With: {len(event.shared_with_users)} users')
for user in event.shared_with_users:
print(f' - {user}')
Best Practices
- This class is read-only and designed for querying event data, not for creating or modifying events
- Always check if property values are None before using them, as event_type and editor return Optional[str]
- The shared_by_user property returns a default empty SharedWithUser object if not present, so check its properties rather than None
- The shared_with_users property returns a ClientValueCollection which can be iterated even if empty
- Instances are typically obtained from SharePoint API responses rather than manually instantiated
- The class inherits from Entity, so it may have additional methods and properties from the base class for property management and API operations
- Use within a proper SharePoint ClientContext to ensure authentication and API connectivity
- Properties are lazily evaluated from the internal properties dictionary, so ensure data is loaded via execute_query() before accessing
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class FileVersion 61.1% similar
-
class LogFileInfo 58.7% similar
-
class FileVersionCollection 58.5% similar
-
class AbstractFile 58.3% similar
-
class SPAuthEvent 57.3% similar