Try our conversational search powered by Generative AI!

Changing pages programmatically does not reflect in site pages


i m using epi server 8 and I am editing page programatically but changes made programatically does not show up in site pages in order for editor to publish publish but when i check the page history it shows changes over there

my code is 

var pages = DataFactory.Instance.FindAllPagesWithCriteria(PageReference.StartPage, Criterias, "en", new LanguageSelector("en"));
if (pages != null && pages.Count > 0)
var Page = pages[0];

writablePage = (Page as PageData).CreateWritableClone();

writablePage.Name = (writablePage as MyPage).PageTitle = "Page Name";

var saveAction = SaveAction.CheckIn |  SaveAction.ForceNewVersion;

DataFactory.Instance.Save(writablePage, saveAction, EPiServer.Security.AccessLevel.NoAccess);


Jul 20, 2015 21:05

I think you'll need to clear the cache for the page after saving it:


Jul 21, 2015 7:20

After adding this line. Following happens

1:-  If page has no changes to publish. the changes i made in back end displayed properly

2: If page has already some changes which are pending to be published then changes made in backend are still not visible in site pages

Jul 21, 2015 9:34
Jul 21, 2015 9:35

I'm guessing you'll need to fetch the latest version when programmatically getting the page:

            var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
            var latestVersion = repository.List(page.ContentLink).OrderBy(x => x.Saved).FirstOrDefault();
            var latestPage = contentLoader.Get<PageData>(latestVersion.ContentLink);
            var writablePage = (latestPage as PageData).CreateWritableClone();
            latestPage.Name = "new name!";

I did not test this though. The OrderBy might need to reversed :-)

Jul 21, 2015 10:04

but that will give me last saved version of the page and all my changes will reflect in that version. i want to create new version of programatic changes for that page.

Jul 21, 2015 10:25

Then I suppose you need to set the common draft to the new version you create:

            writablePage.Name = "a new name";
            var saveAction = SaveAction.CheckIn | SaveAction.ForceNewVersion;
            var newReference = contentRepository.Save(writablePage, saveAction, EPiServer.Security.AccessLevel.NoAccess);
            var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>(); 
Jul 21, 2015 11:27
Evdin Ursan - Feb 08, 2021 20:32
Many thanks for the `repository.SetCommonDraft(newReference);`

Thanks aloooooot!!! Now its working fine

Only last question is if use following Save Action, the page changes do not appear in "Drafts" category of Tasks gadget

var saveAction = SaveAction.Save

Jul 21, 2015 11:38

Are you sure you refreshed the gadget? It should appear if you use "SaveAction.Save".

Jul 21, 2015 11:48

yes i have refreshed the gadget and i have refreshed the page but gadget is nt displaying but again if i do some manual change, it starts appearing in Gadget 

Jul 21, 2015 11:51

If you open the "versions" gadget. Is the newly created version a draft?

Jul 21, 2015 11:53

yes in the versions gadget it shows this version status as draft with three nested circles on on right top corner of this column

Jul 21, 2015 12:02

Okay, then it should be working. Are you sure it's not just out of sight? If you scroll down? :-)

Or do you see it if you select something other than "draft"? Like "ready to publish"?

Jul 21, 2015 12:09

if i use SaveAction.CheckedIn then it appears under Ready to publish catgory but if i use SaveAction.Save it doesnot appear under Draft or any other categorie.

I have doubled checked the scrol bar thing but its not there :-(

Jul 21, 2015 12:12

In the versions list, who does it say that the page has been saved by? System? Cause "tasks" will only display content changed by you

Jul 21, 2015 12:18

I m setting the changedby in backend

writablePage.ChangedBy = "BackEndUser";

BackEndUser is different from the one i am using to log into Epi Server cms

Versions gadget shows saved by "BackEndUser"

how can make it viewable for tasks gadget of any editor who has the publishing rights?????

Edited, Jul 21, 2015 12:23

I'm not sure if that's possible without doing some nasty hacks

Jul 21, 2015 13:00

Hi, Yasar,

I ended up using a different value for ChangedBy, check out this blog post:

However, what is different in later version of 8 is the following:

So, now, instead of using SaveAction.Save | SaveAction.ForceCurrentVersion, I use SaveAction.Publish | SaveAction.SkipSetCommonDraft.

Then, in the published event, I check the save action:

            if (e.Content is IHasFeedback && e.Content is IChangeTrackable &&
                ((SaveContentEventArgs)e).Action != AppSettings.SaveActionForNonContentChanges)
                ((IHasFeedback)e.Content).RealContentChangedBy = ((IChangeTrackable)e.Content).ChangedBy;

We didn't have any issues with the approach so far.

Jul 21, 2015 16:42
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.