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...

1 Answer 1


SPContentTypeUsage.Url returns server relative Url in case of usage in a list. Instead of SPWeb.GetListFromUrl(usage.Url) use

var list = this.Web.GetList(usage.Url);


var list = this.Web.GetList(this.Web.Url + usage.Url);
  • So even though I am only dealing with a top level site/web, I need to be using Web.GetList() instead of Web.GetListFromUrl()?
    – Jason
    Mar 17, 2014 at 21:34
  • GetListFromUrl() expects url to a webpart page (for example url to a view, like http://...../AllItems.aspx) while GetList() expect Url to the list, like "/Lists/ListName". usage.Url returns Url to the list, not to a webpart page. If you still have problems try with this.Web.Site.RootWeb.GetList(usage.Url). Mar 17, 2014 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.