コード例 #1
0
        //TODO: create data access layer, move it
        private void CreateForm(Form templateForm, ListInfo info, bool addImmediately = true)
        {
            var list = info.SiteList;
            var isDocLibrary = list.IsDocumentLibrary();
            var serverRelativeUrl = list.RootFolder.ServerRelativeUrl;
            var fileName = string.Format("{0}/{1}{2}", serverRelativeUrl, isDocLibrary ? "Forms/" : "", GetPageName(templateForm.ServerRelativeUrl));
            var root = list.RootFolder;

            root.Files.AddTemplateFile(fileName, TemplateFileType.FormPage);
            if (templateForm.IsDefault)
            {
                switch (templateForm.FormType)
                {
                    case PageType.DisplayForm:
                        list.DefaultDisplayFormUrl = fileName;
                        break;
                    case PageType.EditForm:
                        list.DefaultEditFormUrl = fileName;
                        break;
                    case PageType.NewForm:
                        list.DefaultNewFormUrl = fileName;
                        break;
                }
            }
            if (addImmediately)
            {
                list.Context.ExecuteQueryRetry();
            }
        }
コード例 #2
0
        private static ListInstance ExtractForms(Web web, List siteList, ListInstance list)
        {
            web.Context.Load(siteList, l => l.Forms);
            web.Context.ExecuteQueryRetry();

            var defaultForms = new[] { siteList.DefaultDisplayFormUrl, siteList.DefaultEditFormUrl, siteList.DefaultNewFormUrl };

            foreach (var form in siteList.Forms)
            {
                var model = new Form
                {
                    FormType = form.FormType,
                    ServerRelativeUrl = form.ServerRelativeUrl,
                    IsDefault = defaultForms.Contains(form.ServerRelativeUrl)
                };
                list.Forms.Add(model);
            }
            return list;
        }