0

ドキュメント ライブラリを備えた SharePoint サイトを持っています。いくつかのカスタム ビューを設定しました。ユーザーが好きなビューを選択できるようにしたいと考えています。これは 'AllItems.aspx' 'ビュー' で正常に動作します。つまり、Web パーツのタイトルをクリックすると、'完全な' DocLib ページのように見える新しいページが表示されます。

ただし、ほとんどのユーザーはタブ付きのポータル サイトからアクセスするため、代わりに「Web パーツ」ビューを表示します。

私の質問は、Web パーツ内に AllItems ビューを表示する方法はありますか? 具体的には、左側のツールバー (さまざまなビューを表示) を Web パーツに表示したいと考えています。

4

1 に答える 1

0

ビューのRenderAsHtml()メソッドを使用できます。

このメソッドは、Web パーツ内に表示できる HTML 文字列を返します。ただし、コンテキスト 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 に答える