[英]Displaying the AllItems.aspx as a Web Part?
I've got a Sharepoint site with a document library. 我有一个带有文档库的Sharepoint网站。 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. 这在“ AllItems.aspx”“视图”中运行良好-即,当我单击Web部件的标题时,它将带我到一个新页面,其中似乎是一个“完整”的DocLib页面。
However, most users will access through a tabbed portal site, and thus will view the 'Web Part' view instead. 但是,大多数用户将通过选项卡式门户网站进行访问,因此将改为查看“ Web部件”视图。
My question is: is there a way to display the AllItems view within a Web Part? 我的问题是:有没有办法在Web部件中显示AllItems视图? Specifically, I'd like the nice left-hand toolbar (displaying my various views) to appear in the Web Part. 具体来说,我希望漂亮的左侧工具栏(显示我的各种视图)出现在Web部件中。
You could use the RenderAsHtml() method of a view. 您可以使用视图的RenderAsHtml()方法。
This method returns a HTML string, which you can display within your webpart. 此方法返回一个HTML字符串,您可以在Webpart中显示它。 But be careful, there is a bug regarding the context IDs. 但是请注意,存在关于上下文ID的错误。
I recommend to use the following function for setting the ID manually: 我建议使用以下功能手动设置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.