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


C# Sitecore.GetItem方法代码示例

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


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

示例1: CreateImportedTagsInSitecore

        private static void CreateImportedTagsInSitecore(Sitecore.Data.Database master, List<WPTag> tags, XBlogTags xbTags)
        {
            Sitecore.Data.Items.TemplateItem blogTagTemplate = master.GetItem(Tag.TagTemplateId);
            foreach (WPTag wpt in tags)
            {
                try
                {
                    string tagName = ItemUtil.ProposeValidItemName(wpt.TagName);

                    Tag t = xbTags.InnerItem.Add(tagName, blogTagTemplate).CreateAs<Tag>();

                    using (new EditContext(t.InnerItem))
                    {
                        t.InnerItem.SetString(Tag.TagNameFieldId, wpt.TagName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create tag: " + wpt.TagName + ex.Message, "XB Creator");
                }
            }
        }
开发者ID:zmalmquist,项目名称:XBlog,代码行数:22,代码来源:BlogCreator.cs

示例2: AddLanguageVersionItem

        private Item AddLanguageVersionItem(string posttype, string itemName, Dictionary<string, string> fieldsToUpdate, TemplateItem template, Item newItem, Sitecore.Data.Database master, string lang, string postid) {

            Item newLanguageVersionItem = master.GetItem(newItem.Paths.Path, Sitecore.Globalization.Language.Parse(lang));

            using (new Sitecore.SecurityModel.SecurityDisabler()) {
                try {
                    if (0 == newLanguageVersionItem.Versions.Count) {
                        newLanguageVersionItem.Versions.AddVersion();
                    }

                    newLanguageVersionItem.Editing.BeginEdit();
                    // Assign values to the fields of the new item
                    foreach (var fields in fieldsToUpdate) {
                        if (fields.Key == "Content Thumbnail") {
                            MediaItem mediaItem = DownloadImage(fields.Value);

                            Sitecore.Data.Fields.ImageField image = newLanguageVersionItem.Fields[fields.Key];
                            image.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
                            image.Alt = mediaItem.Alt;
                            image.MediaID = mediaItem.ID;

                        }
                        else {
                            if (fields.Key == "Page Title") {
                                Response.Write(postid + " | " + lang + " | <b>" + fields.Value + "</b><br/>");
                            }
                            newLanguageVersionItem.Fields[fields.Key].Value = fields.Value;

                        }
                        string tagids = string.Empty;
                        string source = string.Empty;
                        switch (fields.Key) {
                            case "Child Issues":
                                tagids = GetTags(posttype, "child-issue", postid, ChildIssueTemplate, "Issue Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Child Grades":
                                tagids = GetTags(posttype, "grade_level", postid, ChildGradesTemplate, "Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Child Diagnoses":
                                tagids = GetTags(posttype, "child-diagnosis", postid, ChildDiagnosesTemplate, "Diagnosis Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Complexity Levels":
                                tagids = GetTags(posttype, "content-complexity", postid, ComplexityLevelsTemplate, "Complexity Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Diagnosed Condition":
                                tagids = GetTags(posttype, "diagnosed-undiagnosed", postid, DiagnosedConditionTemplate, "Diagnosis Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Applicable Interests":
                                tagids = GetTags(posttype, "parent-interests", postid, ApplicableInterestsTemplate, "Applicable Interests");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Applicable Personalities":
                                tagids = GetTags(posttype, "personality-type", postid, ApplicablePersonalitiesTemplate, "Personality Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;
                            case "Other Applicable Evaluations":
                                tagids = GetTags(posttype, "other-evaluations", postid, OtherApplicableEvaluationsTemplate, "Evaluation Name");
                                if (!string.IsNullOrEmpty(tagids)) {
                                    newLanguageVersionItem[fields.Key] = tagids;
                                }
                                break;


                            //case "Reviewed by":
                            //    source = "/sitecore/content/Globals/Content Taxonomies/Article/Reviewers";
                            //    tagids = GetTags(posttype, "child-diagnosis", newLanguageVersionItem.Fields["Reviewed by"].Source, postid, source);
                            //    if(!string.IsNullOrEmpty(tagids)){
                            //        newLanguageVersionItem[fields.Key] = tagids;
                            //    }
                            //    break;
                        }
                        // newLanguageVersionItem.Fields[fields.Key].Value = fields.Value;
                    }
                    newLanguageVersionItem.Editing.EndEdit();
                    newLanguageVersionItem.Editing.AcceptChanges();

                }
                catch (Exception ex) {
                    newLanguageVersionItem.Editing.CancelEdit();

                }
//.........这里部分代码省略.........
开发者ID:D0cNet,项目名称:UnderstoodDotOrg.sln,代码行数:101,代码来源:import.aspx.cs

示例3: CreateImportedAuthorsInSitecore

        private static void CreateImportedAuthorsInSitecore(Sitecore.Data.Database master, List<WPAuthor> authors, XBlogAuthors xbAuthors)
        {
            Sitecore.Data.Items.TemplateItem blogAuthorTemplate = master.GetItem(Author.AuthorTemplateId);
            foreach (WPAuthor wpa in authors)
            {
                try
                {
                    string authorsName = ItemUtil.ProposeValidItemName(wpa.Name);

                    Author a = xbAuthors.InnerItem.Add(authorsName, blogAuthorTemplate).CreateAs<Author>();

                    using (new EditContext(a.InnerItem))
                    {
                        a.InnerItem.SetString(Author.AuthorFullNameFieldId, wpa.Name.Replace(".", " "));
                        a.InnerItem.SetString(Author.AuthorEmailAddressFieldId, wpa.Email);
                        a.InnerItem.SetString(Author.CreatorFieldId, wpa.Creator);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create author: " + wpa.Name + ex.Message, "XB Creator");
                }
            }
        }
开发者ID:zmalmquist,项目名称:XBlog,代码行数:24,代码来源:BlogCreator.cs

示例4: CreateImportedCategoriesInSitecore

        private static void CreateImportedCategoriesInSitecore(Sitecore.Data.Database master, List<WPCategory> categories, XBlogCategories xbCategory)
        {
            Sitecore.Data.Items.TemplateItem blogCategoryTemplate = master.GetItem(Category.CategoryTemplateId);
            foreach (WPCategory wpc in categories)
            {
                try
                {
                    string categoryName = ItemUtil.ProposeValidItemName(wpc.CategoryName);

                    Category c = xbCategory.InnerItem.Add(categoryName, blogCategoryTemplate).CreateAs<Category>();

                    using (new EditContext(c.InnerItem))
                    {
                        c.InnerItem.SetString(Category.CategoryNameFieldId, wpc.CategoryName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("failed to create categor: " + wpc.CategoryName + ex.Message, "XB Creator");
                }
            }
        }
开发者ID:zmalmquist,项目名称:XBlog,代码行数:22,代码来源:BlogCreator.cs

示例5: RemoveTestTemplate

 private void RemoveTestTemplate(Sitecore.Data.Database db)
 {
     using (var disabler = new Sitecore.SecurityModel.SecurityDisabler())
     {
         var template = db.GetItem("/sitecore/templates/user defined/user defined item");
         template.Delete();
     }
 }
开发者ID:dsolovay,项目名称:SitecoreData,代码行数:8,代码来源:FastQueryAcceptanceTests.cs

示例6: RemoveTestContent

 private void RemoveTestContent(Sitecore.Data.Database db)
 {
     using (new SecurityDisabler())
     {
         db.GetItem("/sitecore/content/home/test data").Delete();
     }
 }
开发者ID:dsolovay,项目名称:SitecoreData,代码行数:7,代码来源:FastQueryAcceptanceTests.cs

示例7: CreateTestTemplate

 private void CreateTestTemplate(Sitecore.Data.Database db)
 {
     using (var disabler = new Sitecore.SecurityModel.SecurityDisabler())
     {
         string templatexml = File.ReadAllText(System.Environment.CurrentDirectory + @"\..\..\xml\TestTemplate.xml").ToString();
         db.GetItem("/sitecore/templates/user defined").Paste(templatexml, false, PasteMode.Merge);
     }
 }
开发者ID:dsolovay,项目名称:SitecoreData,代码行数:8,代码来源:FastQueryAcceptanceTests.cs

示例8: CreateTestContent

 private void CreateTestContent(Sitecore.Data.Database db)
 {
     string itemxml = File.ReadAllText(System.Environment.CurrentDirectory + @"\..\..\xml\TestItems.xml");
     Item home = db.GetItem("/sitecore/content/home");
     using (new SecurityDisabler())
     {
         home.Paste(itemxml,false,PasteMode.Merge);
     }
 }
开发者ID:dsolovay,项目名称:SitecoreData,代码行数:9,代码来源:FastQueryAcceptanceTests.cs

示例9: getAliasItem

        /// <summary>
        /// Gets the alias item.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        private Item getAliasItem(HttpRequestArgs args, Sitecore.Data.Database masterDb) 
        {
            string websitePath = Sitecore.Context.Site.RootPath.ToLower();

            if (masterDb != null && Sitecore.Context.Site != null)
            {
                if (!string.IsNullOrEmpty(args.LocalPath) && args.LocalPath.Length > 1)
                {                    
                    Item aliasItem = masterDb.GetItem(string.Format("{0}/{1}/{2}", websitePath, "settings", "aliases") + args.LocalPath);                   
                    if (aliasItem != null)
                    {                    
                        return aliasItem;
                    }
                }
            }            

            return null;
        }
开发者ID:yvanruth,项目名称:Sitecore.SharedSource.MultisiteAliasResolver,代码行数:23,代码来源:MultiSiteAliasResolver.cs


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