0

我有一个带有文档库的 Sharepoint 站点。我已经设置了一些自定义视图,并希望用户能够选择他们喜欢的视图。这在“AllItems.aspx”“视图”中运行良好 - 即,当我单击 Web 部件的标题时,它会将我带到一个新页面,其中似乎是一个“完整的”DocLib 页面。

但是,大多数用户将通过选项卡式门户网站进行访问,因此将改为查看“Web 部件”视图。

我的问题是:有没有办法在 Web 部件中显示 AllItems 视图?具体来说,我希望漂亮的左侧工具栏(显示我的各种视图)出现在 Web 部件中。

4

1 回答 1

0

您可以使用视图的RenderAsHtml()方法。

此方法返回一个 HTML 字符串,您可以在 Web 部件中显示该字符串。但要小心,有一个关于上下文 ID 的错误。

我建议使用以下函数手动设置 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;
}
于 2012-02-02T15:54:14.950 回答