Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

SPDocDiscussionCollection Class

Windows SharePoint Services 3

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

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

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPDocDiscussionCollection : SPBaseCollection

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

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.

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);

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 Best Practices: Using Disposable Windows SharePoint Services Objects.

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

Community Additions

© 2015 Microsoft