Modify document without versioning?
Hello fellow posters,
We are creating a CRM based app using Sitefinity as a framework. Part of the app requires uploading "attachments" associated with CRM entities. We have successfully used the API to create, modify, and delete documents as described in the documentation found at:
http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/media-modules/documents-and-files/managing-documents
However, we would like to know if there is an option to replace (modify) a document without versioning as it seems this is automatic thru the API and not settable at the individual document level.
This post is on behalf of a fully licensed SF customer.
Thanks...Bob Baldwin
Trabon Solutions
Hi,
A document that is already uploaded can be retrieved using sitefinity API and all of its properties changed, I believe you have done this part by taking the sample from this documentation.
For versioning of the document I suppose you mean that no revision history must be saved for this document when it has been replaced, or some of the document properties (title, url) have been changed. The revision history in sitefinity can`t be disabled and upon every publish operation revision history is created. As the modification of the document will be done trough code the created version can also be modified and removed. This can be done trough VersionManager, here is a sample how to query version and truncate them based on version change creation date or the number of allowed revisions for docuent.
using
Telerik.Sitefinity.Versioning;
using
Telerik.Sitefinity.Versioning.Model;
LibrariesManager libMan = LibrariesManager.GetManager();
VersionManager versManager = VersionManager.GetManager();
IQueryable<Document> docs = libMan.GetDocuments().Where(n => n.ApprovalWorkflowState ==
"Published"
);
var _numOfRevisions = 3;
foreach
(NewsItem newsitem
in
docs)
if
(versManager.GetItemVersionHistory(newsitem.Id).Count >= _numOfRevisions)
var provider = VersionManager.GetManager().Provider;
IQueryable<Change> result = from c
in
provider.GetChanges()
where c.Parent.Id == newsitem.Id && c.LastModified < DateTime.Now
//.AddMonths(-NumberOfMonths)
select c;
IQueryable<Change> result1 = from c
in
provider.GetChanges()
where c.Parent.Id == newsitem.Id && c.LastModified > DateTime.Now
//.AddMonths(-NumberOfMonths)
select c;
//leaves only the last 3 versions
versManager.TruncateVersions(newsitem.Id, 30000);
versManager.SaveChanges();
versManager.Dispose();
libMan.SaveChanges();