Export (0) Print
Expand All

SPDocDiscussionCollection Class

NOTE: This API is now obsolete.

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

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

[ObsoleteAttribute("SPDocDiscussionCollection is deprecated", false)]
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);
        }
    }
    oWebsite.Dispose();
}
NoteNote

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.

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