共用方式為


SPViewStyle class

代表檢視的樣式。

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPViewStyle

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

Syntax

'宣告
Public Class SPViewStyle
'用途
Dim instance As SPViewStyle
public class SPViewStyle

備註

在\\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL\XML\VWSTYLES.XML中定義檢視樣式。

使用SPWeb類別之ViewStyles屬性可傳回站台的檢視樣式的集合。若要從集合中傳回單一檢視樣式使用索引器。例如,若集合已指派給變數collViewStyles,使用collViewStyles[index]以 C# 或 Visual Basic,其中index是索引編號集合中的檢視樣式中的collViewStyles(index) 。

Examples

下列程式碼範例會逐一查看的檢視樣式為網站集合,並顯示的檢視欄位的樣式名稱和欄位名稱。

這個範例需要Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間using指示詞 (在 Visual Basic 中的Imports )。

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim vwStyles As SPViewStyleCollection = site.ViewStyles
Dim vwStyle As SPViewStyle

For Each vwStyle In  vwStyles

    Dim vwFieldCollection As SPViewFieldCollection = vwStyle.ViewFields

    If Not (vwFieldCollection Is Nothing) Then

        Dim vwFieldNames 
            As System.Collections.Specialized.StringCollection = 
            vwFieldCollection.ToStringCollection()
        Dim i As Integer

        For i = 0 To vwFieldNames.Count - 1

            Response.Write(SPEncode.HtmlEncode(vwStyle.Title) & 
                " :: " & SPEncode.HtmlEncode(vwFieldNames(i)) & "<BR>")

        Next i

    End If

Next vwStyle
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPViewStyleCollection collViewStyles = oWebsite.ViewStyles;

    foreach (SPViewStyle oViewStyle in collViewStyles)
    {
        SPViewFieldCollection collViewFields = oViewStyle.ViewFields;

        if (collViewFields != null)
        {
            System.Collections.Specialized.StringCollection collFieldNames = collViewFields.ToStringCollection();

            for (int i=0; i<collFieldNames.Count; i++)
            {
                Response.Write(SPEncode.HtmlEncode(oViewStyle.Title) + 
                " :: " + SPEncode.HtmlEncode(collFieldNames[i]) + 
                "<BR>");
            }
        }
    }
}
注意事項注意事項

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

請參閱

參照

SPViewStyle members

Microsoft.SharePoint namespace