예제 #1
0
        internal static void UpdateFilesInModule(SPElementDefinition elementDefinition, SPWeb web)
        {
            XElement   xml        = elementDefinition.XmlDefinition.ToXElement();
            XNamespace xmlns      = "http://schemas.microsoft.com/sharepoint/";
            string     featureDir = elementDefinition.FeatureDefinition.RootDirectory;
            Module     module     = (from m in xml.DescendantsAndSelf()
                                     select new Module
            {
                Name = (m.Attribute("Name") != null) ? m.Attribute("Name").Value : null,
                ProvisioningUrl = (m.Attribute("Url") != null) ? m.Attribute("Url").Value : null,
                PhysicalPath = featureDir,
                Files = (from f in m.Elements(xmlns.GetName("File"))
                         select new Module.File
                {
                    FilePath = (m.Attribute("Path") == null) ? string.Empty : Path.Combine(featureDir, m.Attribute("Path").Value),
                    Name = (f.Attribute("Url") != null) ? f.Attribute("Url").Value : null,
                    Properties = (from p in f.Elements(xmlns.GetName("Property"))
                                  select p).ToDictionary(
                        n => n.Attribute("Name").Value,
                        v => v.Attribute("Value").Value)
                }).ToArray()
            }).First();

            if (module == null)
            {
                return;
            }

            if (module.Name == "Layout Pages")
            {
                foreach (Module.File file in module.Files)
                {
                    string filename     = file.Name.Contains("/") ? file.Name.Substring(file.Name.LastIndexOf("/") + 1) : file.Name;
                    string physicalPath = string.IsNullOrEmpty(file.FilePath) ? Path.Combine(module.PhysicalPath, filename) : Path.Combine(file.FilePath, filename);
                    string virtualPath  = string.Concat(web.Url, "/", module.ProvisioningUrl, "/", file.Name);

                    if (File.Exists(physicalPath))
                    {
                        using (StreamReader sreader = new StreamReader(physicalPath))
                        {
                            if (!CheckOutStatus(web.GetFile(virtualPath)))
                            {
                                web.GetFile(virtualPath).CheckOut();
                            }
                            SPFile spFile = web.Files.Add(virtualPath, sreader.BaseStream, new Hashtable(file.Properties), true);
                            spFile.CheckIn("Updated", SPCheckinType.MajorCheckIn);
                            if (CheckContentApproval(spFile.Item))
                            {
                                spFile.Approve("Updated");
                            }

                            spFile.Update();
                        }
                    }
                }
            }
        }
        public static string GetElementDefinition(ISharePointCommandContext context,
                                                  FeatureElementInfo elementInfo)
        {
            SPFeatureDefinition definition = SPFarm.Local.FeatureDefinitions[elementInfo.FeatureID];
            SPElementDefinition element    = definition.GetElementDefinitions(CultureInfo.CurrentCulture)
                                             .OfType <SPElementDefinition>()
                                             .Where(searchElement => searchElement.ElementType == elementInfo.ElementType)
                                             .Where(searchElement => GetNameFromNode(searchElement.XmlDefinition) == elementInfo.Name)
                                             .FirstOrDefault();

            return(element.XmlDefinition.OuterXml);
        }
        internal static void UpdateFilesInModule(SPElementDefinition elementDefinition, SPWeb web)
        {
            XElement xml = elementDefinition.XmlDefinition.ToXElement();
            XNamespace xmlns = "http://schemas.microsoft.com/sharepoint/";
            string featureDir = elementDefinition.FeatureDefinition.RootDirectory;
            Module module = (from m in xml.DescendantsAndSelf()
                             select new Module
                             {
                                 Name = (m.Attribute("Name") != null) ? m.Attribute("Name").Value : null,
                                 ProvisioningUrl = (m.Attribute("Url") != null) ? m.Attribute("Url").Value : null,
                                 PhysicalPath = featureDir,
                                 Files = (from f in m.Elements(xmlns.GetName("File"))
                                          select new Module.File
                                          {

                                              FilePath = (m.Attribute("Path") == null) ? string.Empty : Path.Combine(featureDir, m.Attribute("Path").Value),
                                              Name = (f.Attribute("Url") != null) ? f.Attribute("Url").Value : null,
                                              Properties = (from p in f.Elements(xmlns.GetName("Property"))
                                                            select p).ToDictionary(
                                                              n => n.Attribute("Name").Value,
                                                              v => v.Attribute("Value").Value)
                                          }).ToArray()
                             }).First();

            if (module == null)
            {
                return;
            }

            if (module.Name == "Layout Pages")
            {
                foreach (Module.File file in module.Files)
                {

                    string filename = file.Name.Contains("/") ? file.Name.Substring(file.Name.LastIndexOf("/") + 1) : file.Name;
                    string physicalPath = string.IsNullOrEmpty(file.FilePath) ? Path.Combine(module.PhysicalPath, filename) : Path.Combine(file.FilePath, filename);
                    string virtualPath = string.Concat(web.Url, "/", module.ProvisioningUrl, "/", file.Name);

                    if (File.Exists(physicalPath))
                    {
                        using (StreamReader sreader = new StreamReader(physicalPath))
                        {
                            if (!CheckOutStatus(web.GetFile(virtualPath)))
                            {
                                web.GetFile(virtualPath).CheckOut();
                            }
                            SPFile spFile = web.Files.Add(virtualPath, sreader.BaseStream, new Hashtable(file.Properties), true);
                            spFile.CheckIn("Updated", SPCheckinType.MajorCheckIn);
                            if (CheckContentApproval(spFile.Item))
                            {
                                spFile.Approve("Updated");
                            }

                            spFile.Update();
                        }
                    }
                }
            }
        }