Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Changing pages programmatically does not reflect in site pages

Vote:
 

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


}

#131308
Jul 20, 2015 21:05
Vote:
 

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

DataFactoryCache.RemovePage(writablePage)



#131311
Jul 21, 2015 7:20
Vote:
 

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

#131322
Jul 21, 2015 9:34
Vote:
 
#131323
Jul 21, 2015 9:35
Vote:
 

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 :-)

#131324
Jul 21, 2015 10:04
Vote:
 

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.

#131325
Jul 21, 2015 10:25
Vote:
 

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>(); 
            repository.SetCommonDraft(newReference);
#131326
Jul 21, 2015 11:27
Evdin Ursan - Feb 08, 2021 20:32
Many thanks for the `repository.SetCommonDraft(newReference);`
Vote:
 

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

#131328
Jul 21, 2015 11:38
Vote:
 

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

#131329
Jul 21, 2015 11:48
Vote:
 

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 

#131330
Jul 21, 2015 11:51
Vote:
 

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

#131331
Jul 21, 2015 11:53
Vote:
 

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

#131332
Jul 21, 2015 12:02
Vote:
 

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"?

#131333
Jul 21, 2015 12:09
Vote:
 

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 :-(

#131334
Jul 21, 2015 12:12
Vote:
 

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

#131335
Jul 21, 2015 12:18
Vote:
 

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?????

#131336
Edited, Jul 21, 2015 12:23
Vote:
 

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

#131339
Jul 21, 2015 13:00
Vote:
 

Hi, Yasar,

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

http://www.mogul.com/en/about-mogul/blog/saveactionsave-saveactionforcecurrentversion-doesnt-change-changed-but-does-touch-changedby

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

http://world.episerver.com/forum/developer-forum/-EPiServer-75-CMS/Thread-Container/2015/6/error-after-upgrade-to-8-5-quotusing-saveaction-save--saveaction-forcecurrentversion-on-published-content-is-not-allowedquot/

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.

#131348
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.