SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In other words, is there a SPField.ListsFieldUsedIn() equivalent in SharePoint 2007? Ref:

share|improve this question
I checked both SPField and SPList class members. Nothing in either have any property or method that will give me a connection between the two. Please help. I need to findout whether a given Site Column is already added to the List. – Tom Mar 8 '12 at 16:56

Here's how it's done in SharePoint 2010:

public ICollection<SPFieldTemplateUsage> ListsFieldUsedIn()
    List<SPFieldTemplateUsage> list = new List<SPFieldTemplateUsage>();
    using (SPSqlCommand command = new SPSqlCommand())
        using (SqlDataReader reader = this.GetSqlDataForPushdown(command))
            if (reader != null)
                while (reader.Read())
                    SPFieldTemplateUsage item = new SPFieldTemplateUsage();
                    item.WebID = (Guid) reader[0];
                    item.ListID = (Guid) reader[1];
            return list;

private SqlDataReader GetSqlDataForPushdown(SPSqlCommand cmd)
    SPSite site = this.Fields.Web.Site;
    SqlSession sqlSession = site.SqlSession;
    cmd.Parameters.AddWithValue("@SiteId", site.ID);
    cmd.Parameters.AddWithValue("@FieldId", this.Id.ToByteArray());
    cmd.Parameters.AddWithValue("@BaseTypes", SPBaseFieldId.BaseTypesFromFieldId(this.Id));
    return sqlSession.ExecuteReader((SqlCommand) cmd);

I don't have a SharePoint 2007 VM handy to see if the stored proc exists.

The alternative is to loop through all the lists in the site collection and check the Fields collection. It won't be fast but it'll do the trick.

share|improve this answer
Thanks for the code Rob. If you could post the loop, I could mark it as answer. In fact, that is exactly what I ended up doing. I had to loop through all the lists in the site collection and use the List.Fields() method. – Tom Mar 9 '12 at 3:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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