Code Sample for ServerSide C# for Custom Content Type not Working
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;
Hi Walt,
Add this to your usings:
using
Telerik.Sitefinity.Model;
Hi Daniel,
Thank you! This took care of the issue.
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