In SharePoint 2010, when using SharePoint list and column type "multiple line of text" with Enhanced Rich Text option (which allows inserting images, html code etc.), how can I enable to allow inserting one or more SharePoint Web parts ?
I think a better approach is to Create Custom List Column Type that can work as per your business logic. If you still need to use rich text column, please continue reading... :-)
Traditional Webparts are actually server side controls which are processed by SharePoint(actually ASP.NET) runtime and the corresponding HTML markup is generated and embedded in the requested Page.This HTML is then processed by browser and the webpart is displayed to user.
Now, If you can manage to get the HTML of the webpart (copy from view source) and insert into the rich text column, it will work.However, it will be static - which may not serve the purpose
To have dynamic HTML, you can try using the client side techniques ( instead of server side, like webpart).Below are some ways:
<span id="Message"></span>in the rich text list column and dynamically feed the html response you get via callback.
Jquery\WebServices : You can code your own webservice and call it via Jquery to get the HTML response or use SPServices library.
To make above methods working, you will need to insert scripts outside the rich text list column, because the OOTB list column don't allow to insert scripts(for security purpose). To have them inside,you can create a custom rich text column to allow scripts
You can't insert a Web Part into a SharePoint list. SharePoint does not work that way. You add SharePoint Web Parts to a Web Part Page.
I don't think that it is possible to put web part into rich text field. Maybe you can tell us more about what you need to do and we can advice you alternative way?
By default enhance rich text's features like (html,image etc) are totally different from webparts. For any SharePoint field there are 4 areas considered main in terms of interaction with user:
- Add/Remove area for that field (in List settings)
- List Item Add/Edit form
- List Item Display form
- List views
Even if some way you are able to insert webparts in rich text.. your list item display form and list view will create big mess on screen.
Adding webpart on rich text means you want to do some business function .. to show processed data .. another way are you seeking for KPI or some sort of calculated fields ?
Unless you can clarify the usage , what you want to achieve by inserting webpart in rich text no one can help you more.
Here are my two cents. Before we start though, know that I would avoid with all my strength to actually have to code what I will describe. I fear that this awake Cthulhu from his sleep in the sunken city of R'lyeh.
Anyway you could try to start from a custom field type, as Amit Kumawat suggested here. I would avoid trying to generate the webpart html and store it in the field though. What I would do is saving the web part export data in the field: that would be a string - so there shouldn't be any problem.
You would then need to have the web part rendering on the page. I believe that you could do that by abusing the rendering control for your custom field type. Have it return render a web part instance when in view mode (notice: that could be hard but you should be able to, creating the instance from the template isn't hard). In edit mode... you could try to render the web part tool part? again you should be able to get it from the web part instance - but then you would need some way to save the modified properties to the backing field.
Also worth a notice would be that your "field" would basically break almost any standard out of the box view inside SharePoint: just think the view item form with a web part inside it. And I'm not even considering other problems: connections, relative urls, web part that interact with data and so on.
Again, I would try to avoid this. If I may give you an advice, I would try to question the needs for a similar solution. Is this a customer request? Are you sure that your customer is describing what he need and not what he believe to need?
Note: leave a comment here if you need some more info. Also, feel free to add some more details on why you
must have to do this.