コード例 #1
0
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)
コード例 #2
0
ファイル: listitem.py プロジェクト: franciscomcdias/SpoKlient
 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"))
コード例 #3
0
 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
コード例 #4
0
ファイル: klient.py プロジェクト: franciscomcdias/SpoKlient
 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
コード例 #5
0
 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
コード例 #6
0
 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
コード例 #7
0
    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
コード例 #8
0
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)
コード例 #9
0
 def get_by_url(self, url):
     """Retrieve File object by url"""
     return File(
         self.context,
         ResourcePathServiceOperation(self.context, self.resource_path,
                                      "GetByUrl", [url]))