def upload_file(context): upload_into_library = False path = "../tests/data/SharePoint User Guide.docx" with open(path, 'rb') as content_file: file_content = content_file.read() if upload_into_library: list_title = "Documents" library = context.web.lists.get_by_title(list_title) file = upload_file_into_library(library, os.path.basename(path), file_content) print("File url: {0}".format(file.properties["ServerRelativeUrl"])) else: target_url = "/Shared Documents/{0}".format(os.path.basename(path)) File.save_binary(context, target_url, file_content)
def file(self): """Get file""" if self.is_property_available("File"): return self.properties["File"] else: from spoklient.sharepoint.file import File return File(self.context, ResourcePathEntity(self.context, self.resource_path, "File"))
def get_file_by_server_relative_url(self, url): """Returns the file object located at the specified server-relative URL.""" file_obj = File( self.context, ResourcePathServiceOperation(self.context, self.resource_path, "getfilebyserverrelativeurl", [url]) ) return file_obj
def download_file(self, relative_url): """ Downloads as file by URL :param relative_url: :return: """ response = File.open_binary(self.context, relative_url) return response.content
def add_template_file(self, url_of_file, template_file_type): """Adds a ghosted file to an existing list or document library.""" file_new = File(self.context) qry = ClientQuery.service_operation_query( self, ActionType.PostMethod, "addTemplateFile", { "urlOfFile": url_of_file, "templateFileType": template_file_type }) self.context.add_query(qry, file_new) self.add_child(file_new) return file_new
def add(self, file_creation_information): """Creates a File resource""" file_new = File(self.context) qry = ClientQuery.service_operation_query( self, ActionType.PostMethod, "add", { "overwrite": file_creation_information.overwrite, "url": file_creation_information.url }, file_creation_information.content) self.context.add_query(qry, file_new) self.add_child(file_new) return file_new
def add(self, attachment_file_information): """Creates an attachment""" if isinstance(attachment_file_information, dict): attachment_file_information = AttachmentfileCreationInformation( attachment_file_information.get('filename'), attachment_file_information.get('content')) file_new = File(self.context) qry = ClientQuery.service_operation_query( self, ActionType.PostMethod, "add", { "filename": attachment_file_information.filename, }, attachment_file_information.content) self.context.add_query(qry, file_new) self.add_child(file_new) return file_new
def download_file(context): response = File.open_binary(context, "/Shared Documents/SharePoint User Guide.docx") with open("./data/SharePoint User Guide.docx", "wb") as local_file: local_file.write(response.content)
def get_by_url(self, url): """Retrieve File object by url""" return File( self.context, ResourcePathServiceOperation(self.context, self.resource_path, "GetByUrl", [url]))