class FileCreationInformation
A data transfer object (DTO) class that encapsulates properties required for creating a file in a SharePoint FileCollection, including URL, overwrite flag, and content.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/files/creation_information.py
4 - 26
simple
Purpose
This class serves as a parameter object for the FileCollection.Add method in SharePoint operations. It bundles together all necessary information for file creation: the target URL (relative or absolute), whether to overwrite existing files, the file content (as string or bytes), and an optional XorHash for integrity verification. It inherits from ClientValue, making it serializable for transmission to SharePoint services.
Source Code
class FileCreationInformation(ClientValue):
"""Represents properties that can be set when creating a file by using the FileCollection.Add method."""
def __init__(self, url=None, overwrite=False, content=None):
"""
:param str url: Specifies the URL of the file to be added. It MUST NOT be NULL. It MUST be a URL of relative
or absolute form. Its length MUST be equal to or greater than 1.
:param bool overwrite: Specifies whether to overwrite an existing file with the same name and in the same
location as the one being added.
:param str or bytes content: Specifies the binary content of the file to be added.
"""
super(FileCreationInformation, self).__init__()
self.Url = url
self.Overwrite = overwrite
self.Content = content
self.XorHash = None
def to_json(self, json_format=None):
return {"overwrite": self.Overwrite, "url": self.Url}
@property
def entity_type_name(self):
return None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
url: The URL where the file will be created. Can be relative or absolute. Must be non-null and have length >= 1. This specifies the destination path for the new file within the SharePoint site or document library.
overwrite: Boolean flag indicating whether to replace an existing file at the same URL. If True, any existing file will be overwritten; if False, the operation may fail if a file already exists at the target location. Defaults to False.
content: The actual file content to be uploaded. Can be provided as either a string (for text files) or bytes (for binary files). This is the data that will be written to the created file.
Return Value
Instantiation returns a FileCreationInformation object with the specified properties set. The to_json() method returns a dictionary containing 'overwrite' and 'url' keys for serialization. The entity_type_name property returns None, indicating this is a value object rather than an entity.
Class Interface
Methods
__init__(url=None, overwrite=False, content=None)
Purpose: Initializes a new FileCreationInformation instance with file creation parameters
Parameters:
url: The destination URL for the file (relative or absolute, length >= 1)overwrite: Whether to overwrite existing files at the same location (default: False)content: The file content as string or bytes (default: None)
Returns: A new FileCreationInformation instance
to_json(json_format=None) -> dict
Purpose: Serializes the object to a JSON-compatible dictionary for API transmission
Parameters:
json_format: Optional format parameter (currently unused in implementation)
Returns: Dictionary with 'overwrite' and 'url' keys containing their respective values
entity_type_name -> None
property
Purpose: Returns the entity type name for this value object (always None for value objects)
Returns: None, indicating this is a value object rather than an entity
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
Url |
str | The URL where the file will be created (relative or absolute path) | instance |
Overwrite |
bool | Flag indicating whether to overwrite existing files at the target URL | instance |
Content |
str | bytes | The actual file content to be uploaded (text or binary data) | instance |
XorHash |
str | None | Optional hash value for file integrity verification (typically set by the system) | instance |
Dependencies
office365
Required Imports
from office365.runtime.client_value import ClientValue
Usage Example
from office365.runtime.client_value import ClientValue
from office365.sharepoint.files.file_creation_information import FileCreationInformation
# Create file info for a text file
file_info = FileCreationInformation(
url='Documents/example.txt',
overwrite=True,
content=b'Hello, World!'
)
# Access properties
print(file_info.Url) # 'Documents/example.txt'
print(file_info.Overwrite) # True
# Serialize to JSON for API call
json_data = file_info.to_json()
print(json_data) # {'overwrite': True, 'url': 'Documents/example.txt'}
# Typically used with FileCollection.Add:
# folder.files.add(file_info).execute_query()
Best Practices
- Always provide a valid URL with length >= 1 when instantiating this class
- Use bytes for binary file content and string for text content to ensure proper encoding
- Set overwrite=True only when you intentionally want to replace existing files
- This is an immutable-style DTO - set all properties during instantiation rather than modifying after creation
- The XorHash attribute is optional and typically set by the system for integrity verification
- This object is meant to be passed to FileCollection.Add() method, not used standalone
- The to_json() method only serializes url and overwrite; content is handled separately in the upload process
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class ContentTypeCreationInformation 78.3% similar
-
class AttachmentCreationInformation 78.1% similar
-
class GroupCreationInformation 75.1% similar
-
class ListItemCreationInformation 74.5% similar
-
class WebCreationInformation 73.0% similar