Пример #1
0
        public SharePointDocumentLocation GetOrCreateDocumentLibraryLocation(SharePointSite site, string documentLibraryName)
        {
            using (var context = new OrganizationServiceContext(_crmService))
            {
                // Get location
                SharePointDocumentLocation docLocation = (from d in context.CreateQuery <SharePointDocumentLocation>()
                                                          where d.ParentSiteOrLocation.Id == site.Id &&
                                                          d.Name == documentLibraryName
                                                          select new SharePointDocumentLocation
                {
                    Id = d.Id,
                    Name = d.Name,
                    ParentSiteOrLocation = d.ParentSiteOrLocation,
                    RegardingObjectId = d.RegardingObjectId,
                    RelativeUrl = d.RelativeUrl
                }).FirstOrDefault();
                if (docLocation == null)
                {
                    // Create if not already
                    docLocation = new SharePointDocumentLocation
                    {
                        Name = documentLibraryName,
                        ParentSiteOrLocation = site.ToEntityReference(),
                        RelativeUrl          = documentLibraryName
                    };
                    docLocation.Id = _crmService.Create(docLocation);
                }



                return(docLocation);
            }
        }