Share via


SPViewFieldCollection.ToStringCollection method

Loads the names of the view fields into a StringCollection object.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Function ToStringCollection As StringCollection
'Usage
Dim instance As SPViewFieldCollection
Dim returnValue As StringCollection

returnValue = instance.ToStringCollection()
public StringCollection ToStringCollection()

Return value

Type: System.Collections.Specialized.StringCollection
A System.Collections.Specialized.StringCollection object that contains the names of the view fields.

Examples

The following code example loads the view fields of a list view into a StringCollection object and iterates through the collection to display the name of each field.

This example requires a using directive (Imports in Visual Basic) for the Microsoft.SharePoint namespace.

Dim oSiteCollection As SPSite =  New SPSite("Absolute_URL") 
Using oWebsite As SPWeb = oSiteCollection.AllWebs("Website_Name"))

    Dim oList As SPList =  oWebsite.Lists("List_Name") 
    Dim oView As SPView =  oList.Views("View_Name") 
    System.Collections.Specialized.StringCollection collStrings =
    oView.ViewFields.ToStringCollection()
 
    Dim i As Integer
    For  i = 0 To  collStrings.Count- 1  Step  i + 1
        Console.WriteLine(collStrings(i))
    Next

End Using
SPSite oSiteCollection = new SPSite("Absolute_URL");
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];
    System.Collections.Specialized.StringCollection collStrings =
    oView.ViewFields.ToStringCollection();

    for (int i = 0; i < collStrings.Count; i++)
    {
        Console.WriteLine(collStrings[i]);
    }
}

See also

Reference

SPViewFieldCollection class

SPViewFieldCollection members

Microsoft.SharePoint namespace