4

So I'm absolutely new to SharePoint 2010, and have been given a task as part of my internship and I'm stuck.

When I click 'new document' in Document Library, I need to give option of selecting 1 of the multiple templates availale, and then launch word 2010, with that template pre-loaded. Now, how do I go about doing all this??

I could not find any solution online since they all create custom content types, but no one talks about templates. Also, I'm trying to do this using Visual Studio.

1
  • Welcome to SharePoint Stack Exchange! A well written question encourages people to answer it. Please read our guidelines which I've used to improve your post. You can also read How to Ask for more general guidelines.
    – Alex Angas
    Commented Jul 28, 2011 at 0:02

2 Answers 2

4

This can be done, but you need to use one Content Type for each template needed. Create a new content type. Give it whatever name you would like, but set dropdown properties as defined. Would suggest to define a group name for these content types (I used Test Type with Template).

Content Type Create Properties

Next go to the Advanced Settings for this new content type. This is where you define the template to use for this new content type.

Advanced Settings

Repeat these steps for the other document templates needed.

Go to the document library where you want to launch and store these documents. I am choosing the Shared DL for this example. Go to the settings for this DL and choose Advanced Settings. The first option is to Manage Content Types. Change it to Yes and click OK.

Advanced DL Settings

Content Types area is now visible on the settings page. Click the Add from Existing Content Type link. If you defined a content group, you can filter the list using this group and get right to your content type. Otherwise, leave the all groups item in the dropdown and find your content type in the pick list. Add it and then hit OK. Add Content Type

Repeat this for the other content types. You can also remove the default document template.

Now when you choose the down arrow under the New Document icon, all of your content types will be listed. If you click the new document button, the default content type will be used to create a new document.

New Document

This solution is completely out of the box. There is a video here that describes the process in 2007. The same features are there in 2010 as well.

6
  • Thanks, I am working with a similar library. However, I got the impression that when I select the new template from the drop-down menu in the last picture and the template opens in Word, I would be able to make some changes, click Save and the new document would be saved straight back to the document library. However, on my machine Word only gives me the option to save the file locally. Isn't Sharepoint/Office supposed to save the file to the document library? Do you have any idea what's going on here? Commented Jul 28, 2011 at 11:06
  • This depends on your version of office. I have office 2010 and I can save documents back into my SP site. What version are you using?
    – Rich Ross
    Commented Jul 28, 2011 at 11:14
  • I am using Office 2010. I can save documents to document libraries in other situations, and I can do it in this instance as well...but I have to enter the URL of the doclib manually. I was under the impression that it would be entered automatically. Could it be some obscure setting that needs to be changed? Commented Jul 28, 2011 at 11:18
  • How about the specific product since there are differences between standard and pro? I am using Office 2010 Professional Plus according to the Help menu.
    – Rich Ross
    Commented Jul 28, 2011 at 11:32
  • Microsoft Office Professional Plus 2010 also, Version 14.0.5128.5000 (64-bit). It does work the way I describe it on your setup, right? Maybe I'll open a question. Commented Jul 28, 2011 at 11:36
2

Now to do the same thing with code. I am taking from your question, that you can create the custom content type in code. Just in case, here are links to two options, one through code and using the list definition. I am also going to guess that you need to deploy this using a feature, which is why you need to use visual studio.

The code option makes the most sense since we need to add the template. We can do this in the FeatureActivated method of you feature receiver. Once you have created your code in the feature, we need to set the properties.

There is a property for the Document Template and Document Template Url on the content type. As you can see from the documentation, they need to contain the filename and url of the document template. You will need to upload the document templates to the same document library and use those values for the properties. They can be uploaded manually or included in your project and placed there when the feature is activated, but they should go in the Forms folder on the DL.

Final step in code is assign this content type to the list. Here is a method from one of my projects that does this.

    private static void AddContentTypeToList(SPWeb web, string listName, string contentTypeName)
    {
        try
        {
            SPList taskList = web.Lists[listName];
            taskList.ContentTypes.Add(web.AvailableContentTypes[contentTypeName]);
            taskList.ContentTypesEnabled = true;
            taskList.Update();
        }
        catch (Exception ex)
        {
            throw;
        }
    }

Please reply back with any questions. Welcome to the world of SharePoint!

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.