5

I have created a custom list in visual studio 2013 for sharepoint 2013. Is it possible to enable versioning for this list in visual studio itself? Or Do we need to do it via UI only in sharepoint ?

6

you can do it through code:

as an example:

SPList list = web.Lists["My List"];
list.EnableVersioning = true;

so the above can be simply added to your code when your creating the list:

somthing on the lines of:

//get web object from context
SPWeb web = SPContext.Current.Web;
//get list collection
SPListCollection lists = Web.Lists;
//add list to list collection
lists.Add("My List", "My list for user input form", SPListTemplateType.GenericList);
//call list that we just made
SPList newMyList = Web.Lists["My List"];
//enable versioning on that list
newMyList.EnableVersioning = true;

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.enableversioning.aspx

EDIT

i get you! when adding the list using vs2012 you can go into the xml of the list (Elements.xml ):

<ListInstance 
  CustomSchema = string
  Description = "Text"
  DocumentTemplate = integer
  FeatureId = "Text"
  Hidden = "TRUE" | "FALSE"
  HyperlinkBaseUrl = string
  Id = Text
  OnQuickLaunch = "TRUE" | "FALSE"
  QuickLaunchUrl = "Text"
  RootWebOnly = "TRUE" | "FALSE"
  TemplateType = Integer
  Title = "Text"
  Url = "Text"
  VersioningEnabled = "TRUE" | "FALSE"
</ListInstance>

the above is appended within the list elements.xml as you can see within ListInstance you have VersioningEnabled, just add that like so: VersioningEnabled = true and versioning is enabled to that custom list.

for major and minor versions that is the same concept here again:

http://msdn.microsoft.com/en-us/library/office/ms415091.aspx

<List
  BaseType = "Integer" | "Text"
  Default = "TRUE" | "FALSE"
  DefaultItemOpen = "Integer"
  Description = "Text"
  Direction = "Text"
  DisableAttachments = "TRUE" | "FALSE"
  DraftVersionVisibility = "Integer"
  EnableContentTypes = "TRUE" | "FALSE"  EnableMinorVersions = "TRUE" | "FALSE"  EnableThumbnails = "TRUE" | "FALSE"
  EventSinkAssembly = "Text"
  EventSinkClass = "Text"
  EventSinkData = "Text"
  FolderCreation = "TRUE" | "FALSE"
  Id = "GUID"
  ModeratedList = "TRUE" | "FALSE"
  ModerationType = "TRUE" | "FALSE"
  Name = "Text"
  OrderedList = "TRUE" | "FALSE"
  PrivateList = "TRUE" | "FALSE"
  QuickLaunchUrl = "URL"
  RootWebOnly = "TRUE" | "FALSE"
  ThumbnailSize = "Integer"
  Title = "Text"
  Type = "Integer"
  Url = "URL"
  URLEncode = "TRUE" | "FALSE"
  VersioningEnabled = "TRUE" | "FALSE" 
  WebImageHeight = "Integer"
  WebImageWidth = "Integer">
</List>

you append the above within the schema.xml that belongs to the list with the elements.xml

http://msdn.microsoft.com/en-us/library/office/ms459356.aspx

3
  • Thanks for your reply. Actually, I was trying to add a list via visual studio. No webpart is used. So is it possible to do a coding inside this ? – Anish V Nov 27 '13 at 10:05
  • just ammended my answer – Ali Jafer Nov 27 '13 at 11:10
  • just updated answer again ;) – Ali Jafer Nov 27 '13 at 11:46
5

In the schema you can add

How does versioning work in a list or library

VersioningEnabled="TRUE"
EnableMinorVersions="TRUE"
MajorVersionLimit="5"
MajorWithMinorVersionsLimit="2"

For example

<List xmlns:ows="Microsoft SharePoint"
            Title="Title here"
            VersioningEnabled="TRUE"
            EnableMinorVersions="TRUE"
            MajorVersionLimit="5"
            MajorWithMinorVersionsLimit="2"
            Direction="$Resources:Direction;"
            Url="url here"
            BaseType="1"
            xmlns="http://schemas.microsoft.com/sharepoint/"
            EnableContentTypes="TRUE">
3
  • What is the difference between these two tags ? I want to change the versions if somebody changes the contents of the list. – Anish V Nov 27 '13 at 6:55
  • added a link how versioning works and the difference between major and minor – Remko Nov 27 '13 at 7:00
  • I have enabled the versioning via UI.. By taking the list settings.. Now my problem, is its showing only the major versions (ie. only the numbers) How can we enable a minor version number with decimal for the list like 1.1, 1.2, 1.3 etc.. – Anish V Nov 27 '13 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.