예제 #1
0
 public override void LoadListItems(SharePointClientContext spContext, ListItemCollection items)
 {
     spContext.Load(items, t => t.Include(doc => doc.File),
                    t => t.Include(doc => doc.ParentList.RootFolder.ServerRelativeUrl),
                    t => t.Include(doc => doc.ParentList.ParentWebUrl),
                    t => t);
 }
        public virtual void GetListSettings(SharePointClientContext spContext, List list, string title, string destinationPath)
        {
            // extend this when needed to be more generic...

            if (title != "OAMPS Branding")
            {
                return;
            }

            var values = new Dictionary <string, object>();

            var choices = spContext.CastTo <FieldChoice>(list.Fields.GetByTitle("Speciality"));

            spContext.Load(choices, f => f.Choices, f => f.DefaultValue);
            spContext.ExecuteQuery();
            var specialities = choices.Choices;

            values.Add("Speciality.DefaultValue", choices.DefaultValue);
            values.Add("Speciality.Choices", specialities);
            var json = JsonConvert.SerializeObject(values);

            System.IO.File.WriteAllText(Path.Combine(destinationPath, "list-settings.txt"), json);
        }
예제 #3
0
        public override void HandleListItem(SharePointClientContext spContext, ILog logger, Arguments args, string destinationPath, ListItem item, ref int updatedCount, ref int noUpdateRequiredCount)
        {
            var fileName = Path.Combine(destinationPath, item.File.Name);

            if (args.Overwrite || item.File.TimeLastModified > System.IO.File.GetLastWriteTime(fileName))
            {
                logger.Info($"Updating: {fileName}");
                using (var fileStream = System.IO.File.Create(fileName))
                {
                    var spFileStream = item.File.OpenBinaryStream();
                    spContext.ExecuteQuery();

                    spFileStream.Value.CopyTo(fileStream);
                    updatedCount++;
                }

                if (fileName.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                {
                    var thumbName = FileHelpers.GetThumbnailPath(fileName);
                    using (var thumbStream = System.IO.File.Create(thumbName))
                    {
                        var fileUrl  = item.File.ServerRelativeUrl;
                        var thumbUrl = FileHelpers.ReplaceLastOccurrence(FileHelpers.GetThumbnailPath(fileUrl), "/", "/_t/");
                        var thumb    = spContext.Web.GetFileByServerRelativeUrl(thumbUrl);
                        spContext.Load(thumb);
                        var spThumbStream = thumb.OpenBinaryStream();
                        spContext.ExecuteQuery();
                        spThumbStream.Value.CopyTo(thumbStream);
                    }
                }
            }
            else
            {
                noUpdateRequiredCount++;
                logger.Info($"Skipping: {fileName}");
            }
        }