phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Add an attachment to a list item with custom AuthorId/EditorId field

Open vatsake opened this issue 2 years ago • 0 comments

I removed AuthorId and EditorId as readonly fields.

I'm using phpSPO to create list item as another user (know the ID). How can I send those fields when adding attachment?

        $list = $this->client->getWeb()->getLists()->getByTitle("listTitle");
        $ctx = $list->getContext();
        $listItem = $list->addItem([
            "Title" => "title",
            'Comment' => "comment",
            "AuthorId" => "id",
            "EditorId" => "id",
        ]);
        $ctx->executeQuery();
        $attCreationInformation = new AttachmentCreationInformation();
           
        $attCreationInformation->FileName = basename("filename");
        $attCreationInformation->ContentStream = file_get_contents("filepath");
        $listItem->getAttachmentFiles()->add($attCreationInformation);
        $ctx->executeQuery();

vatsake avatar Jan 11 '22 08:01 vatsake