Code Sample for ServerSide C# for Custom Content Type not Wo

Posted by Community Admin on 04-Aug-2018 20:31

Code Sample for ServerSide C# for Custom Content Type not Working

All Replies

Posted by Community Admin on 14-Aug-2013 00:00

A module has been created called myModule. It is activated and a Content Type Exists for myModule.  I took the code from:
Administration > Module Builder > Code reference for myModule > Server side (C#) Create a myModule
The code cannot compile because there is no method called SetValue on a DynamicContent object.
I have included all the necessary usings

The code is:
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type myType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.myModule.myModule");
DynamicContent myDataItem = new DynamicContent(); 
myDataItem = dynamicModuleManager.CreateDataItem(myType); // This is how values for the properties are set
 myDataItem.SetValue("Idmod", "Some id");
 myDataItem.SetValue("tempNumber", "Some whse_number");
 myDataItem.SetValue("UrlName", "SomeUrlName");
 myDataItem.SetValue("fax", "Some fax");
 myDataItem.SetValue("isWilsonart", true);
 myDataItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
 myDataItem.SetValue("PublicationDate", DateTime.Now);
 myDataItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
myDataItem.Status = ContentLifecycleStatus.Live;
 


Posted by Community Admin on 14-Aug-2013 00:00

Hi Walt,

Add this to your usings:

using Telerik.Sitefinity.Model;

The GetValue() and SetValue() methods are extension methods inside that namespace.

Kind regards,
Daniel

Posted by Community Admin on 14-Aug-2013 00:00

Hi Daniel,

Thank you!  This took care of the issue. 


Posted by Community Admin on 19-Aug-2013 00:00

Hi all,

Thank you, Daniel for your help.

For custom fields we have our extension methods GetValue and SetValue which help retrieve and set the custom field values accordingly. More information could be found in the following article.

Regards,
Stefani Tacheva
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed