2012-02-02 2 views
0

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

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

私の質問です:Webパーツ内にAllItemsビューを表示する方法はありますか?具体的には、Webパーツに表示される便利な左ツールバー(さまざまなビューを表示する)が必要です。

答えて

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