I need to present the user with a drop down of lists that contain a specific Content Type. The selected drop down item will be used within a workflow. The idea is similar to the existing functionality when associating a workflow when you select a list to hold the Tasks and a list to hold the History.
The code I came up with is as follows but it does not seem to work.
private System.Collections.Generic.IDictionary<Guid, string> GetTechnicalRoutingContentTypeUsage() {
var contentType = this.Web.Site.RootWeb.AvailableContentTypes[new SPContentTypeId("0x010089E3DFDB8C9D4B3FBB980447E313CE27")];
if (contentType == null) { return null; }
var lists = new System.Collections.Generic.Dictionary<Guid, string>();
var usages = SPContentTypeUsage.GetUsages(contentType);
foreach (var usage in usages) {
if (usage.IsUrlToList) {
var list = this.Web.GetListFromUrl(usage.Url);
lists.Add(list.ID, list.Title);
}
}
return lists;
}
Note that this
refers to an instance of LayoutsPageBase
since the method is being run within my workflow association form.
The problem is with the GetListFromUrl
method. It returns the very unhelpful exception:
System.Runtime.InteropServices.COMException: Cannot complete this action.
Please try again.<nativehr>0x80004005</nativehr><nativestack></nativestack>
Is there anything wrong with my code? Should I be collecting this information in a different manner? I know I can get a list of all the websites, then traverse through the lists while checking the ContentTypes property for each one but that seem like the long way...