This topic has not yet been rated - Rate this topic

VersionDiff Class

Provides the version difference when given a field with Versioning enabled. It displays the changes between two versions.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class VersionDiff : FormComponent
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
VersionDiff
Description 

The Microsoft.SharePoint.WebControls.VersionDiff class inherits from the Microsoft.SharePoint.WebControls.FormComponent class which is the base class for form-rendering and field-rendering controls. VersionDiff provides a complete HTML differential between publishing pages outputting changes, highlighting the publishing text that have been deleted, added, or changed. The most evident place that VersionDiff is used is for the default SharePoint Wiki functionality as part of the default interface. 

VersionDiff obtain most of the heavy lifting through the static SPDiffUtility.Diff method which takes three parameters: the original string, the changed string, and a 32-bit integer specifying the limit of changes to find. The string that the method returns is robust, providing a differential output highlighting changes. The highlights contain the applicable HTML tags for deleted, added, or changed actions. As it is a solitary string that is returned, the output represents a merged version of string parameters. This return is subsequently used in order to provide the literal HTML string to render to the output stream. 

Usage Scenario

VersionDiff is primarily used internally in order to support the differential elements (VersionDiffIterator) that are provided through the use of the Wiki functionality. Since it is an orthodox control however, it is possible to add it to an instance control collection if desired.

Below I am demonstrating instantiating a new VersionDiff object and specifying the one public property, VersionDiff.FieldName to a literal string representing a field name. After the object is hydrated, it is subsequently added to the current instance control collection.

C# Code Example

public class ExampleWebPart : WebPart
{
protected override void CreateChildControls()
{
VersionDiff diff = new VersionDiff();
diff.FieldName = "My Field Name";
Controls.Add(diff);
}
}

Visual Basic .NET Code Example

Public Class ExampleWebPart
Inherits WebPart
Protected Overloads Overrides Sub CreateChildControls()
Dim diff As New VersionDiff()
diff.FieldName = "My Field Name"
Controls.Add(diff)
End Sub
End Class

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com