Content type document template url

Feb 20, 2011 at 12:04 PM

Can I get content type document template url form GetListContentTypes method?

Coordinator
Feb 20, 2011 at 2:21 PM
Edited Feb 20, 2011 at 2:22 PM

Yes. When you have questions about what the Web Services operations actually return, check the MSDN SDK pages, which I provide links to.

If you look at http://msdn.microsoft.com/en-us/library/lists.lists.getlistcontenttypes.aspx, you'll see that the URL to the DocumentTemplate is one of the values returned.

M.

Feb 20, 2011 at 7:17 PM

Thansk for reply, but whean i run  .find("DocumentTemplate").size() method result is "0". I'm missing something? 

Coordinator
Feb 21, 2011 at 5:11 AM

You'll need to do some debugging on this. I can't really tell where you've got the .find().

M.

Feb 21, 2011 at 11:40 AM

Here is my code:

 

$().SPServices({
  operation: "GetListContentTypes", // See the MSDN SDK at http://msdn.microsoft.com/en-us/library/lists.lists.getlistcontenttypes.aspx for details on this operation
  listName: $().SPServices.SPListNameFromUrl(), // The SPListNameFromUrl function gets the list name for the current context based on the URL
  async: false, // We'll do this asynchronously
  completefunc: function (xData, Status) {

    // trying to find DocumentTemplate TargetName
    $(xData.responseXML).find("DocumentTemplate").each(function() { // All of the list's Content Types will be returned. We'll loop through to get the one we are interested in
      alert($(this).attr("TargetName"));
    });

   or ...

  
  $(xData.responseXML).find("ContentType").each(function() { // All of the list's Content Types will be returned. We'll loop through to get the one we are interested in
    alert($(this).attr("DocumentTamplate"));
  });

  }
});

Can you help me extract that information, content type document template url?

Coordinator
Feb 21, 2011 at 2:48 PM
Edited Feb 21, 2011 at 3:02 PM

The DocumentTemplate will only be present if all of the following are true:
* It's a Document Library (should go without saying, but still...)
* Content Type Management is turned on in the Document Librairy's Advanced Settings
* A specific template has been uploaded in the Advanced Settings for the Content Type

It looks like the MSDN documentation for GetListContentTypes is incorrect, and the DocumentTemplate is not returned. However, it *is* returned with GetListContentType:

$().SPServices({
  operation: "GetListContentType",
  listName: "jQuery Libraries",
  contentTypeId: "0x010100C0F3E45BE83A6942AFEA485A1F128D840018AE9B3BF9B36B4D88F57F4557DFA0B8",
  async: false, // We'll do this asynchronously
  completefunc: function (xData, Status) {
    $(xData.responseXML).find("DocumentTemplate").each(function() {
alert($(this).attr("TargetName")); }); } });
M.
Feb 21, 2011 at 2:59 PM

Ok, that was very helpful.

My plan is to use GetListContentType in GetListContentTypes method for extracting this information. Now I have another problem, performance ;)

Thanks!

Coordinator
Feb 21, 2011 at 3:01 PM

I think that you'll find that that the Web Services are very fast. Worry about performance if/when it becomes an issue!

M.