Friday, August 14, 2015

How To Convert HTML To Formatted Plain Text

Simple removing of HTML tags with Regex.Replace method

Sometimes you want to remove tags from HTML and get only plain text. In general, this is simple task but there are few drawbacks in some scenarios. The simplest solution is to just remove all tags from given HTML without any formatting.

using System.Text.RegularExpressions;

// Below code is used for .NET sites
private string StripHtml(string source)
        string output;

  // Replace &lt; with < symblol and &gt; with > symblol
        source = source.Replace("&lt;", "<").Replace("&gt;", ">");

        //get rid of HTML tags
        output = Regex.Replace(source, "<[^>]*>", string.Empty);
  output = Regex.Replace(output, "&nbsp;", "");

  //get rid of multiple blank lines
        output = Regex.Replace(output, @"^\s*$\n", string.Empty, RegexOptions.Multiline);
        return output;

// Below code is used for SharePoint sites
private string StripHtml(string str)

        str = Regex.Replace(str, "&lt;", "<");
        str = Regex.Replace(str, "&gt;", ">");
        str= SPHttpUtility.ConvertSimpleHtmlToText(str, -1);
        str= Regex.Replace(str, "&nbsp;", "");
        str = Regex.Replace(str, @"^\s*$\n", string.Empty, RegexOptions.Multiline);
       return  str;                 

Tuesday, June 21, 2011

SharePoint Interview Queations.

TCS :--

1) How do you display Dropdown list in WerPart Property pane?

Example : Dropdown Filter Web Part in SharePoint

2) How you can use Workflow tokens in VS Workflow?

3) Question on Form topology?

4) Questions on SDLC?

Displaying custom properties in the property Pane

Displaying custom properties in the property Pane

After you've imported your sample Web Part into a Web Part Page, you can display the property pane to view or change their values. A custom property will be displayed automatically in the default property pane if the property is of type string, bool, int or enum. The following table describes how each of these property types is displayed in the property pane.

Property Type-------- Displayed in property pane as

bool--------> Check box
DateTime --------> Text box
enum --------> Dropdown
int --------> Text box
string --------> Text box

To display or change the values of custom properties  

  • On the Web Part menu, click Modify This Web Part.

  • Expand the Custom Properties section of the property pane.

Friday, December 24, 2010



Thursday, December 23, 2010

Using Javascript code to show/hide controls in NewForm or EditForm.

You can use the following javascript code to show/ hide controls in NewForm or EditForm.

< script type="text/javascript" >


function hideFieldsOnStart() {

//hide the control at startvar control = getTagFromIdentifierAndTitle("input","TextField","FieldDisplayName");"none";

//add an onchange event to the dropdown
getTagFromIdentifierAndTitle("select","DropDownChoice","DropDownDisplayName").onchange = function() {ChangeEvent()};


function ChangeEvent()

//get the dropdownvar dropdown = getTagFromIdentifierAndTitle("select","DropDownChoice","DropDownDisplayName");

//get the selected valuevar option = dropDown.options[dropDown.selectedIndex].text;

//get the controlvar control = getTagFromIdentifierAndTitle("input","TextField","FieldDisplayName");

//show hide based on your conditionif(option == "xyz")

//this gets the field based on title identifier and tagnamefunction getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
</script >

List of sharepoint column types and their corresponding identifiers, tagnames and Title

SharePoint Field Type Identifier Tag Name Title
Single Line of Text TextField input Same as Field Title
Multiple Lines of Text TextField input Same as Field Title
Number TextField input Same as Field Title
Currency TextField input Same as Field Title
Choice (dropdown) DropDownChoice select Same as Field Title
Lookup (single)* Lookup select Same as Field Title
Lookup (multiple) SelectCandidate; SelectResult select Same as Field Title
Yes/No BooleanField input Same as Field Title
People or Group UserField_downlevelTextBox textarea People Picker

(It must be

People Picker only. Irrespective of Filed name)

It depends what type of field you are trying hide it is in your case
if text field it should be
var control = getTagFromIdentifierAndTitle("input","TextField","FieldDisplayName");

if choice

var control = getTagFromIdentifierAndTitle("select","DropDownChoice","FieldDisplayName");

if yes/no then

var control = getTagFromIdentifierAndTitle("input","BooleanField","FieldDisplayName");

if Lookup then

var control = getTagFromIdentifierAndTitle("select","Lookup","FieldDisplayName");

If it is People Picker

var control = getTagFromIdentifierAndTitle('textarea','UserField_downlevelTextBox','People Picker');

Adding Context Menu in SharePoint List or Library using Content Editor Web part

< script type="text/javascript">
function Custom_AddListMenuItems(m, ctx) {
CAMOpt(m,'Edit Form(new window)','\'EditForm.aspx?ID=' + currentItemID + '\');','/_layouts/images/LIST.GIF');
// false means that the standard menu items should also be rendered
// if you set true, it will show only the menu which you added( standard sharepoint menu items will not be available.
// you can control by setting the value of true or false
return true;

If the above function returns false, then the context menu is displayed as below.

If the above function returns true, then the context menu is displayed as below.

Similary if you want to do for List, you have to use the Different method name.

For Document Library : Instead "Custom_AddDocLibMenuItems"

For List : "Custom_AddListMenuItems"

Also you can do following using Script in Content Editor Webpart

To hide the "Delete" (particular) menu item in LibraryContext Menu add this below function

function CAMOpt(p,wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc);
if(!mo)return null;
//wzText you can give which one you want hide (like "Edit Properties")
if(wzText != "Delete") AChld(p,mo);
return mo;

You can download the script and add it in your content editor webpart; it will take care of the previous actions for document Library.

Use the approriate Script for list / library.

Using javascript to hide People Picker SharePoint field based on DropDown value

< script type="text/javascript">


function hidePeoplePicker() {
var control = getTagFromIdentifierAndTitle('textarea','UserField_downlevelTextBox','People Picker');"none";

//This code runs on the onchange event of the drop down list field
getField('select','Form Type').onchange = function() {getSecurityLevelValue()};


function showPeoplePicker() {
var control = getTagFromIdentifierAndTitle('textarea','UserField_downlevelTextBox','People Picker');"";


function getTagFromIdentifierAndTitle(tagName, identifier, title) {

//alert("tagName = " + tagName);

var len = identifier.length;
//alert("Len = " + len);

var tags = document.getElementsByTagName(tagName);
//alert("tags length = " + tags.length);

for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
var tt = tempString.indexOf(identifier);
var ss = tempString.length - len;
if(tags[i].title == "People Picker")
//alert("tempString = " + tt +"---"+ss );
if (tags[i].title == title && (identifier == "" ||
tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
return null;

function getField(fieldType,fieldTitle) {

var docTags = document.getElementsByTagName(fieldType);

//alert("Length = " + docTags.length);

for (var i=0; i < docTags.length; i++) {

if (docTags[i].title == fieldTitle) {

//alert("Value in getField = " + docTags[i].value);

return docTags[i];




function getSecurityLevelValue() {

//alert("In getSecurityLevelValue");
selectedId = getField('select','Form Type').options[getField('select','Form Type').selectedIndex].value;

//alert("Value in hide =" + selectedId);

if(selectedId != 'Org change/ cost centre change')


//alert("NOT Specific Request Hide");





//alert("Request Show");





1) If you have more than one People Picker either in edit form or new form, in that case hidden field should be displayed first and then non hidden people picker in that form. It is done by changing Column order.