コード例 #1
0
        /// <summary>
        /// Bind a lookup field to the target list
        /// </summary>
        public static void BindLookupField(ClientContext clientContext, string sourceListTitle, string lookupFieldName, string lookupDisplayFieldName, string lookupListTitle)
        {
            var sourceList = CSOMUtil.GetListByTitle(clientContext, sourceListTitle);
            var lookupList = CSOMUtil.GetListByTitle(clientContext, lookupListTitle);

            if (sourceList != null && lookupList != null)
            {
                var fieldColl = sourceList.Fields;
                var q         = clientContext.LoadQuery <Field>(fieldColl.Where(n => n.InternalName == lookupFieldName));
                clientContext.ExecuteQuery();

                if (q.Count() > 0)
                {
                    var field = q.FirstOrDefault <Field>() as FieldLookup;

                    field.LookupList = lookupList.Id.ToString();

                    field.LookupField = lookupDisplayFieldName;

                    field.Update();

                    clientContext.ExecuteQuery();
                }
            }
        }
コード例 #2
0
        public void RemoveIncidentWorkflowAndRelatedLists()
        {
            var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents");

            var service = new WorkflowProvisionService(clientContext);

            service.Unsubscribe(incidentsList.Id, "Incident");
            service.DeleteDefinitions("Incident");
            service.DeleteList("Incident Workflow Tasks");
            service.DeleteList("Incident Workflow History");
        }
コード例 #3
0
        /// <summary>
        /// Remove a list/document library in o365 web
        /// </summary>
        public static void RemoveSharePointList(ClientContext clientContext, string listTitle)
        {
            var list = CSOMUtil.GetListByTitle(clientContext, listTitle);

            // check if the content type exists
            if (list != null)
            {
                list.DeleteObject();
                clientContext.ExecuteQuery();
            }
        }
コード例 #4
0
        public void ProvisionIncidentWorkflowAndRelatedLists(string incidentWorkflowFile, string suiteLevelWebAppUrl, string dispatcherName)
        {
            var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents");

            var service    = new WorkflowProvisionService(clientContext);
            var incidentWF = System.IO.File.ReadAllText(incidentWorkflowFile)
                             .Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl)
                             .Replace("(dispatcherPlaceHolder)", dispatcherName);
            var incidentWFDefinitionId = service.SaveDefinitionAndPublish("Incident",
                                                                          WorkflowUtil.TranslateWorkflow(incidentWF));
            var taskListId    = service.CreateTaskList("Incident Workflow Tasks");
            var historyListId = service.CreateHistoryList("Incident Workflow History");

            service.Subscribe("Incident Workflow", incidentWFDefinitionId, incidentsList.Id,
                              WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId);
        }
コード例 #5
0
        /// <summary>
        /// Add a list/document library to o365 web
        /// </summary>
        public static void AddSharePointList(ClientContext clientContext, string contentTypeID, string listTitle, string url, int listTemplateType, bool isHideTitle = false)
        {
            Web web = clientContext.Web;

            var contentType = CSOMUtil.GetContentTypeById(clientContext, contentTypeID);
            var list        = CSOMUtil.GetListByTitle(clientContext, listTitle);

            // check if the content type exists
            if (list == null && contentType != null)
            {
                ListCreationInformation creationInfo = new ListCreationInformation();
                creationInfo.Title        = listTitle;
                creationInfo.Url          = url;
                creationInfo.TemplateType = listTemplateType;
                list = web.Lists.Add(creationInfo);
                list.Update();
                clientContext.ExecuteQuery();

                // insert content type
                var cts = list.ContentTypes;
                list.ContentTypesEnabled = true;
                cts.AddExistingContentType(contentType);
                clientContext.Load(cts);
                clientContext.ExecuteQuery();


                // remove default content type
                var count = cts.Count;
                while (--count >= 0)
                {
                    if (cts[0].Name != "Folder" && cts[0].Name != contentType.Name)
                    {
                        cts[0].DeleteObject();
                    }
                }
                clientContext.ExecuteQuery();


                // add fields to default view
                View defaultView = list.DefaultView;
                clientContext.Load(defaultView, v => v.ViewFields);
                clientContext.Load(contentType, c => c.Fields);
                clientContext.ExecuteQuery();
                if (!defaultView.ViewFields.Contains("ID"))
                {
                    defaultView.ViewFields.Add("ID");
                    defaultView.ViewFields.MoveFieldTo("ID", 0);
                }
                //hide title field in view
                if (isHideTitle == true)
                {
                    defaultView.ViewFields.Remove("LinkTitle");
                }
                foreach (Field field in contentType.Fields)
                {
                    if (!defaultView.ViewFields.Contains(field.Title) && field.Title != "Content Type" && field.Title != "Title")
                    {
                        defaultView.ViewFields.Add(field.Title);
                    }
                }
                defaultView.Update();
                clientContext.ExecuteQuery();

                //hide title field in forms
                if (isHideTitle == true)
                {
                    var field_title = list.Fields.GetByTitle("Title");
                    clientContext.Load(field_title);
                    clientContext.ExecuteQuery();
                    field_title.Hidden = true;
                    field_title.Update();
                    clientContext.ExecuteQuery();
                }
            }
        }