如何使用C#代码在Wiki内容Web部件页面的内容标签中获取文本以及如何写文本? [英] How to get as well as write text inside content tag of Wiki content web part page using C# code?

查看:111
本文介绍了如何使用C#代码在Wiki内容Web部件页面的内容标签中获取文本以及如何写文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

<WebPartPages:WikiContentWebpart><Content>sdfsdf</Content></WebPartPages:WikiContentWebpart>

无法使用CSOM在内容标签内获取文本.我们也无法将财产放在财产袋中.

Cant get text inside the content tag using CSOM. We are also unable to get the property in property bag.

使用OM,这是我们如何通过:- 

Using OM, here is how we were able to achieve this by :- 

((Microsoft.SharePoint.WebPartPages.WikiContentWebpart)(wp)).Content

我们尝试将Microsoft.SharePoint.Client.WebParts.WebPart强制转换为Microsoft.SharePoint.WebPartPages.WikiContentWebpart,但无法这样做.因此需要帮助.

We tried casting Microsoft.SharePoint.Client.WebParts.WebPart to Microsoft.SharePoint.WebPartPages.WikiContentWebpart but were unable to. Hence need help.

推荐答案

WikiContentWebpart 是服务器端对象模型,因此您需要使用服务器端dll来访问它.

WikiContentWebpart is server side object model so you need use server side dll to access it.

此处是示例代码供您参考.

using (SPSite site = new SPSite("http://sp:12001/"))
            {
                var web = site.RootWeb;
                var page = web.GetFile("/SitePages/wikic1.aspx");

                var limitedWebPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);

                var webparts = limitedWebPartManager.WebParts;

                foreach (var webpart in webparts)
                {
                    if (webpart.GetType() == typeof(WikiContentWebpart))
                    {
                        var wikiwp = webpart as WikiContentWebpart;
                        Console.WriteLine( wikiwp.Content);
                    }
                    Console.WriteLine(webpart.GetType());
                }
                Console.WriteLine("done");
                Console.ReadKey();

            }



最好的问候,


这篇关于如何使用C#代码在Wiki内容Web部件页面的内容标签中获取文本以及如何写文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆