Create Page with Element Content

48 views
Skip to first unread message

Ayaz Asif

unread,
Nov 4, 2015, 6:51:09 PM11/4/15
to SmartAPI
Hi -

I have the following code working:

                    var project = session.ServerManager.Projects.GetByName("ProjectName");
                    var contentClass = project.ContentClasses.GetByName("ContentClass");
                    var announcement = project.Pages.CreateAndConnect(contentClass, LinkPageGuid, "Headline");
                    announcement.Filename = announcement.Id.ToString();

                    var elements = announcement.ContentElements.ToList();

But now I need to set values for elements on the newly created page, does the value property not have a set?
                    elements[0].Value = "ElementContent"; //??

In debug I see the Value property, but I cannot set it. Is this not possible or am I doing something wrong?

Thanks,

Ayaz


Jonas Jacobi

unread,
Nov 5, 2015, 4:13:53 AM11/5/15
to smar...@googlegroups.com

Hi,

you have to cast the elements down to their concrete element interface,

 

e.g.

 

((IStandardFieldText)elements[0]).Value = “abc”;

 

This is because the value can have different types for different element types, e.g. IFile for IImage or DateTime for IStandardFieldDate .

 

Mit freundlichen Grüßen / Best regards,

Jonas Jacobi


erminas
SmartAPI: Freie .NET RQL Bibliothek

 

erminas GmbH

Nadorster Str. 60

26123 Oldenburg

 

Tel.: +49 (0)441 249 287-13

Fax: +49 (0)441 249 287-91

jonas....@erminas.de

http://www.erminas.de

 

Registergericht: Amtsgericht Oldenburg, HRB 209480

Geschäftsführer: Hilmar Bunjes

--
More information about SmartAPI: http://www.smartapi.de
---
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "SmartAPI" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an smartapi+u...@googlegroups.com.
Wenn Sie in dieser Gruppe einen Beitrag posten möchten, senden Sie eine E-Mail an smar...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.

Jonas Jacobi

unread,
Nov 5, 2015, 5:19:21 AM11/5/15
to SmartAPI
And you also have to call

.Commit() on the element, to write the change to the server.

Cheers
Jonas

Ayaz Asif

unread,
Nov 5, 2015, 5:09:21 PM11/5/15
to SmartAPI
Ah, I see, thank you. So then one more question.. how do I cast the values? For an IValueElement<IOptionListEntry> for example?

Thanks,

Ayaz

Jonas Jacobi

unread,
Nov 6, 2015, 5:21:12 AM11/6/15
to SmartAPI
I'm not 100% sure i got your question, but i'll try to answer :)
IOptionList is a bit of a special case. You can get the possible values from
optionList.PossibleValues

So it would normally look something like

var valueToSet = optionListElement.PossibleValues.First(v=>v.Name == "MyValue");
optionListElement.Value = valueToSet;
optionListElement.Commit();

Ayaz Asif

unread,
Nov 6, 2015, 7:27:55 PM11/6/15
to smar...@googlegroups.com
Ah, yes, thank you! That answers my question. This is a great framework that will save A LOT of time! Thank you for making it and quick response to my questions! 

Regards,

aaa
Sie erhalten diese Nachricht, weil Sie in Google Groups ein Thema der Gruppe "SmartAPI" abonniert haben.
Wenn Sie sich von diesem Thema abmelden möchten, rufen Sie https://groups.google.com/d/topic/smartapi/0vtzFoZ3VQ0/unsubscribe auf.
Wenn Sie sich von dieser Gruppe und allen Themen dieser Gruppe abmelden möchten, senden Sie eine E-Mail an smartapi+u...@googlegroups.com.

Hilmar Bunjes

unread,
Nov 10, 2015, 4:34:56 AM11/10/15
to smar...@googlegroups.com
Ayaz,
I'm happy to hear that you like the SmartAPI and that it helps you working with the CMS :-)

Maybe it's also worth to have a look at the Sync Tool which is used to synchronize content classes and templates between different projects and/or servers based on attributes and template lines.

You can find it here: http://www.erminas.de/en/products#synctool

Currently, there is only a German video but you should get the idea nevertheless.

Best,
Hilmar
Reply all
Reply to author
Forward
0 new messages