Saving a preperty value via code

Vote:
 

Hi fellas.

I've build a plugin-tool to admin mode, where one can enter the name of a property, it's expected current value and a new value.
Press "Change" and all pages where the given property has the specified current value, it changes into the new value.

This works very well, if the property you want to change is of type string.

This tool was build to change the "Pages" property, so that you can enter a number value (the ID of a page) and another value (a new ID of a page) and press change, and all pages that point to a page with the old ID will instead point to a page with the new ID.
However, the problem is that the "Pages" property needs a PageRefererence, not a string or an int, so I need to cast..

So my question is actually a two-part question:

First of..
Is there a way to add a new value as a string or an object and let episerver to the casting for me, like: Page[propertyname] = newValue;

Or

Is there a way to make a simple (but ugly) swith statement, and if so, how do I compare, since Page[propertyName].GetType() returns a type, and the PropertyDataType is an enum which returns a DataType..

switch (Page[propertyName].GetType())
                    {
                        case PropertyDataType.PageReference:
                            // code
                            break;
                    }

Thanks.. :)

#35319
Dec 04, 2009 10:22
Vote:
 

CurrentPage.Property["propertyname"] gives you a PropertyData object. if you work on CurrentPage["propertyname"] you get the underline value of the property

PropertyData objects have the ParseToSelf function that have string as an input parameter...

Quess that will do the trick

#35324
Dec 04, 2009 13:42
Vote:
 

Genius, works like a charm, thanks a million

#35326
Dec 04, 2009 14:07
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.