Modify document without versioning?

Posted by Community Admin on 04-Aug-2018 13:57

Modify document without versioning?

All Replies

Posted by Community Admin on 31-Jul-2013 00:00

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

Posted by Community Admin on 05-Aug-2013 00:00

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


Regards,
Stanislav Velikov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed