{"id":1794,"date":"2012-05-02T21:32:43","date_gmt":"2012-05-03T04:32:43","guid":{"rendered":"https:\/\/mmman.itgroove.net\/2012\/05\/coding-challenge-unknown-contenttypeid\/"},"modified":"2023-02-24T21:47:04","modified_gmt":"2023-02-24T21:47:04","slug":"coding-challenge-unknown-contenttypeid","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/","title":{"rendered":"Coding Challenge: Unknown ContentTypeId in Document Library"},"content":{"rendered":"<p>I was recently working with a colleague on a SharePoint coding problem involving a ContentTypeId we had assumed was correct, but quickly found out was coming up as something completely unexpected.&#160; We were performing a CAML query in C#, in which were were trying to retrieve the ContentType, and the unique ContentTypeId values.&#160; The values we were expecting should have started 0x followed by 73 HEX characters (for example, 0x010100124D1872DA1E3C4AA5B8505A4E86197A00B05E965C40608049BB8C2C1218F7120D).&#160; The query we formulated looked like below.<\/p>\n<p><font size=\"2\" face=\"Courier New\">SPQuery sQuery = new SPQuery();<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">sQuery.Query = @&quot;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;&quot;ContentType&quot;&quot; \/&gt;&lt;Value Type=&quot;&quot;Text&quot;&quot;&gt;My CT Value&lt;\/Value&gt;&lt;\/Eq&gt;&lt;\/Where&gt;&quot;;<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">sQuery.ViewFields = @&quot;&lt;FieldRef Name=&quot;&quot;Title&quot;&quot; \/&gt;&lt;FieldRef Name=&quot;&quot;ContentType&quot;&quot; \/&gt;&quot;;<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">sQuery.IncludeMandatoryColumns = true;<\/font><\/p>\n<p>The problem we were having was that <u>all<\/u> the results were coming back as the value 0x00C2208B8CE6E1422CADC1C521EAB2A68B instead (for distinctly different content types).&#160; The other problem we eventually detected was that the ContentType had no value either.&#160; So finally we brought out the big guns and went into the debugger.&#160; As it turns out, this unknown ContentTypeId value (00C2208B8CE6E1422CADC1C521EAB2A68B) is the null content type value.<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"600\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"600\"><a href=\"https:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png\" width=\"639\" height=\"157\" \/><\/a>          <\/p>\n<p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>To resolve this problem, we found the following MSDN article, <a title=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/sharepoint2010programming\/thread\/5998657c-2c83-43d5-ab48-3197d2250778\" href=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/sharepoint2010programming\/thread\/5998657c-2c83-43d5-ab48-3197d2250778\">http:\/\/social.technet.microsoft.com\/Forums\/en-US\/sharepoint2010programming\/thread\/5998657c-2c83-43d5-ab48-3197d2250778<\/a>. In there, a comment from Ferovac described a proper method for solving this in the CAML query (note, there\u2019s another proposed solution, but that solution requires you to re-write your query).&#160; His suggestion was as follows, \u201cI tried and managed to reproduce the same thing, but by adding also &quot;&lt;FieldRef Name=&quot;ContentTypeId&quot; \/&gt;&quot; to ViewFields, I received the correct result.\u201d. We simply changed the ViewFields line to the following, and it started returning the expected results.<\/p>\n<p><font size=\"2\" face=\"Courier New\">sQuery.ViewFields = @&quot;&lt;FieldRef Name=&quot;&quot;Title&quot;&quot; \/&gt;&lt;FieldRef Name=&quot;&quot;ContentType&quot;&quot; \/&gt;<font color=\"#ff0000\">&lt;FieldRef Name=&quot;&quot;ContentTypeId&quot;&quot; \/&gt;<\/font>&quot;;<\/font><\/p>\n<p><em>Important Note<\/em>, we had assumed that because we had the statement \u201csQuery.IncludeMandatoryColumns = true;\u201d in our code, that it would automatically include any fields (like ContentTypeId) which were necessary for a successful query.&#160; This assumption was clearly negatory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently working with a colleague on a SharePoint coding problem involving a ContentTypeId we had assumed was correct, but quickly found out was coming up as something completely unexpected.&#160; We were performing a CAML query in C#, in which were were trying to retrieve the ContentType, and the unique ContentTypeId values.&#160; The values &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\"><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[18,7],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Coding Challenge: Unknown ContentTypeId in Document Library - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Coding Challenge: Unknown ContentTypeId in Document Library - Archive\" \/>\n<meta property=\"og:description\" content=\"I was recently working with a colleague on a SharePoint coding problem involving a ContentTypeId we had assumed was correct, but quickly found out was coming up as something completely unexpected.&#160; We were performing a CAML query in C#, in which were were trying to retrieve the ContentType, and the unique ContentTypeId values.&#160; The values &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-03T04:32:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:47:04+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Colin Phillips (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Colin Phillips (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\",\"name\":\"Coding Challenge: Unknown ContentTypeId in Document Library - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png\",\"datePublished\":\"2012-05-03T04:32:43+00:00\",\"dateModified\":\"2023-02-24T21:47:04+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage\",\"url\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png\",\"contentUrl\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Coding Challenge: Unknown ContentTypeId in Document Library\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\",\"name\":\"Colin Phillips (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"caption\":\"Colin Phillips (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/cphillips\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Coding Challenge: Unknown ContentTypeId in Document Library - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/","og_locale":"en_US","og_type":"article","og_title":"Coding Challenge: Unknown ContentTypeId in Document Library - Archive","og_description":"I was recently working with a colleague on a SharePoint coding problem involving a ContentTypeId we had assumed was correct, but quickly found out was coming up as something completely unexpected.&#160; We were performing a CAML query in C#, in which were were trying to retrieve the ContentType, and the unique ContentTypeId values.&#160; The values &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/","og_site_name":"Archive","article_published_time":"2012-05-03T04:32:43+00:00","article_modified_time":"2023-02-24T21:47:04+00:00","og_image":[{"url":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png"}],"author":"Colin Phillips (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Colin Phillips (Alumni)","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/","url":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/","name":"Coding Challenge: Unknown ContentTypeId in Document Library - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"primaryImageOfPage":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage"},"image":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage"},"thumbnailUrl":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png","datePublished":"2012-05-03T04:32:43+00:00","dateModified":"2023-02-24T21:47:04+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#primaryimage","url":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png","contentUrl":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb.png"},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/02\/coding-challenge-unknown-contenttypeid\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"Coding Challenge: Unknown ContentTypeId in Document Library"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b","name":"Colin Phillips (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","caption":"Colin Phillips (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/cphillips\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1794"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=1794"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1794\/revisions"}],"predecessor-version":[{"id":2000,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1794\/revisions\/2000"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=1794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=1794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=1794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}