What is "Publishing Image" content type?
"Publishing Image" is a content type which will bind the image with all its properties and will show it on the screen with those properties applied. The properties like height width etc.What my task was?
My task was to add a "Publishing Image" content type with Display Name as "Rollup Image" in the content type list "Post". This was a site level feature, once i activate this feature all the blog type site with SharePoint List "Post" will have an extra field "Rollup Image". Please have a look at the 2 pictures which can give you a clear idea.The 1st from the above one is new post screen. and the 2nd one comes when you click to add a new image reference.
Solution
- Open a visual studio 2010
- Add new project
- Empty Sharepoint Project > Deploy as Farm Solution > Finish.
- In the visual studio solution project select "Features > Feature1 > Feature1.feature".
- Right click "Add event receiver".
- I used this code to achieve it.
/// <summary> /// Add a field name "Rollup Image" to a content type "Post". /// "Post" is the content type used in the Site Template blog. /// </summary> /// <param name="properties"></param> public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate { using (SPWeb _web = ((SPSite)properties.Feature.Parent).RootWeb) { //Post is the content type list which is on the blogs. SPContentType _contentType = _web.ContentTypes["Post"]; if (_contentType != null) { //PublishingRollupImage is the static name for the "Publishing Image " if (!_contentType.Fields.ContainsFieldWithStaticName("PublishingRollupImage")) { //Name of the column to be added to the list content type post SPField _field = _web.AvailableFields["Rollup Image"]; SPFieldLink _fieldText = new SPFieldLink(_field); if (_contentType.FieldLinks[_fieldText.Id] == null) { _contentType.FieldLinks.Add(_fieldText); } _contentType.Update(true); } } } }); }
- Deploy the solution.
How to verify this?
- Open the Sharepoint Site.
- Site Actions > Site Settings > Site Content Types
- Click "Post" in "List Content Type".
- You can see the newly added column in the image below. For checking the above 2 images you should go to the "Post" sharepoint list in the blog site.
Please feel free to ask question, I will be more glad to answer your question.