[英]Displaying the AllItems.aspx as a Web Part?
我有一個帶有文檔庫的Sharepoint網站。 我已經設置了一些自定義視圖,希望用戶能夠選擇他們喜歡的視圖。 這在“ AllItems.aspx”“視圖”中運行良好-即,當我單擊Web部件的標題時,它將帶我到一個新頁面,其中似乎是一個“完整”的DocLib頁面。
但是,大多數用戶將通過選項卡式門戶網站進行訪問,因此將改為查看“ Web部件”視圖。
我的問題是:有沒有辦法在Web部件中顯示AllItems視圖? 具體來說,我希望漂亮的左側工具欄(顯示我的各種視圖)出現在Web部件中。
您可以使用視圖的RenderAsHtml()方法。
此方法返回一個HTML字符串,您可以在Webpart中顯示它。 但是請注意,存在關於上下文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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.