How to modify and publish a page programmatically in EPiServer
by Rizo on apr.28, 2010, under Developing
When you want to alter a page programmatically you need to use EPiServers CreateWriteableClone on the working page. This is because the Page itself is readonly. Now, there’s plenty of info out there how to do this, but just to refresh your mind, here’s some code:
[sourcecode language=’c#’]
PageData clone = pd.CreateWritableClone();
clone.Property[”MyProperty”] = ”New value”;
DataFactory.Instance.Save(clone, SaveAction.Publish);
[/sourcecode]
Simple enough, right?
Now, here’s the catch. If you are for example saving page ID’s into a customproperty, simply like this ”42 43 553 23” and so forth and you want to change this programmatically by removing one and adding one. So for example, going from ”42 43 553 23” to ”42 43 55” won’t work with the code above. The result will be ”42 43 553 23 55” as it will only add it up to your current value. So you want to clear your value before you set it although that is also not enough. You’ll have to save the page after you clear it and THEN you can set your new value and save the page. Something like this
[sourcecode language=’c#’]
PageData clone = pd.CreateWritableClone();
clone.Property[”MyProperty”].Clear();
DataFactory.Instance.Save(clone, SaveAction.Publish);
clone.Property[”MyProperty”] = ”New value”;
DataFactory.Instance.Save(clone, SaveAction.Publish);
[/sourcecode]
If someone has a better way to override values without having to doublesave, please do let me know.
2 Comments for this entry
21 Trackbacks / Pingbacks for this entry
-
How to modify and publish a page programmatically in EPiServer
mars 11th, 2023 on 09:50CashSweep
I found a great…
-
Hunter898 แจกเครดิตฟรี
oktober 6th, 2023 on 01:21… [Trackback]
[…] There you can find 31253 more Information on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
hizeed
oktober 17th, 2023 on 00:37… [Trackback]
[…] Here you will find 91146 more Information on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
visit this page
oktober 18th, 2023 on 09:45… [Trackback]
[…] Find More Info here on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
Infy
november 5th, 2023 on 07:21… [Trackback]
[…] Read More Info here on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
Buy Apple Airpods Pallet
december 4th, 2023 on 23:52… [Trackback]
[…] Here you will find 74093 additional Information on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
condo for sale
februari 20th, 2024 on 06:22… [Trackback]
[…] Read More here to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
เชื่อมสแตนเลส
februari 29th, 2024 on 01:55… [Trackback]
[…] Read More on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
golden teacher mushroom images
mars 12th, 2024 on 22:55… [Trackback]
[…] Here you can find 84845 more Information to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
ขายที่ดิน
maj 2nd, 2024 on 02:27… [Trackback]
[…] Read More on on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
outdoor furniture bangkok
juni 11th, 2024 on 23:35… [Trackback]
[…] Read More on to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
ks quik
juni 20th, 2024 on 11:47… [Trackback]
[…] There you can find 33251 additional Info on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
kayak
juni 21st, 2024 on 01:23… [Trackback]
[…] Info on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
คาเฟ่อารีย์
juni 23rd, 2024 on 06:32… [Trackback]
[…] Find More here to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
Bilad Alrafidain
juli 14th, 2024 on 13:23… [Trackback]
[…] Info on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
sex girldie
augusti 31st, 2024 on 00:38… [Trackback]
[…] Info on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
Pragmatic Play
september 16th, 2024 on 23:41… [Trackback]
[…] Read More on on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
lucabet88
september 17th, 2024 on 02:26… [Trackback]
[…] Find More on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
Buy browning a5 wicked wing Online
september 21st, 2024 on 04:40… [Trackback]
[…] Info to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
remisolleke
oktober 11th, 2024 on 18:55… [Trackback]
[…] Find More on to that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
-
saคาสิโน
oktober 26th, 2024 on 14:11… [Trackback]
[…] Read More on that Topic: from-rizo.se/how-to-modify-and-publish-a-page-programmatically-in-episerver/ […]
juli 26th, 2013 on 12:56
Thank you for your post, this solved stupid problem I tried to solve for some hours.
augusti 20th, 2014 on 22:59
Pretty nice post. I just stumbled upon your weblog and wished to say
that I’ve truly enjoyed browsing your blog posts. In any case I will be subscribing to your rss feed and I hope you write again very soon!