LogoLogo
GoDocGitHub
  • Introduction
  • FAQ
  • Authentication strategies
    • Overview
    • Strategies
      • Azure Certificate Auth
      • Azure Creds Auth
      • Azure Env-based Auth
      • Azure Device Flow
      • SAML Auth
      • AddIn Only
        • Configuration
      • NTLM Auth
      • NTLM (alternative)
      • On-Demand Auth
      • ADFS Auth
      • FBA Auth
      • TMG Auth
      • Anonymous
    • Dynamic auth
    • Custom Auth
  • SharePoint client
    • HTTP Client
    • Fluent API
    • Hooks
    • Retries
    • Context
  • Samples
    • Library Initiation
    • Basic CRUD
    • Documents
    • Chunk upload
    • Permissions
    • Groups & Users
    • Search API
    • User Profiles
    • Change API
    • Attachments
    • Record Management
    • Sending Emails
    • Property Bags
    • Recycle Bin
    • Feature management
    • Advanced item requests
    • Advanced add/update
    • Unmarshaling responses
  • Sandbox
    • Overview
  • Utilities
    • Headers presets
    • Cpass
    • Compatibility matrix
  • Contributing
    • Overview
    • Testing
Powered by GitBook
On this page
  • Getting deleted items
  • Restoring recycled items

Was this helpful?

Edit on GitHub
Export as PDF
  1. Samples

Recycle Bin

Recycling methods and dealing with recycle bin

You can work with recycle bins via REST API similarly as with lists.

Getting deleted items

data, err := sp.Site().RecycleBin().
	OrderBy("DeletedDate", false).
	Top(5).
	Get() // site's Recycle Bin
// data, err := sp.Web().RecycleBin().Get() // web's one
if err != nil {
	log.Fatal(err)
}

for _, item := range data.Data() {
	d := item.Data()
	fmt.Println(
		d.ID,
		d.ItemType,
		d.LeafNamePath.DecodedURL,
		d.DeletedByName,
		d.DeletedDate,
	)
}

Items in recycle bins are queryable collection, OData modifiers can be applied in a usual way.

Response is strongly typed, helps do not care about unmarshalling the structures. Items in recycle bin contains the following metadata:

type RecycledItem struct {
	AuthorEmail               string
	AuthorName                string
	DeletedByEmail            string
	DeletedByName             string
	DeletedDate               time.Time
	DeletedDateLocalFormatted string
	DirName                   string
	ID                        string
	ItemState                 int
	ItemType                  int
	LeafName                  string
	Size                      int
	Title                     string
	LeafNamePath              *DecodedURL
	DirNamePath               *DecodedURL
}

Once you have Item ID (which is a GUID in case of recycle bin) you can not resore it.

Restoring recycled items

data, err := sp.Site().RecycleBin().Top(1).Get()
if err != nil {
	log.Fatal(err)
}

if len(data.Data()) > 0 {
	itemID := data.Data()[0].Data().ID
	if err := sp.Site().RecycleBin().GetByID(itemID).Restore(); err != nil {
		log.Fatal(err)
	}
}
PreviousProperty BagsNextFeature management

Last updated 5 years ago

Was this helpful?