1

In my SharePoint list I have address column with comma values.

For example Address1,Address2,Address3. When I was retrieving the value from list only I can get the address1 value.

But address column I have these 3 values Address1,Address2,Address3. How to retrieve these 3 values with comma?

    string AddressLine1 = Convert.ToString(dr["Address Line 1"])
string AddressLine2 = Convert.ToString(dr["Address Line 2"]);
string AddressLine3 = Convert.ToString(dr["Address Line 3"]);
string AddressLine4 = Convert.ToString(dr["Address Line 4"]);
Address = AddressLine1;
  if (!string.IsNullOrEmpty(AddressLine2))
 {
  Address = AddressLine1 + ',' + AddressLine2;
  }
if (!string.IsNullOrEmpty(AddressLine3))
 {
   Address = Address + ',' + AddressLine3;
 }
 if (!string.IsNullOrEmpty(AddressLine4))
  {
 Address = Address + ',' + AddressLine4;
 }
    string Value = Convert.ToString(oItems["Address"]);
    if (Value != Address)
    {
        if(!htvalues.Contains("Address"))
            htvalues.Add("Address", Address);
    }

Value contains only address1. I want to store Address1, Address2, Address3 values in string.

enter image description here

When I was retrieving the values I got (155 GAITHER DRIVE) before comma value.

Below image when I was editing the value it contains all values. enter image description here

  • What is the Data Type of the Coloumn – Esaki Dec 14 '16 at 6:53
  • Multiple lines of text – Elina Dec 14 '16 at 6:54
  • I tried like this. var AddressField = olist.Fields.GetFieldByInternalName("Address"); var CAddress = oItems[AddressField.Id]; var AddressasText = AddressField.GetFieldValueAsText(CAddress); AddressasText contains only address1. – Elina Dec 14 '16 at 6:56
  • can you paste what actual value your address column is holding when do see edit item ? – Siddharth Vaghasia Dec 14 '16 at 7:01
  • Is Address your custom field? IS it plain text or Rich text? – Viraj Gorajia Dec 14 '16 at 7:09
1

Put .= for assigning the addressline2, addressline3 and addressline4 concatenated with ,

Right now, in your code addressline1 value is overwriting to Address in all the conditions as you have missed the .

Update the lines in if conditions of your code as below

Address .= Address + ',' + AddressLine2;
Address .= Address + ',' + AddressLine3;
Address .= Address + ',' + AddressLine4;

This will work and output all the address lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.