0

In SharePoint 2007, I am trying to create a Document Library containing a special folder where the files within that special folder can have some extra meta-data. I've been following these instructions and it is working pretty well. I created a folder content type, SpecialFolderType, and a document content type, SpecialDocumentType. When the user is inside of the special folder, the New menu correctly only displays the SpecialDocumentType option.

My problem is that when using the Upload option inside the special folder, the default content type is still the plain Document type. Is there a way to either force the content type to be SpecialDocumentType, or at least make it the default, for this special folder only?

0

I found a way to do this. It's not perfect -- any improvements are welcome...

Using SharePoint Designer 2007, I opened the document library's EditForm.aspx file, and found this line:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

After that I added the following code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("chooseNonDefaultContentType");
function chooseNonDefaultContentType() 
{
  var options = $("select[title='Content Type'] option");
  if (options.length == 2)
  {
    nonDocumentOptions = options.filter(function() {
      return $(this).text() != "Document"
    });
    if (nonDocumentOptions.length == 1)
    {
      if (!nonDocumentOptions.prop('selected'))
      {
        nonDocumentOptions.prop('selected', true);
        nonDocumentOptions.parent().trigger("change");
      }
      else
      {
        nonDocumentOptions.parent().prop('disabled', true);
      }
    }   
  }
}
</script>

It is fairly specific to my case -- it searches for the Content Type drop-down select control. If there are exactly 2 options, one of which is Document, it selects the other option, triggers the normal change handler, and then disables the select control. Triggering the change handler was necessary for the change to stick but it does cause a page reload/flicker.

There is also has a problem if the user clicks Cancel on the edit form after uploading a file: the file is still present but has the Document content type. It's not a big problem since check-in/out is enabled, which means that these Documents are checked out, and the javascript has another chance to run before the file can be checked in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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