Sitecore 更新项目中的链接?
我有下面的小脚本Sitecore 更新项目中的链接?,sitecore,Sitecore,我有下面的小脚本 Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master"); using (new Sitecore.SecurityModel.SecurityDisabler()) { foreach (Sitecore.Data.Items.Item child in item.Children) {
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
using (new Sitecore.SecurityModel.SecurityDisabler())
{
foreach (Sitecore.Data.Items.Item child in item.Children)
{
foreach (ItemLink link in child.Links.GetAllLinks())
{
Item itm = link.GetTargetItem();
if (itm != null) {
Response.Write(link.TargetPath + " (" + itm.Paths.IsMediaItem + ", " + itm.ID + ")" + "<br/>");
} else
{
Response.Write("<span style='color:red;font-weight:bold;'>NULL ITEM ("+ link.TargetPath + ")</span><br/>");
}
}
if (item.Paths.ContentPath.Split("/".ToCharArray()).Length <= 10)
RecurseLinks(child, reset);
}
}
Sitecore.Data.Database master=Sitecore.Configuration.Factory.GetDatabase(“master”);
使用(新Sitecore.SecurityModel.SecurityDisabler())
{
foreach(Item.Children中的Sitecore.Data.Items.Item子项)
{
foreach(child.Links.GetAllLinks()中的ItemLink链接)
{
Item itm=link.GetTargetItem();
如果(itm!=null){
Write(link.TargetPath+”(“+itm.path.IsMediaItem+”,“+itm.ID+”)+”
);
}否则
{
Write(“空项(“+link.TargetPath+”)
);
}
}
if(item.path.ContentPath.Split(“/”.ToCharArray()).Length则“重建链接数据库”操作应该可以工作。
空ID可能是由断开的链接(更新链接时在数据库中找不到目标项)引起的。
因此,通过控制面板或在代码中重建链接(请参见LinkDatabaseHelper
)应该有效。我不明白您为什么要使用SecurityDisabler,除非内容受到保护或您试图修改sitecore中的内容项。此外,从您的问题来看,不清楚您试图实现什么:在数据库中重写sitecore项URL或呈现项的绝对路径?@xoail我正在使用SecurityDisabler beca使用我想修改内容-只是还没有弄清楚如何修改:-)上面提到的脚本列出了“我的项目”中的所有链接。这是一个Sitecore 6.5解决方案,因此默认情况下,链接将与GUID一起列出。但是,由于某些内容是从另一个解决方案导入的,因此某些链接将直接链接到媒体库中的文件。类似“~/media/my folder/my pdf file.pdf.ashx”。我想更改这些设置,因此它们将链接到GUID(然后我可以通过web.config设置控制它如何显示给用户)。我怀疑它是否有效,但您是否尝试调用Sitecore.Links.LinkDatabaseHelper.UpdateLink(child);对于每个孩子?@ChristianHagelid不知道这个。但是找不到任何关于它实际功能的好文档?我在ILSpy中查看内核dll时发现了它。很难看到它实际在做什么。问题是有些链接是“硬编码”的在富文本编辑器中。我想将这些更改为链接到项目的GUID,而不是绝对链接。