我有一个SharePoint 2010网站设置本地调试具有以下地形:如何检查是否一个文档库(SPDocumentLibrary)支持特定的ContentType
Main (SPSite)
-> Toolbox (SPWeb)
-> MyTool (SPWeb)
我已经创建并部署以下主:
- 自定义字段 “RequestedBy”
- 自定义字段 “OriginalRequestFileName”
- 自定义内容类型 “RequestContentType” 的CO ntains除了基于上述的ContentType
- VisualWebPart“MyFileUploaderWebPart”具有自定义的EditorPart允许用户定义哪些文档库中的文件应该被上传OOB领域
- 自定义列表定义“RequestListDefinition”上述两个领域至。
我在MyTool中创建了一个基于我的自定义列表定义“RequestListDefinition”的“My Request List”列表实例。
在EditorPart中我有一个文档库的下拉列表。
private void PopulateDocumentLibraryList(DropDownList dropDownList)
{
SPWeb currentWebsite = SPContext.Current.Web;
SPListCollection lists = currentWebsite.GetListsOfType(SPBaseType.DocumentLibrary);
if (lists.Count > 0)
{
List<SPDocumentLibrary> docLibraries = lists.Cast<SPList>()
.Select(list => list as SPDocumentLibrary)
.Where(library => library != null && !library.IsCatalog && !library.IsSiteAssetsLibrary)
.ToList();
dropDownList.DataSource = docLibraries;
dropDownList.DataTextField = "Title";
dropDownList.DataValueField = "ID";
dropDownList.DataBind();
// Default the selected item to the first entry
dropDownList.SelectedIndex = 0;
}
}
我想将文档库的列表限制为仅从我部署的自定义列表定义派生的文档库列表。我想通过检查所支持的内容类型这样做的,因此试图改变WHERE子句:
private void PopulateDocumentLibraryList(DropDownList dropDownList)
{
SPWeb currentWebsite = SPContext.Current.Web;
SPListCollection lists = currentWebsite.GetListsOfType(SPBaseType.DocumentLibrary);
if (lists.Count > 0)
{
SPContentType voucherRequestListContentType = currentWebsite.ContentTypes["VoucherRequestContentType"];
List<SPDocumentLibrary> docLibraries = lists.Cast<SPList>()
.Select(list => list as SPDocumentLibrary)
.Where(library => library != null && !library.IsCatalog && !library.IsSiteAssetsLibrary && library.IsContentTypeAllowed(voucherRequestListContentType))
.ToList();
dropDownList.DataSource = docLibraries;
dropDownList.DataTextField = "Title";
dropDownList.DataValueField = "ID";
dropDownList.DataBind();
// Default the selected item to the first entry
dropDownList.SelectedIndex = 0;
}
}
它弹了,下面的错误,但:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Value cannot be null.
Parameter name: ct
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: ct
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: ct]
Microsoft.SharePoint.SPList.IsContentTypeAllowed(SPContentType ct) +26981638
Dominos.OLO.WebParts.FileUploader.<>c__DisplayClass7.<PopulateDocumentLibraryList>b__4(SPDocumentLibrary library) +137
System.Linq.WhereEnumerableIterator`1.MoveNext() +269
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +578
System.Linq.Enumerable.ToList(IEnumerable`1 source) +78
Dominos.OLO.WebParts.FileUploader.DocumentLibrarySelectorEditorPart.PopulateDocumentLibraryList(DropDownList dropDownList) +801
Dominos.OLO.WebParts.FileUploader.DocumentLibrarySelectorEditorPart.CreateChildControls() +154
System.Web.UI.Control.EnsureChildControls() +146
Dominos.OLO.WebParts.FileUploader.DocumentLibrarySelectorEditorPart.SyncChanges() +102
Microsoft.SharePoint.WebPartPages.ToolPane.OnSelectedWebPartChanged(Object sender, WebPartEventArgs e) +283
System.Web.UI.WebControls.WebParts.WebPartEventHandler.Invoke(Object sender, WebPartEventArgs e) +0
Microsoft.SharePoint.WebPartPages.SPWebPartManager.BeginWebPartEditing(WebPart webPart) +96
Microsoft.SharePoint.WebPartPages.SPWebPartManager.ShowToolPaneIfNecessary() +579
Microsoft.SharePoint.WebPartPages.SPWebPartManager.OnPageInitComplete(Object sender, EventArgs e) +296
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnInitComplete(EventArgs e) +11056990
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1674
这表明,我认为它的失败找到内容类型。
我的另一个想法是尝试和检索我的自定义列表定义类型“RequestListDefinition”的所有列表。但是,SPWeb.GetListsOfType()需要一个SPListTemplateType,它是一个枚举,因此不包含我的自定义列表定义。 SPListTemplateType(http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx)的文档建议使用接受字符串或int而不是SPListTemplateType的方法,但我没有看到任何文档。
有人可以帮我找出两种:
- 我怎么能得到的只是那些从我的自定义列表定义导出列表;或
- 如何获取我的自定义内容类型;或
- 指向一个更好的解决方案,限制SPDocumentLibrary的列表的方向?
谢谢!!
感谢,斯特凡:)这似乎已经成功地找到contentType中看到这一点。不幸的是,将IsContentTypeAllowed()调用添加到where子句并没有给我我期待的结果。 “网站页面”文档库仍显示在我的文档库下拉菜单中。 –
更新了关于“IsContentTypeAllowed”问题的问题。 – Stefan
导致没有返回文档库:/ –