Esempio n. 1
0
        private bool UploadTemplateToSharePoint(SharePointListStructure list)
        {
            var featureID = Guid.NewGuid();

            // Get the List template Gallery Folder
            var listTemplateGallery = web.Lists.GetByTitle("List Template Gallery");
            var listFolder          = listTemplateGallery.RootFolder;
            FileCreationInformation fileCreationInformation = new FileCreationInformation
            {
                Content   = System.IO.File.ReadAllBytes(list.ListPhysicalPath),
                Overwrite = true,
                Url       = "_catalogs/lt/" + list.ListName + ".stp",
            };

            var file = listFolder.Files.Add(fileCreationInformation);

            file.Update();
            clientContext.Load(file);

            try
            {
                clientContext.ExecuteQuery();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private bool CreateListFromTemplate(SharePointListStructure list)
        {
            // Create list
            //ListCreationInformation listCreationInfo = new ListCreationInformation
            //{
            //    Title = list.ListName,
            //    TemplateType = (int)ListTemplateType.GenericList
            //};
            //List oList = web.Lists.Add(listCreationInfo);
            //clientContext.ExecuteQuery();

            //// add fields to list

            //var pList = clientContext.Web.Lists.GetByTitle(list.ListName);

            //pList

            //var pField = oList.Fields.AddFieldAsXml("<Field DisplayName='MyField' Type='Number' />",

            //    true, AddFieldOptions.DefaultValue);

            //var fieldNumber = clientContext.CastTo<FieldNumber>(pField);
            //fieldNumber.MaximumValue = 100;
            //fieldNumber.MinimumValue = 35;

            //fieldNumber.Update();

            //clientContext.ExecuteQuery();

            return(true);
        }
Esempio n. 3
0
        public ViewFieldsView(SharePointListStructure sharePointListStructure)
        {
            InitializeComponent();

            // initialise rest of window
            data = sharePointListStructure ?? throw new ArgumentNullException(nameof(SharePointListStructure));
            SetUpData();
            tbListName.Text = string.Format("DISPLAYING: {0}", data.ListName);
        }
Esempio n. 4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var items = dtSharePointLists.SelectedItems;

            Task.Run(() =>
            {
                foreach (Microsoft.SharePoint.Client.List item in items)
                {
                    var sharePointListStructure = new SharePointListStructure
                    {
                        ListName = item.Title
                    };

                    // get our list data populated.
                    var listData = sharePointDataService.LoadListItems(item) as Microsoft.SharePoint.Client.List;

                    //initialise object lists
                    sharePointListStructure.ColumnDefinitions = new List <Models.ColumnDefinition>();
                    sharePointListStructure.ViewDefinitions   = new List <SharePointListView>();

                    foreach (var field in listData.Fields)
                    {
                        sharePointListStructure.ColumnDefinitions.Add(new Models.ColumnDefinition
                        {
                            ColumnType  = field.TypeDisplayName,
                            DisplayName = field.Title,
                            Name        = field.InternalName,
                            Required    = field.Required ? "True" : "False",
                            StaticName  = field.StaticName
                        });
                    }

                    foreach (var view in listData.Views)
                    {
                        sharePointListStructure.ViewDefinitions = new List <SharePointListView>()
                        {
                            new SharePointListView()
                            {
                                ViewDisplayName = view.Title,
                                ViewFieldRefs   = view.ViewFields.ToList(),
                            }
                        };
                    }

                    RetrievedData.Add(sharePointListStructure);
                }

                Dispatcher.Invoke(() => { RootWindow.RemoveFromMainContentView(this); });
            });
        }
        public SharePointListStructure ParseSPTFile(string filepath)
        {
            var fullXMLString = File.ReadAllText(filepath);

            string xmlString = string.Empty;

            // remove <Data></Data> node
            var    readString  = fullXMLString;
            string dataPattern = "<Data>[\\s\\S]*?<\\/Data>";
            Regex  dataRegex   = new Regex(
                dataPattern,
                RegexOptions.IgnoreCase |
                RegexOptions.CultureInvariant |
                RegexOptions.IgnorePatternWhitespace |
                RegexOptions.Compiled);

            Match match = dataRegex.Match(readString);

            if (match.Success)
            {
                xmlString = Regex.Replace(readString, dataPattern, string.Empty);
            }

            // see if we can deserialise it as is into our template
            var         template      = new ListTemplate();
            XmlDocument doc           = new XmlDocument();
            bool        attemptManual = false;

            try
            {
                doc.LoadXml(xmlString);
                using (TextReader reader = new StringReader(doc.OuterXml))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ListTemplate));
                    template = (ListTemplate)serializer.Deserialize(reader);
                    reader.Close();
                }
            }
            catch
            {
                attemptManual = true;
            }

            // we failed to parse the XML into an object, so let's try to manually extract the data we need
            if (attemptManual)
            {
                template = ManualXMLParse(fullXMLString, doc, template);
            }

            if (template == null)
            {
                // if we are null here we need to abort this parsing.
                string value  = null;
                var    groups = Regex.Match(fullXMLString, "(?<=TemplateTitle>).*(?=</TemplateTitle>)").Groups;
                if (groups != null && groups?.Count > 0)
                {
                    value = groups[0].Value;
                }

                return(new SharePointListStructure
                {
                    ListName = value ?? "No List Name could be retrieved from XML",
                    ColumnDefinitions = null,
                    ListPhysicalPath = filepath,
                    LocalList = true,
                    FullXMLSchema = fullXMLString,
                });
            }

            try
            {
                var sharePointListStructure = new SharePointListStructure
                {
                    ListName          = template.Details.TemplateTitle,
                    ColumnDefinitions = new List <ColumnDefinition>(),
                    ViewDefinitions   = new List <SharePointListView>(),
                    LocalList         = true,
                    ListPhysicalPath  = filepath,
                    FullXMLSchema     = fullXMLString,
                };

                foreach (var field in template.UserLists.List.MetaData.Fields)
                {
                    var columnDefinition = new ColumnDefinition
                    {
                        ColumnType  = field.Type,
                        DisplayName = field.DisplayName,
                        Name        = field.Name,
                        Required    = field.Required,
                        StaticName  = field.StaticName
                    };
                    sharePointListStructure.ColumnDefinitions.Add(columnDefinition);
                }

                if (template.UserLists.List.MetaData.Views != null)
                {
                    foreach (var view in template.UserLists.List.MetaData.Views)
                    {
                        var splv = new SharePointListView()
                        {
                            ViewDisplayName = view.DisplayName
                        };
                        splv.ViewFieldRefs = new List <string>();

                        if (view.Items[0] is ListTemplateUserListsListMetaDataViewViewFields viewFields)
                        {
                            foreach (var item in viewFields.FieldRef)
                            {
                                splv.ViewFieldRefs.Add(item.Name);
                            }
                        }
                        sharePointListStructure.ViewDefinitions.Add(splv);
                    }
                }

                return(sharePointListStructure);
            }
            catch (Exception)
            {
                string value  = null;
                var    groups = Regex.Match(fullXMLString, "(?<=TemplateTitle>).*(?=</TemplateTitle>)").Groups;
                if (groups != null && groups?.Count > 0)
                {
                    value = groups[0].Value;
                }

                return(new SharePointListStructure
                {
                    ListName = value ?? "No List Name could be retrieved from XML",
                    ColumnDefinitions = null,
                    FullXMLSchema = fullXMLString,
                });
            }
        }