Share via


SPDocDiscussionCollection Class

NOTE: This API is now obsolete.

Represents the collection of SPDocDiscussion objects associated with documents in a specific document library.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPDocDiscussionCollection

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<ObsoleteAttribute("SPDocDiscussionCollection is deprecated", False)> _
Public Class SPDocDiscussionCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPDocDiscussionCollection
[ObsoleteAttribute("SPDocDiscussionCollection is deprecated", false)]
public class SPDocDiscussionCollection : SPBaseCollection

Remarks

Use the GetDocDiscussions method of the SPWeb class to return all the document discussions for a specified folder in a site.

Examples

The following code example iterates through the Shared Documents folders of every site in the current site collection and, if the number of comments made in discussions of a document exceeds 10, copies the document into a subfolder within the document library. If the subfolder does not exist, the example creates it.

Dim siteCollection As SPSite = SPContext.Current.Site
Dim sites As SPWebCollection = siteCollection.AllWebs
Dim site As SPWeb

For Each site In  sites

    Dim discs As SPDocDiscussionCollection 
        = site.GetDocDiscussions("Shared Documents")
    Dim disc As SPDocDiscussion

    For Each disc In  discs

        If disc.CommentCount > 10 Then

            Dim files As SPFileCollection 
                = site.Folders("Shared Documents").Files
            Dim subFolders As SPFolderCollection 
                = site.Folders("Shared Documents").SubFolders

            Dim subFolder As SPFolder 
                = site.GetFolder("Shared Documents/Discussed")

            If Not subFolder.Exists Then

                subFolder = subFolders.Add
                    ("Shared Documents/Discussed")

            End If

            Dim urlString As String = disc.DocUrl.ToString()
            Dim index As Integer = urlString.LastIndexOf("/")
            Dim newUrl As String = urlString.Substring(index)

            files(urlString).CopyTo(subFolder.Url + newUrl)

        End If

    Next disc

Next site 
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;

foreach (SPWeb oWebsite in collWebsites)
{
    SPDocDiscussionCollection collDocDiscussions = oWebsite.GetDocDiscussions("Shared Documents");

    foreach (SPDocDiscussion oDocDiscussion in collDocDiscussions)
    {
        if (oDocDiscussion.CommentCount > 10)
        {
            SPFileCollection collFiles = oWebsite.Folders["Shared Documents"].Files;
            SPFolderCollection collFolders = oWebsite.Folders["Shared Documents"].SubFolders;

            SPFolder oFolder = oWebsite.GetFolder("Shared Documents/Discussed");

            if (!oFolder.Exists)
            {
                oFolder = collFolders.Add("Shared Documents/Discussed");
            }

            string strUrl = oDocDiscussion.DocUrl.ToString();
            int intIndex = strUrl.LastIndexOf("/");
            string strNewUrl = strUrl.Substring(intIndex);

            collFiles[strUrl].CopyTo(oFolder.Url + strNewUrl);
        }
    }
    oWebsite.Dispose();
}

Note

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.

See Also

Reference

SPDocDiscussionCollection Members

Microsoft.SharePoint Namespace