Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            Web web = ctx.Site.OpenWeb(Web.Read());

            if (Identity != null)
            {
                SPOList list = Identity.Read(web, Detail);
                WriteObject(list);
                return;
            }
            var lists = web.Lists;

            ctx.Load(web);
            ctx.Load(lists);
            ctx.ExecuteQuery();


            foreach (var list in lists)
            {
                if (Identity == null)
                {
                    SPOList.LoadList(ctx, list, Detail);
                    WriteObject(new SPOList(list));
                    continue;
                }
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            Dictionary <string, object> fieldValues = null;

            if (FieldValues != null)
            {
                fieldValues = FieldValues.Read();
            }

            byte[]             content  = System.IO.File.ReadAllBytes(File);
            System.IO.FileInfo file     = new System.IO.FileInfo(File);
            string             leafName = file.Name;

            if (ParameterSetName == "List")
            {
                var     web  = ctx.Site.OpenWeb(Web.Read());
                SPOList list = List.Read(web, true);
                WriteObject(list.AddFile(content, Overwrite, leafName, fieldValues));
            }
            else
            {
                WriteObject(Folder.AddFile(content, Overwrite, leafName, fieldValues));
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;
            Web web = ctx.Site.OpenWeb(Web.Read());

            var listci = new ListCreationInformation
            {
                CustomSchemaXml      = CustomSchemaXml,
                Description          = Description,
                Title                = Title,
                Url                  = Url,
                DocumentTemplateType = DocumentTemplateType,
                DataSourceProperties = DataSourceProperties,
                QuickLaunchOption    = QuickLaunchOption,
                TemplateType         = TemplateType,
                TemplateFeatureId    = TemplateFeatureId
            };

            List newList = web.Lists.Add(listci);

            ctx.ExecuteQuery();
            SPOList.LoadList(ctx, newList, true);
            WriteObject(new SPOList(newList));
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            if (!base.ShouldProcess(Identity.ToString(), "Remove List"))
            {
                return;
            }

            Web     web  = ctx.Site.OpenWeb(Web.Read());
            SPOList list = Identity.Read(web, false);

            if (list != null)
            {
                if (Recycle)
                {
                    list.List.Recycle();
                }
                else
                {
                    list.List.DeleteObject();
                }

                list.List.Context.ExecuteQuery();
            }
            else
            {
                throw new ArgumentException("Unable to locate the specified list.");
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;
            Web web = ctx.Site.OpenWeb(Web.Read());



            SPOContentType newContentType    = null;
            SPOList        list              = List.Read(web, false);
            SPOContentType parentContentType = ContentType.Read(web);

            if (parentContentType == null)
            {
                throw new ArgumentException("Unable to locate the specified parent content type.");
            }
            SPOContentType existingContentType = SPOContentType.GetContentType(ctx, list.List.ContentTypes, parentContentType.Name);

            if (existingContentType != null)
            {
                WriteWarning("The content type \"" + parentContentType.Name + "\" already exists within the List.");
                WriteObject(existingContentType);
                return;
            }

            ContentType ct = list.List.ContentTypes.AddExistingContentType(parentContentType.ContentType);

            ctx.ExecuteQuery();
            SPOContentType.LoadContentType(ctx, ct);
            newContentType = new SPOContentType(ct);

            WriteObject(newContentType);
        }
Ejemplo n.º 6
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;
            Web web = ctx.Site.OpenWeb(Web.Read());

            SPOField fieldToAdd = Identity.Read(web);

            if (fieldToAdd == null)
            {
                WriteError(new ErrorRecord(new ArgumentOutOfRangeException("The specified field could not be found! The field was not added to the list."), null, ErrorCategory.InvalidData, Identity));
                return;
            }
            SPOList  list          = List.Read(web, false);
            SPOField existingField = SPOField.GetField(ctx, list.List.Fields, fieldToAdd.InternalName);

            if (existingField != null)
            {
                WriteWarning("The specified field already exists within the list.");
                WriteObject(existingField);
                return;
            }
            Field field = list.List.Fields.Add(fieldToAdd.Field);

            ctx.Load(field);
            ctx.ExecuteQuery();
            WriteObject(new SPOField(field));
        }
Ejemplo n.º 7
0
        public List <SPOList> GetLists(bool detailed)
        {
            if (_detailedLists != null)
            {
                return(_detailedLists);
            }
            if (_lists != null && !detailed)
            {
                return(_lists);
            }

            var lists = _web.Lists;
            var ctx   = SPOSiteContext.CurrentSiteContext.Context;

            ctx.Load(lists);
            ctx.ExecuteQuery();

            var spoLists = new List <SPOList>();

            foreach (var list in lists)
            {
                SPOList.LoadList(ctx, list, detailed);
                spoLists.Add(new SPOList(list));
            }
            _lists = spoLists;
            if (detailed)
            {
                _detailedLists = spoLists;
            }

            return(spoLists);
        }
Ejemplo n.º 8
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;
            Web web = ctx.Site.OpenWeb(Web.Read());

            SPOContentType contentType = null;

            if (List == null)
            {
                contentType = ContentType.Read(web);
            }
            else
            {
                SPOList list = List.Read(web, false);
                contentType = ContentType.Read(list.List);
            }

            if (contentType == null)
            {
                throw new ArgumentException("Unable to locate the specified content type.");
            }

            if (base.ShouldProcess(contentType.Name, "Remove Content Type"))
            {
                contentType.Delete();
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            string surl = Web.Read();
            Web    web  = ctx.Site.OpenWeb(surl);

            ContentTypeCollection contentTypes = null;

            if (ParameterSetName == "Web")
            {
                contentTypes = web.ContentTypes;
            }
            else if (ParameterSetName == "List")
            {
                SPOList list = List.Read(web, false);
                contentTypes = list.List.ContentTypes;
            }
            ctx.Load(contentTypes);
            ctx.ExecuteQuery();

            foreach (ContentType ct in contentTypes)
            {
                if (string.IsNullOrEmpty(Identity) || ct.Name.ToLower() == Identity.ToLower() || ct.Id.StringValue.ToLower() == Identity.ToLower())
                {
                    SPOContentType.LoadContentType(ctx, ct);
                    WriteObject(new SPOContentType(ct));
                }
            }
        }
Ejemplo n.º 10
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            SPOWikiPage page = null;

            try
            {
                if (ParameterSetName == "List")
                {
                    var     web  = ctx.Site.OpenWeb(Web.Read());
                    SPOList list = List.Read(web, true);
                    page = SPOWikiPage.AddWikiPage(list, WikiPageName, true);
                }
                else
                {
                    page = SPOWikiPage.AddWikiPage(Folder, WikiPageName, true);
                }
            }
            catch (FileExistsException)
            {
                throw new Exception("The specified wiki page already exists and will not be overwritten.");
            }
            if (page != null)
            {
                page.AddLayoutToWikiPage(WikiPageLayout);
            }

            WriteObject(page);
        }
 public SPOListPipeBind(SPOList spoList)
 {
     if ((spoList == null) || spoList.Id == Guid.Empty)
     {
         throw new ArgumentNullException("The List ID must be specified.");
     }
     _listId = spoList.Id;
     _list   = spoList.List;
 }
Ejemplo n.º 12
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            var     web  = ctx.Site.OpenWeb(Web.Read());
            SPOList list = List.Read(web, true);

            WriteObject(list.GetFolder(ListRelativeUrlFolderPath, true, true));
        }
Ejemplo n.º 13
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            XmlDocument viewSchema = null;

            if (ViewSchema != null)
            {
                viewSchema = ViewSchema.Read();
            }
            if (string.IsNullOrEmpty(ViewTitle) && viewSchema == null)
            {
                throw new ArgumentException("You must specify a value for at least one of the ViewTitle or ViewSchema parameters.");
            }
            var     web    = ctx.Site.OpenWeb(Web.Read());
            SPOFile file   = File.Read(web);
            SPOList list   = List.Read(web, true);
            Guid    viewId = Guid.Empty;

            if (!string.IsNullOrEmpty(ViewTitle))
            {
                var view = list.GetViews().Where(v => v.Title.ToLowerInvariant() == ViewTitle.ToLowerInvariant()).FirstOrDefault();
                if (view == null)
                {
                    throw new ArgumentException("The value specified for the ViewTitle parameter does not match an existing view.");
                }
            }

            string xml = GetXsltListViewWebPartXml(list.Id, list.Url, viewId, viewSchema, file.ServerRelativeUrl, Title, JSLink, ChromeType);

            if (list.BaseTemplate == 106)
            {
                if (viewSchema == null)
                {
                    var view = list.GetViews().Where(v => v.Title.ToLowerInvariant() == ViewTitle.ToLowerInvariant()).FirstOrDefault();
                    viewSchema = new XmlDocument();
                    viewSchema.LoadXml(view.ListViewXml);
                }
                xml = GetListViewWebPartXml(list.Id, list.Url, viewSchema, file.ServerRelativeUrl, Title, ChromeType);
            }
            if (ParameterSetName == "WikiPage")
            {
                SPOWikiPage wikiPage = file as SPOWikiPage;
                if (wikiPage == null)
                {
                    throw new Exception("The specified file is either not found or is not a wiki page.");
                }
                WriteObject(wikiPage.AddWebPartToWikiPage(xml, Title, Row, Column, AddSpace));
            }
            else
            {
                WriteObject(file.AddWebPartToWebPartPage(xml, Zone, ZoneIndex, Title));
            }
        }
Ejemplo n.º 14
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var     ctx  = base.Context;
            var     web  = ctx.Site.OpenWeb(Web.Read());
            SPOList list = List.Read(web, true);

            Dictionary <string, object> fieldValues = null;

            if (FieldValues != null)
            {
                fieldValues = FieldValues.Read();
            }

            WriteObject(list.AddItem(ListRelativeUrlFolderPath, fieldValues));
        }
        public SPOList Read(Web web, bool detailed)
        {
            var  ctx  = SPOSiteContext.CurrentSiteContext.Context;
            List list = null;

            if (this.ListId != Guid.Empty)
            {
                list = web.Lists.GetById(this.ListId);
            }
            else if (!string.IsNullOrEmpty(this.ListTitle))
            {
                list = web.Lists.GetByTitle(this.ListTitle);
            }
            else if (!string.IsNullOrEmpty(this.Url))
            {
                var lists = web.Lists;
                ctx.Load(lists, l => l.Include(a => a.Title, a => a.Id, a => a.RootFolder));
                ctx.ExecuteQuery();

                foreach (var list2 in lists)
                {
                    string pathAndQuery = HttpUtility.UrlPathEncode(this.Url, true);
                    if (!this.Url.StartsWith("/"))
                    {
                        pathAndQuery = new Uri(this.Url).PathAndQuery;
                    }

                    if (HttpUtility.UrlPathEncode(list2.RootFolder.ServerRelativeUrl, true).ToLower().TrimEnd('/') == pathAndQuery.ToLower().TrimEnd('/'))
                    {
                        list = list2;
                        break;
                    }
                }
            }
            if (list != null)
            {
                _list = list;
                SPOList.LoadList(ctx, list, detailed);

                return(new SPOList(list));
            }
            return(null);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;
            Web web = ctx.Site.OpenWeb(Web.Read());

            XmlDocument schemaXmlDoc = SchemaXml.Read();
            string      xml          = schemaXmlDoc.OuterXml;

            if (ParameterSetName == "Web")
            {
                SPOField existingField = SPOField.GetField(ctx, web.AvailableFields, schemaXmlDoc);
                if (existingField != null)
                {
                    WriteWarning("The field " + schemaXmlDoc.DocumentElement.GetAttribute("Name") + " already exists!");
                    WriteObject(existingField);
                    return;
                }
                Field field = web.Fields.AddFieldAsXml(xml, false, Options);
                ctx.Load(field);
                ctx.ExecuteQuery();
                WriteObject(new SPOField(field));
            }
            else if (ParameterSetName == "List")
            {
                SPOList  list          = List.Read(web, false);
                SPOField existingField = SPOField.GetField(ctx, list.List.Fields, schemaXmlDoc);
                if (existingField != null)
                {
                    WriteWarning("The field " + schemaXmlDoc.DocumentElement.GetAttribute("Name") + " already exists!");
                    WriteObject(existingField);
                    return;
                }
                Field field = list.List.Fields.AddFieldAsXml(xml, AddToDefaultView, Options);
                ctx.Load(field);
                ctx.ExecuteQuery();
                WriteObject(new SPOField(field));
            }
        }
Ejemplo n.º 17
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            SPOFile page = null;

            if (ParameterSetName == "List")
            {
                var     web  = ctx.Site.OpenWeb(Web.Read());
                SPOList list = List.Read(web, true);
                page = list.GetRootFolder(true).GetFile(WikiPageName);
            }
            else
            {
                page = Folder.GetFile(WikiPageName);
            }
            if (page != null)
            {
                SPOWikiPage wikiPage = new SPOWikiPage(page.File);
                wikiPage.SetWikiPageLayout(WikiPageLayout);
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var     ctx  = base.Context;
            var     web  = ctx.Site.OpenWeb(Web.Read());
            SPOList list = Identity.Read(web, true);

            if (base.ParameterSetName == "BreakRoleInheritance")
            {
                if (list.HasUniqueRoleAssignments)
                {
                    throw new ArgumentException("The specified List already has unique role assignments.");
                }

                if (base.Fields.Contains("BreakRoleInheritance") && BreakRoleInheritance)
                {
                    list.List.BreakRoleInheritance(CopyRoleAssignments, ClearScopes);
                    list.List.Context.ExecuteQuery();

                    Identity.Refresh();
                    list.Refresh();
                    WriteObject(list);
                    return;
                }
            }
            else if (base.ParameterSetName == "ResetRoleInheritance")
            {
                if (!list.HasUniqueRoleAssignments)
                {
                    throw new ArgumentException("The specified List does not have unique role assignments.");
                }

                if (base.Fields.Contains("ResetRoleInheritance") && ResetRoleInheritance)
                {
                    list.List.ResetRoleInheritance();
                    list.List.Context.ExecuteQuery();

                    Identity.Refresh();
                    list.Refresh();
                    WriteObject(list);
                    return;
                }
            }
            else
            {
                if (base.Fields.Contains("ContentTypesEnabled"))
                {
                    list.ContentTypesEnabled = ContentTypesEnabled;
                }

                if (base.Fields.Contains("DefaultContentApprovalWorkflowId"))
                {
                    list.DefaultContentApprovalWorkflowId = DefaultContentApprovalWorkflowId;
                }

                if (base.Fields.Contains("DefaultDisplayFormUrl"))
                {
                    list.DefaultDisplayFormUrl = DefaultDisplayFormUrl;
                }

                if (base.Fields.Contains("DefaultEditFormUrl"))
                {
                    list.DefaultEditFormUrl = DefaultEditFormUrl;
                }

                if (base.Fields.Contains("DefaultNewFormUrl"))
                {
                    list.DefaultNewFormUrl = DefaultNewFormUrl;
                }

                if (base.Fields.Contains("Description"))
                {
                    list.Description = Description;
                }

                if (base.Fields.Contains("Direction"))
                {
                    list.Direction = Direction;
                }

                if (base.Fields.Contains("DocumentTemplateUrl"))
                {
                    list.DocumentTemplateUrl = DocumentTemplateUrl;
                }

                if (base.Fields.Contains("DraftVersionVisibility"))
                {
                    list.DraftVersionVisibility = DraftVersionVisibility;
                }

                if (base.Fields.Contains("EnableAttachments"))
                {
                    list.EnableAttachments = EnableAttachments;
                }

                if (base.Fields.Contains("EnableFolderCreation"))
                {
                    list.EnableFolderCreation = EnableFolderCreation;
                }

                if (base.Fields.Contains("EnableMinorVersions"))
                {
                    list.EnableMinorVersions = EnableMinorVersions;
                }

                if (base.Fields.Contains("EnableModeration"))
                {
                    list.EnableModeration = EnableModeration;
                }

                if (base.Fields.Contains("EnableVersioning"))
                {
                    list.EnableVersioning = EnableVersioning;
                }

                if (base.Fields.Contains("ForceCheckout"))
                {
                    list.ForceCheckout = ForceCheckout;
                }

                if (base.Fields.Contains("Hidden"))
                {
                    list.Hidden = Hidden;
                }

                if (base.Fields.Contains("ImageUrl"))
                {
                    list.ImageUrl = ImageUrl;
                }

                if (base.Fields.Contains("IrmEnabled"))
                {
                    list.IrmEnabled = IrmEnabled;
                }

                if (base.Fields.Contains("IrmExpire"))
                {
                    list.IrmExpire = IrmExpire;
                }

                if (base.Fields.Contains("IrmReject"))
                {
                    list.IrmReject = IrmReject;
                }

                if (base.Fields.Contains("IsApplicationList"))
                {
                    list.IsApplicationList = IsApplicationList;
                }

                if (base.Fields.Contains("LastItemModifiedDate"))
                {
                    list.LastItemModifiedDate = LastItemModifiedDate;
                }

                if (base.Fields.Contains("MultipleDataList"))
                {
                    list.MultipleDataList = MultipleDataList;
                }

                if (base.Fields.Contains("NoCrawl"))
                {
                    list.NoCrawl = NoCrawl;
                }

                if (base.Fields.Contains("OnQuickLaunch"))
                {
                    list.OnQuickLaunch = OnQuickLaunch;
                }

                if (base.Fields.Contains("Title"))
                {
                    list.Title = Title;
                }

                if (base.Fields.Contains("ValidationFormula"))
                {
                    list.ValidationFormula = ValidationFormula;
                }

                if (base.Fields.Contains("ValidationMessage"))
                {
                    list.ValidationMessage = ValidationMessage;
                }

                list.Update();

                Identity.Refresh();
                list.Refresh();
                WriteObject(list);
            }
        }
 public void AddFieldLinks(SPOList list, params string[] fieldsToAdd)
 {
     AddFieldLinks(list.List.ParentWeb.AvailableFields, true, fieldsToAdd);
 }