Tag: Content Type

Programmatically Add Excel Word Access Content Types SharePoint 2010

Create new project using visual studio “Empty SharePoint Project” template, and then select sandbox solution, and then add new web part, now we call below function to create new Content Template with particular document and add some site column, then its add one document library.

        private void ContentTypeAdder()
        {
            using (SPSite site = new SPSite(“http://win7”))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    SPContentType contentType = new SPContentType(web.ContentTypes[“Document”], web.ContentTypes, “SPTECHNET Time Sheet”);
                    web.ContentTypes.Add(contentType);
                    contentType.Group = “SPTECHNET Content Types”;
                    contentType.Description = “Demo content type”;
                    contentType.FieldLinks.Add(new SPFieldLink(web.Fields.GetField(“Address”)));
                    contentType.FieldLinks.Add(new SPFieldLink(web.Fields.GetField(“Office”)));
                    contentType.DocumentTemplate = “http://win7/Shared Documents/Test Dummy.docx”;
                    contentType.Update();
                    
                    SPList list = web.Lists[“Shared Documents”];
                    list.ContentTypesEnabled=true;
                    list.ContentTypes.Add(contentType);
                    list.Update();
                    web.AllowUnsafeUpdates = false;
                }
            }
        }

Image

Add Excel Word Access Content Types SharePoint 2010

Step 1:

Navigate Site Actions–>Site Settings –>under Galleries–>Click Site Content Types and then click Create Button.

Site Content Types

Step 2:

In the Select parent content type from list, select Document Set Content Types and then click OK.

Create New

Step 3:

On the Site Content type Advanced Settings page, select Upload a new document template, and then click Browse to browse to and select the document template you want to assign to the site content type. A document template choose can be any file such as an Excel spreadsheet, a Word document or template, a PowerPoint slide presentation, etc.And then click OK.

dvaced Setting

upload template

Step 4:

In the Document Library Setting dialog under General Settings, click Advanced Settings.In the Content Types section, click Yes for Allow management of content types and then click OK.

Choose Yes

Step 4:

Back in the Document Library Setting dialog under Content Types, click Add from existing site content types.In the Available Site Content Types list, select your content type and then click Add.

Advanced Settings

Select List

Step 5:

Now we can see the new content type on the New Document menu.

New File Sharepoint 2010