Showing posts with label SharePoint Fields. Show all posts
Showing posts with label SharePoint Fields. Show all posts

Thursday, September 22, 2011

Iterating against Multiline Field

We all know how to iterate on single line of text field in SharePoint.But its a bit tricky when it comes to Multiline Text field.I think its more hassle than Lockup column.
Here is how we get the data from the Field.
SPListItemCollection itemCol = List.GetItems(query);
 SPListItem item = itemCol[i];
SPFieldMultiLineText myField =item.Fields.GetField("fieldName") as SPFieldMultiLineText;
string myString=myField.GetFieldValueAsText(item["fieldName"]);

Even though the string gets with \r\n in order to diplay on console here is how to code
string temp = item["myField"].ToString();
string[] fieldValue = temp.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
The above method helps in removing the \r and \n present.
If you are show on web .use a textbox and set the textmode property to "multiline".This will automatically display in same format present as in SharePoint List.
Ex:<asp:TextBox ID="txtField" runat="server" TextMode="MultiLine"></asp:TextBox>
txtField.Text=myField.GetFieldValueAsText(item["fieldName"]);

Thursday, June 23, 2011

Verify if a Field Exist in MOSS 2007

I had a scenario where I have to iterate the same List name in a Site Collection but different sub sites.
Interesting fact is the list has different Fields.
Even though we don't have a method to verify if a list exist but there is one to check if a Field exist in SharePoint List/Document Library.

 SPList list = site.Lists["Your List Name"];
list.Fields.ContainsField("Yout Field Name")