koltyakov / gosip

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

fix: checkGetRelativeURL method with empty relative URI edge case, #70 #72

Closed koltyakov closed 7 months ago

koltyakov commented 7 months ago

The PR fixes #70 and adds corresponding edge case test.

bangbaew commented 7 months ago

Thank you, the program doesn't panic now, but it still does not work as expected when I'm trying to ensure a single folder

sp.Web().EnsureFolderByPath("Original Requests") // gives Microsoft.SharePoint.Client.UnknownError from server

image

sp.Web().EnsureFolderByPath("/Original Requests") // no error thrown, but nothing created

it works fine when it has at least one child path

sp.Web().EnsureFolderByPath("Root Path/Child Path") // works just fine
koltyakov commented 7 months ago

Hey @bangbaew,

Not completely sure, how to repro. I'm checking different variations, using a test:

t.Run("EnsureFolderByPathEdgeCases", func(t *testing.T) {
  if envCode == "2013" {
    t.Skip("is not supported with SP 2013")
  }

  res, err := web.EnsureFolderByPath("Shared Documents")
  if err != nil {
    t.Error(err)
  }

  fmt.Printf("Folder Name: %s\n", string(res.Data().Name))
})

and it worked:

=== RUN   TestWeb
=== RUN   TestWeb/EnsureFolderByPathEdgeCases
Folder Name: Shared Documents
--- PASS: TestWeb (0.18s)
    --- PASS: TestWeb/EnsureFolderByPathEdgeCases (0.18s)
PASS
ok      github.com/koltyakov/gosip/api  1.876s

Are you sure that your folder is actually an SPFolder but not a sub site (SPWeb)?


sp.Web().EnsureFolderByPath("/Original Requests")

This is incorrect way of using the method. If the "Original Requests" is the folder name it should be prefixed with a document library path.

sp.Web().EnsureFolderByPath("DocLib/Original Requests") // DocLib should exist

or

sp.Web().EnsureFolderByPath("/sites/site/DocLib/Original Requests") // DocLib should exist

Yet, if you'd provided something crazy, you'd got: unable to request api: 404 Not Found :: {"error":{"code":"-2147024894, System.IO.FileNotFoundException","message":{"lang":"en-US","value":"File Not Found."}}}.

bangbaew commented 7 months ago

I think it's a document library which is listed on the navigation bar of the page, so is it possible to ensure a document library with this function? image

koltyakov commented 7 months ago

It could be anything added to quick launch menu. 😄 When you open it, what's the URL?

In this test web.EnsureFolderByPath("Shared Documents") "Shared Documents" is a document library and the method works just fine.

bangbaew commented 7 months ago

The url when I clicked on a manually created document library is https://{Host}:{Port}/sites/{Site Name}/{Sub Site}/{Document Library}/Forms/AllItems.aspx

my site url in the configuration is https://{Host}:{Port}/sites/{Site Name}/{Sub Site}

I'm trying to create the {Document Library} which does not exist with

sp.Web().EnsureFolderByPath("{Document Library}") 
koltyakov commented 7 months ago

Document Library (or a List) is not a folder. You can't create it using EnsureFolderByPath method.

If you have a Document Library and need to use/create a folder structure, this is the method to use.

You can create a library using:

newLib, err := sp.Web().Lists().Add("My Lib", map[string]interface{}{
  "BaseTemplate": 101, // Document Library
})

Yet, SharePoint Lists and Libraries provisioning is a bit complex topic. There is a lot you'd need to do with falling back to CSOM. Though, for a generic containers without sophisticated artifacts content types, fields, views, etc.; sp.Web().Lists().Add or sp.Web().Lists().AddWithURI are fine.

bangbaew commented 7 months ago

It works now! Thank you so much.