简体   繁体   English

将AllItems.aspx显示为Web部件?

[英]Displaying the AllItems.aspx as a Web Part?

I've got a Sharepoint site with a document library. 我有一个带有文档库的Sharepoint网站。 I've set up some custom views, and would like users to be able to select which one they like. 我已经设置了一些自定义视图,希望用户能够选择他们喜欢的视图。 This works fine in the 'AllItems.aspx' 'view' - ie, when I click the title of the Web Part, it takes me to a new page, with what seems to be a 'full' DocLib page. 这在“ AllItems.aspx”“视图”中运行良好-即,当我单击Web部件的标题时,它将带我到一个新页面,其中似乎是一个“完整”的DocLib页面。

However, most users will access through a tabbed portal site, and thus will view the 'Web Part' view instead. 但是,大多数用户将通过选项卡式门户网站进行访问,因此将改为查看“ Web部件”视图。

My question is: is there a way to display the AllItems view within a Web Part? 我的问题是:有没有办法在Web部件中显示AllItems视图? Specifically, I'd like the nice left-hand toolbar (displaying my various views) to appear in the Web Part. 具体来说,我希望漂亮的左侧工具栏(显示我的各种视图)出现在Web部件中。

You could use the RenderAsHtml() method of a view. 您可以使用视图的RenderAsHtml()方法。

This method returns a HTML string, which you can display within your webpart. 此方法返回一个HTML字符串,您可以在Webpart中显示它。 But be careful, there is a bug regarding the context IDs. 但是请注意,存在关于上下文ID的错误。

I recommend to use the following function for setting the ID manually: 我建议使用以下功能手动设置ID:

public static String RenderAsHtmlWithFix(SPView view, uint id)
{
    String html = String.Empty;
    if (view != null)
    {
        html = view.RenderAsHtml();
        String ctxIDString;
        int ctxID;
        GetCtxID(html, out ctxIDString, out ctxID);
        if (Int32.TryParse(ctxIDString, out ctxID))
        {
            html = html.Replace("ctx" + ctxID, "ctx" + id);
            html = html.Replace("ctxId = " + ctxID, "ctxId= " + id);
            html = html.Replace("CtxNum=\"" + ctxID + "\"", "CtxNum=\"" + id + "\"");
            html = html.Replace("FilterIframe" + ctxID, "FilterIframe" + id);
            html = html.Replace("titl" + ctxID + "-", "titl" + id + "-");
            html = html.Replace("tbod" + ctxID + "-", "tbod" + id + "-");
            html = html.Replace("foot" + ctxID + "-", "foot" + id + "-");
            html = html.Replace("up('" + ctxID + "-", "up('" + id + "-");
            html = html.Replace("img_" + ctxID + "-", "img_" + id + "-");          
        }
    }
    return html;
}

private static void GetCtxID(String html, out String ctxIDString, out int ctxID)
{
    int idIndex = html.IndexOf("ctxId =");
    ctxIDString = String.Empty;
    for (int i = idIndex + 7; html[i] != ';'; i++)
    {
        ctxIDString += html[i];
    }
    ctxIDString = ctxIDString.Trim();
    ctxID = 1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sharepoint 在“AllItems.aspx”中显示(不完整)ID - Sharepoint shows (incomplete) id in “AllItems.aspx” SharePoint Office365 Powershell Webpart AllItems.aspx - SharePoint Office365 Powershell Webpart AllItems.aspx SharePoint Hosted App 2013:自定义List / AllItems.aspx页 - SharePoint Hosted App 2013: Customize List/AllItems.aspx page 在SharePoint Designer 2010 AllItems.aspx xslt视图中计算列 - Compute columns in SharePoint Designer 2010 AllItems.aspx xslt view 我的子站点中缺少pages / forms / allitems.aspx - pages/forms/allitems.aspx missing from my sub site 如何为 ClientContext 正确删除 SitePages/Home.aspx 或 Forms/AllItems.aspx? - How do I remove SitePages/Home.aspx or Forms/AllItems.aspx correctly for ClientContext? 如何覆盖 Upload.aspx 或 AllItems.aspx 等 SharePoint 2013(不是 SP 设计器) - How can you override Upload.aspx or AllItems.aspx etc. SharePoint 2013 (NOT SP Designer) SharePoint 2013在allitems.aspx中我如何获取列表标题和名称 - SharePoint 2013 In allitems.aspx How Do I get the list title and Name 是否可以在Sharepoint allitems.aspx页面中将静态值调整为动态(javascript)值? - Adjust static value into dynamic (javascript) value possible in Sharepoint allitems.aspx page? 在哪里设置样式标签<style> in AllItems.aspx when edited in Sharepoint Designer - Where to style tag <style> in AllItems.aspx when edited in Sharepoint Designer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM