koltyakov / gosip

⚡️ SharePoint SDK for Go
https://go.spflow.com
MIT License
140 stars 32 forks source link

Change Content Type and set props #73

Closed phhoef closed 6 months ago

phhoef commented 6 months ago

I am uploading a file to SPO and I want to change the document type and set a few specific props of that type. Setting the props are completely ignored, though no error is returned.

    file := web.GetFileByID(item.UniqueId)

    err := file.Props().SetProps(map[string]string{
        SPO_CONTENT_TYPE_ID:  t.StringId,
        "Source":                              "source",
        "Name":                                "blabla",
    })

Neither the ContentTypeId changed nor the properties are applied. Is something wrong with my code?

koltyakov commented 6 months ago

I believe you should update list item instead of file's property bags (which is different, key value pairs).

Something like:

item, err := web.GetFile("/Shared Documents/A File.txt").GetItem()
if err != nil {
  t.Error(err)
}
_, err = item.Update([]byte(`{
  "ContentTypeId": "0x010100B4CBD48E8F4F4BA4B8DCCD2A6A7A3E6A",
  "Title": "Updated Title"
}`))
phhoef commented 6 months ago

thanks @koltyakov! That was exactly, what I was looking for 😄 works like a charm ...