Do’s and Don’ts of SharePoint Development

Leave a comment

A very good blog post on Do’s and Don’ts of SharePoint development…..

http://weblogs.asp.net/bsimser/archive/2011/01/12/do-s-and-don-ts-building-sharepoint-applications.aspx

Getting Field Display name from SPView viewFields collection

Leave a comment

The Sharepoint SPView ViewCollection returns Only Internal Names and if you want to show Display Name that ugly Display_X0020_Name, you can use below mentioned code Snippet.

string str = SPContext.Current.Web.Url;
using (SPSite site = new SPSite(str))
{
using (SPWeb sweb = site.OpenWeb())
{
SPList slist = sweb.Lists.TryGetList(“IdeaTest”);
SPView view = slist.DefaultView;
foreach (string field in view.ViewFields)
{
DataRow dr = listFields.NewRow();
dr[0] = slist.Fields.GetFieldByInternalName(field).Title; //Display Field Title for given Internal name
dr[1] = field;
listFields.Rows.Add(dr);
}
}
}
The Line slist.Fields.GetFieldByInternalName(field).Title; Does the trick to return Title (Display name) for given Internal name.

Happy Coding…

Encode and Decode SharePoint Internal Names

1 Comment

If you’re a SharePoint Developer, you’re bound to face the encoding issue while fetching SharePoint data.
Annual Savings gets encoded to : Annual _x0020_ Savings
So what’s the _x0020_ number about? Actually, hex 20 is the UTF value for a space, and x0020represents that space. Underscores are probably delimiters.
The possible reason for this escaping is that XML element names can’t have a space.

To encode or decode this You can use:
• To encode System.XML.XmlConvert.EncodeName()
• To decode System.XML.XmlConvert.DecodeName()