Getting Custom Columns from SharePoint list

Getting Custom Columns from SharePoint list

Dim sReturnValue As String = Nothing
    Dim sReturnValuec As String = Nothing
    Dim listService As New WssListsSvc.Lists()
    Dim m_credentials  As ICredentials = New Net.NetworkCredential(UserId, Pwd, Domain)
    listService.Credentials = m_credentials
    Dim result As XmlNode = listService.GetList(sLibName)
    For Each ndField As XmlNode In result.FirstChild.ChildNodes
        Dim IsReadOnly As String = String.Empty
        Dim name As String = String.Empty
        If ndField.Attributes("ReadOnly") IsNot Nothing Then
           IsReadOnly = DirectCast(ndField.Attributes("ReadOnly").Value, String)
        End If
        If Not IsReadOnly = "TRUE" Then
            If ndField.Attributes("DisplayName") IsNot Nothing Then
                 name = DirectCast(ndField.Attributes("DisplayName").Value, String)
            End If                        If sTagType.ToLower = "custom" Then
                 Dim SourceID = DirectCast(ndField.Attributes("SourceID").Value, String)
                 If SourceID.Contains("sharepoint") = False Then
                     sReturnValue = name & "," & sReturnValue
                 End If
            Else                                    sReturnValue = name & "," & sReturnValue                          End If
        End If
    Next
Return sReturnValue

C# Version


string sReturnValue = null;
string sReturnValuec = null;
WssListsSvc.Lists listService = new WssListsSvc.Lists();
ICredentials m_credentials = new System.Net.NetworkCredential(UserId, Pwd, Domain);
listService.Credentials = m_credentials;
XmlNode result = listService.GetList(sLibName);
foreach (XmlNode ndField in result.FirstChild.ChildNodes) {
 string IsReadOnly = string.Empty;
 string name = string.Empty;
 if (ndField.Attributes("ReadOnly") != null) {
  IsReadOnly = (string)ndField.Attributes("ReadOnly").Value;
 }
 if (!(IsReadOnly == "TRUE")) {
  if (ndField.Attributes("DisplayName") != null) {
   name = (string)ndField.Attributes("DisplayName").Value;
  }
  if (sTagType.ToLower == "custom") {
   dynamic SourceID = (string)ndField.Attributes("SourceID").Value;
   if (SourceID.Contains("sharepoint") == false) {
    sReturnValue = name + "," + sReturnValue;
   }
  } else {
   sReturnValue = name + "," + sReturnValue;
  }
 }
}

Notes :
1.: UserId, Pwd, Domain, sTagType, sLibName are string variables used in the function.
2.: sTagType Contains the values “All” or “Custom”. If all is passed then all the
columns are retrieved and if custom is selected then Custom Columns Comma separated
list is returned.


Search This Blog

Link Within Related Posts Plugin for WordPress, Blogger...