当前位置: 首页>>代码示例>>C#>>正文


C# IItem.GetItem方法代码示例

本文整理汇总了C#中IItem.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# IItem.GetItem方法的具体用法?C# IItem.GetItem怎么用?C# IItem.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IItem的用法示例。


在下文中一共展示了IItem.GetItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyItemCallback

        public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem)
        {
            if (_PluginOptions[0].Value == "False")
                return;

            foreach (IItem sourceTemplate in sourceItem.Templates)
            {
                // Check if the correct template exists on the item
                if (sourceTemplate.Name.ToLower() != _PluginOptions[3].Value.ToLower())
                    continue;

                IField field = Util.GetFieldByName("__publish", destinationItem.Fields);
                if (field == null)
                {
                    field = Util.GetFieldByName("__valid to", destinationItem.Fields);
                    if (field == null)
                    {
                        field = Util.GetFieldByName("__created", destinationItem.Fields);
                    }
                }
                if (field == null)
                    throw new Exception("Error finding any valid date field in " + this.Name + " plugin.");

                DateTime date = Util.XsdDatetimeToDateTime(field.Content);
                string sDate = date.ToString(_PluginOptions[1].Value);

                string sYearPath = destinationParentItem.Path + "/" + sDate;
                IItem yearFolder = destinationParentItem.GetItem(sYearPath);
                if (yearFolder == null)
                {
                    string sFolderID = destinationParentItem.AddFromTemplate(sDate, "/sitecore/templates/common/folder");
                    yearFolder = destinationItem.GetItem(sFolderID);
                }
                bool bResult = false;
                if (_PluginOptions[2].Value == "")
                    bResult = destinationItem.MoveTo(yearFolder);
                else
                {
                    string sMonth = date.ToString(_PluginOptions[2].Value);
                    IItem monthFolder = destinationParentItem.GetItem(sYearPath + "/" + sMonth);
                    if (monthFolder == null)
                    {
                        string sFolderID = yearFolder.AddFromTemplate(sMonth, "/sitecore/templates/common/folder");
                        monthFolder = destinationItem.GetItem(sFolderID);
                        monthFolder.SortOrder = date.ToString("MM");
                        monthFolder.Save();
                    }
                    destinationItem.MoveTo(monthFolder);
                }
            }
        }
开发者ID:Cabana,项目名称:CMSConverter,代码行数:51,代码来源:MoveItemToDateFolderPlugin.cs

示例2: CopyItemCallback

        public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem)
        {
            if (_PluginOptions[0].Value == "False")
                return;

            // We are copying from masters to branches
            if ((sourceItem.Path.ToLower().IndexOf("/sitecore/masters") > -1) &&
                (destinationItem.Path.ToLower().IndexOf("/sitecore/templates/branches") > -1) &&
                (!sourceItem.Name.StartsWith("__")) && (sourceItem.Name != "masters"))
            {
                Sitecore6xItem destination6xItem = destinationItem as Sitecore6xItem;
                Sitecore6xItem destinationParent6xItem = destinationParentItem as Sitecore6xItem;

                IItem newDestinationItem = destinationParent6xItem.GetItem(destinationParent6xItem.Path + "/$name");
                if (newDestinationItem == null)
                {

                    destination6xItem.CopyTo(destinationParentItem, "$name");

                    newDestinationItem = destinationParent6xItem.GetItem(destinationParent6xItem.Path + "/$name");

                    string sPath = destinationParent6xItem.CreateTemplateItemWithSpecificID(
                                destinationParent6xItem.ID,
                                "/sitecore/templates/System/Branches/Branch",
                                sourceItem.ID,
                                sourceItem.Name);

                    Sitecore6xItem branchItem = destinationParentItem.GetItem(destinationParent6xItem.Path + "/" + sourceItem.Name) as Sitecore6xItem;

                    newDestinationItem.MoveTo(branchItem);

                    if (destination6xItem.Icon != "")
                        branchItem.Icon = destination6xItem.Icon;
                    else
                        branchItem.Icon = destination6xItem.Templates[0].Icon;

                    branchItem.Save();
                }
                // This is a child of a master, so it only needs to be moved
                else
                {
                    destinationItem.MoveTo(newDestinationItem);
                }
            }
        }
开发者ID:Cabana,项目名称:CMSConverter,代码行数:45,代码来源:MoveBranchItems.cs

示例3: CopyItemCallback

        public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem)
        {
            try
            {
                if (_PluginOptions[0].Value == "False")
                    return;
                // No template for this item, so it is probably a template itself
                if ((sourceItem.Templates == null) || (sourceItem.Templates[0] == null))
                    return;

                Uri hostUri = new Uri(sourceItem.GetHostUrl());
                string sHost = hostUri.Scheme + "://" + hostUri.Host;

                IItem tmpItem = sourceItem;
                while (tmpItem != null)
                {
                    if ((tmpItem.Templates[0].Name.ToLower() == "fff.departmentwebsite") ||
                        (tmpItem.Templates[0].Name.ToLower() == "fff.industrysectorclubwebsite"))
                    {
                        // Try to get real gallery folder ID
                        IField field = Util.GetFieldByName("GalleryFolderID", tmpItem.Fields);
                        // We are still at the same department, _sLastDepartmentName is still valid
                        if (field.Content.ToUpper() == _sLastDepartmentID)
                            break;

                        // Default value
                        _sLastDepartmentName = tmpItem.Name;

                        // Try to get real gallery folder name
                        IItem mediaItem = null;
                        try
                        { mediaItem = sourceItem.GetItem(field.Content.ToUpper()); }
                        catch { }
                        if (mediaItem != null)
                        {
                            _sLastDepartmentName = mediaItem.Name;
                            _sLastDepartmentID = "{" + mediaItem.ID.ToString().ToUpper() + "}";
                        }
                        break;
                    }
                    tmpItem = tmpItem.Parent;
                }

                foreach (IField field in destinationItem.Fields)
                {
                    string sContent = field.Content.ToLower();

                    if ((sContent.IndexOf("<file") > -1) || (sContent.IndexOf("&lt;file ") > -1))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(field.Content);
                        XmlNodeList files = doc.SelectNodes("//file");
                        foreach (XmlNode file in files)
                        {
                            // empty file node?
                            if ((file.Attributes["url"] == null) || (file.Attributes["title"] == null))
                                continue;

                            // Content is already in gallery format
                            if (file.Attributes["galleryformat"] != null)
                                continue;

                            string sUrl = file.Attributes["url"].Value;
                            string sTitle = file.Attributes["title"].Value;
                            string sMediaID = file.Attributes["mediaid"].Value;

                            // Content is already in gallery format, since it contains destination host
                            if (sUrl.Contains(_PluginOptions[1].Value))
                                continue;

                            //                        IItem mediaItem = sourceItem.GetItem(sMediaID);
                            int iFileSize = 0;
                            string sResult = CopyFile(sHost + sUrl, sTitle, out iFileSize);
                            if (sResult != null)
                            {
                                file.Attributes["mediaid"].Value = sResult;
                                file.Attributes["url"].Value = _PluginOptions[1].Value + string.Format("/Image.ashx?File={0}", System.Web.HttpUtility.UrlEncode(sResult));
                                file.Attributes.Append(doc.CreateAttribute("size"));
                                file.Attributes["size"].Value = iFileSize.ToString();
                            }
                        }
                        // If the content doesn't have <files> root, the doc object inserts <xml> root
                        if (doc.FirstChild.Name == "files")
                            field.Content = doc.OuterXml;
                        else
                            field.Content = doc.InnerXml;
                    }
                    // Convert filestorage fields
                    else if (sContent.IndexOf("/sitecore%20modules/filestorage/default.aspx?fileid=") > -1)
                    {
                        XmlDocument doc = Sgml.SgmlUtil.ParseHtml(sContent);
                        XmlNodeList linkNodes = doc.SelectNodes("//a");
                        foreach (XmlNode node in linkNodes)
                        {
                            string sUrl = Util.GetAttributeValue(node.Attributes["href"]);
                            string sTitle = Util.GetAttributeValue(node.Attributes["sc_text"]);
                            string sc_linktype = Util.GetAttributeValue(node.Attributes["sc_linktype"]);
                            string sc_url = Util.GetAttributeValue(node.Attributes["sc_url"]);
                            string sTarget = Util.GetAttributeValue(node.Attributes["target"]);
                            if ((sc_linktype == "media") ||
//.........这里部分代码省略.........
开发者ID:Cabana,项目名称:CMSConverter,代码行数:101,代码来源:FilestorageConversionPlugin.cs

示例4: ConvertFieldContent

        /// <summary>
        /// Convert field content into sitecore 6.x format, mostly links
        /// </summary>
        private string ConvertFieldContent(IItem CopyFrom, IField fromField)
        {
            string sContent = fromField.Content;
            if ((fromField.Type == "Rich Text") || (fromField.Type == "html") ||
                (fromField.Type == "MultiLink") || (fromField.Type == "General Link") ||
                (fromField.Type == "link"))
            {
                try
                {
                    XmlDocument doc = Sgml.SgmlUtil.ParseHtml(sContent);

                    List<XmlNode> removeableNodes = new List<XmlNode>();
                    bool bModified = false;
                    // Convert links to new format
                    XmlNodeList linkNodes = doc.SelectNodes("//a");
                    foreach (XmlNode node in linkNodes)
                    {
                        int t = 0;
                        if (fromField.Type == "link")
                            t++;
                        string sUrl = Util.GetAttributeValue(node.Attributes["href"]);
                        string sTitle = Util.GetAttributeValue(node.Attributes["sc_text"]);
                        string sc_linktype = Util.GetAttributeValue(node.Attributes["sc_linktype"]);
                        string sc_url = Util.GetAttributeValue(node.Attributes["sc_url"]);
                        string sTarget = Util.GetAttributeValue(node.Attributes["target"]);
                        // Possible linktypes: internal, external, mailto, anchor, javascript, media
                        if (sc_linktype == "internal")
                        {
                            IItem linkItem = CopyFrom.GetItem(sc_url);
                            if (linkItem != null)
                            {
                                sUrl = "~/link.aspx?_id=" + new Guid(linkItem.ID).ToString("N").ToUpper() + "&_z=z";
                            }
                        }

                        if (sUrl == "")
                        {
                            removeableNodes.Add(node);
                            continue;
                        }

                        node.Attributes["href"].Value = sUrl;
                        node.Attributes.Remove(node.Attributes["sc_text"]);
                        node.Attributes.Remove(node.Attributes["sc_linktype"]);
                        node.Attributes.Remove(node.Attributes["sc_url"]);
                        if (node.Attributes["sc_anchor"] != null)
                            node.Attributes.Remove(node.Attributes["sc_anchor"]);
                        bModified = true;
                    }

                    foreach (XmlNode node in removeableNodes)
                    {
                        node.ParentNode.RemoveChild(node);
                    }

                    if (bModified)
                    {
                        XmlNode root = doc.SelectSingleNode("root");
                        sContent = root.InnerXml;
                        // No tags at all, add a paragraph tag
                        if (root.ChildNodes.Count == 1)
                            sContent = "<p>" + root.InnerXml + "</p>";
                    }
                    // Add paragraph tags around content that weren't modified, and haven't got any paragraph tags
                    else if (((fromField.Type == "Rich Text") || (fromField.Type == "html")) &&
                             (sContent != ""))
                    {
                        XmlNode root = doc.SelectSingleNode("root");
                        // No tags at all, add a paragraph tag
                        if (root.ChildNodes.Count == 1)
                        {
                            sContent = "<p>" + root.InnerXml + "</p>";
                        }
                    }
                    sContent = HttpUtility.HtmlDecode(sContent);
                }
                catch (Exception ex)
                {
                    Util.AddWarning("Error converting content: " + CopyFrom.Path + ", message: " + ex.Message);
                }
            }
            else if (fromField.Type == "datetime")
            {
                // Convert from xsd null to normal null
                if (fromField.Content == "00010101T000000")
                    sContent = "";
            }

            return sContent;
        }
开发者ID:Cabana,项目名称:CMSConverter,代码行数:93,代码来源:Sitecore6xItem.cs


注:本文中的IItem.GetItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。