如何在 sharepoint 2007 中列出和编辑所有 Web 部件的 html?

发布于 2024-10-05 14:29:01 字数 1463 浏览 0 评论 0原文

我是 sharepoint 的新手,我必须在所有 Web 部件中进行非常简单的修改。我们有很多包含非常简单的 html 的 Web 部件。 html 仅包含一个链接和一个图像。

Web 开发人员已将完整链接添加到页面和图像,这会导致一些问题。我想扫描所有 Web 部件 html 并用相对链接替换完整链接。

是否可以 ?我们有大量的页面和链接。手动完成需要两周!

谢谢!

编辑#2: 现在的问题是:是否可以列出我网站中的所有 aspx 文件? 我知道如何使用 url 访问 Web 部件内容:

using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(
                "ca/Pages/Home.aspx", PersonalizationScope.Shared))
        {
            foreach (System.Web.UI.WebControls.WebParts.WebPart wp in manager.WebParts)
            {
                System.Console.WriteLine(wp.Title);
                if (wp.GetType().Equals(typeof(Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)))
                {
                    Microsoft.SharePoint.WebPartPages.ContentEditorWebPart thisWebPart = wp as Microsoft.SharePoint.WebPartPages.ContentEditorWebPart;

                    System.Console.WriteLine(thisWebPart.Content.InnerText );
                    System.Console.WriteLine(thisWebPart.Content.InnerXml);
                }

            }
        }

编辑#1: 根据要求,他们是一个示例:

我想使用如下代码从所有共享 Web 部件中删除“http://www.mywebsite.com”:

<A title="" href="http://www.mywebsite.com/Pages/Career.aspx" target=""><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" src="http://www.mywebsite.com/images/Career.jpg" border=0></A>

I am new in sharepoint and I have to do a very simple modification in all web part. We have lots of web part containing very simple html. The html only contain a link and an image.

Web developers had put full links to pages and images and it cause some problems. I want to scan all of the web parts html and replace full links by relative links.

Is it possible ? We have tons of pages and links. Doing it manually will take 2 weeks!!!

Thanks!

EDIT #2:
Now the question is: Is it possible to list all aspx files in my website?
I know how to access the web parts content with a url :

using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(
                "ca/Pages/Home.aspx", PersonalizationScope.Shared))
        {
            foreach (System.Web.UI.WebControls.WebParts.WebPart wp in manager.WebParts)
            {
                System.Console.WriteLine(wp.Title);
                if (wp.GetType().Equals(typeof(Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)))
                {
                    Microsoft.SharePoint.WebPartPages.ContentEditorWebPart thisWebPart = wp as Microsoft.SharePoint.WebPartPages.ContentEditorWebPart;

                    System.Console.WriteLine(thisWebPart.Content.InnerText );
                    System.Console.WriteLine(thisWebPart.Content.InnerXml);
                }

            }
        }

EDIT #1:
As requested their is an example:

I want to remove "http://www.mywebsite.com" from all shared webparts with code like this:

<A title="" href="http://www.mywebsite.com/Pages/Career.aspx" target=""><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" src="http://www.mywebsite.com/images/Career.jpg" border=0></A>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

意中人 2024-10-12 14:29:01

在内容编辑器 Web 部件中,内容存储在内容标签下,

<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<p>test document test document</p>]]></Content>

我在这里建议是在 sharepoint desginer 中打开网站,并对所有页面使用查找和替换选项

In content editor web part the content is stored under content tag

<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<p>test document test document</p>]]></Content>

what i can suggest here is to open the site in sharepoint desginer and use the find and replace option for all pages

浅浅 2024-10-12 14:29:01

我不确定我是否得到了确切的要求。编写一个程序来做到这一点怎么样?通过正则表达式检测链接并替换它们。

I am not sure if I got what's required exactly. What about writing a program that do that? Detect the links by regex and replace them.

总以为 2024-10-12 14:29:01

如果您想实际更改 Sharepoint 中的内容,则可能很难在代码中执行此操作。每个 Web 部件的工作方式都不同,因此没有适用于所有 Web 部件的标准解决方案。例如,CQWP 可以从各种列表中提取数据,因此对该 Web 部件进行更改的方法是更改​​它从中提取的列表中的数据。其他 Web 部件可能从 SQL Server、报表中提取数据,其中包含 IFrame 等。某些 Web 部件甚至可能将 URL 硬编码在自定义 DLL 中,您只能通过修改 DLL 所属的解决方案/功能来更改它重新部署更新的版本。

然而,另一种解决方案是编写一个响应过滤器,它将获取 Sharepoint 的输出,并在每次从 Sharepoint 请求页面时动态地执行查找/替换。有关如何执行此操作的详细信息,请参阅 http://aspnetresources.com/articles/HttpFilters

If you want to actually change the content in Sharepoint, it could be difficult to do this in code. Every webpart works differently, so there's no standard solution for all web parts. For example, a CQWP can pull data from various lists, so the way to make the change for that webpart would be to change the data in the lists it pulls from. Other webparts might pull data from SQL Server, Reports, have IFrames in them, etc. Some webparts might even have the URLs hardcoded in a custom DLL, which you could only change by modifying the solution/feature that the DLL is a part of and redeploying the updated version.

However, an alternate solution is to write a Response Filter, which will take the output of Sharepoint and dynamically do a find/replace every single time a page is requested from Sharepoint. See http://aspnetresources.com/articles/HttpFilters for more information on how to do that.

累赘 2024-10-12 14:29:01

分为两部分,第一部分是循环访问站点中的所有 Web 部件页面 - 那里有很多示例,因此不要在这里重复这些而使事情变得混乱。

第二部分是更新 Content 属性并保存 - 看起来这是 以编程方式更新内容编辑器 Web 部件 (CEWP),因此:-

using System.Xml;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

private void updateContentEditor(SPWeb web, string pageUrl)
{
    using (SPLimitedWebPartManager manager =
           web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
    {
        foreach (WebPart wp in manager.WebParts)
        {
            if (wp.GetType() == typeof(ContentEditorWebPart))
            {
                ContentEditorWebPart cewp = wp as ContentEditorWebPart;
                cewp.Content.InnerXml;

                // See http://justgeeks.blogspot.com/2009/02/i-found-to-be-bit-tricky-to-update.html
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement xmlElement = xmlDoc.CreateElement("MyElement");

                // Do you change logic here
                xmlElement.InnerText =
                   contentEditor.Content.InnerText.Replace(BEFORE, AFTER);

                // Save changes
                contentEditor.Content = xmlElement;
                manager.SaveChanges(cewp);
            }
        }
    }
}

Two parts to this, the first is to loop through all web part pages in your site - quite a few examples out there so not going to muddy things by repeating that here.

The second part is to update the Content property and save - seem like this is the missing part of your puzzle for updating the Content Editor Web Part (CEWP) programatically so :-

using System.Xml;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

private void updateContentEditor(SPWeb web, string pageUrl)
{
    using (SPLimitedWebPartManager manager =
           web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
    {
        foreach (WebPart wp in manager.WebParts)
        {
            if (wp.GetType() == typeof(ContentEditorWebPart))
            {
                ContentEditorWebPart cewp = wp as ContentEditorWebPart;
                cewp.Content.InnerXml;

                // See http://justgeeks.blogspot.com/2009/02/i-found-to-be-bit-tricky-to-update.html
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement xmlElement = xmlDoc.CreateElement("MyElement");

                // Do you change logic here
                xmlElement.InnerText =
                   contentEditor.Content.InnerText.Replace(BEFORE, AFTER);

                // Save changes
                contentEditor.Content = xmlElement;
                manager.SaveChanges(cewp);
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文