Beispiel #1
0
        public static void DeletePhoto(string url, ClientContext siteContext)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            if (siteContext == null)
            {
                throw new InvalidOperationException("Could not retrieve the Sharepoint context");
            }

            Web            appWeb             = siteContext.Web;
            ListCollection webLists           = appWeb.Lists;
            List           appPicList         = webLists.GetByTitle("Photos");
            Folder         appPicListFolder   = appPicList.RootFolder;
            FileCollection appPicListPictures = appPicListFolder.Files;
            File           picture            = appPicListPictures.GetByUrl(url);

            siteContext.Load(picture);
            siteContext.ExecuteQuery();

            if (picture != null && picture.Exists)
            {
                picture.DeleteObject();
                siteContext.ExecuteQuery();
            }
        }