简体   繁体   中英

Displaying the AllItems.aspx as a Web Part?

I've got a Sharepoint site with a document library. 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.

However, most users will access through a tabbed portal site, and thus will view the 'Web Part' view instead.

My question is: is there a way to display the AllItems view within a Web Part? Specifically, I'd like the nice left-hand toolbar (displaying my various views) to appear in the Web Part.

You could use the RenderAsHtml() method of a view.

This method returns a HTML string, which you can display within your webpart. But be careful, there is a bug regarding the context IDs.

I recommend to use the following function for setting the ID manually:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM