Download & upload files from/to SharePoint is simple
SharePoint is ECM (Enterprise Content Management) system and it's common to expect files being uploaded, downloaded, migrated, processes, and managed in a variety ways.
Gosip provides an easy way of dealing with SharePoint document listaries, files and folders.
Getting library object
Document library in SharePoint is almost the same as a List, but with intention of being a container for files.
// The recommended way of getting lists is by using their relative URIs// can be a short form without full web relative URL prefixlist := sp.Web().GetList("MyLibrary")// other common but less recommended way of getting a list is// list := sp.Web().Lists().GetByTitle("My Library")
// folderResp is a byte array read from response body with extra methodsfolderResp, err := foler.Folders().Add("New Folder Name")if err !=nil { log.Fatal(err)}fmt.Printf("New folder URL: %s\n", folderResp.Data().ServerRelativeURL)
// fileAddResp is a byte array read from response body with extra methodsfileAddResp, err := foler.Files().Add("My File.txt", []byte("File content"), true)if err !=nil { log.Fatal(err)}fmt.Printf("New file URL: %s\n", fileAddResp.Data().ServerRelativeURL)
Obviously, file content can be a result of reading a file from disk, e.g.: