+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Code Sample for ServerSide C# for Custom Content Type not Working

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

4 posts, 1 answered
  1. Walt
    Walt avatar
    6 posts
    Registered:
    16 Jan 2013
    14 Aug 2013
    Link to this post
    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;
     


    Answered
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    14 Aug 2013 in reply to Walt
    Link to this post
    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
  3. Walt
    Walt avatar
    6 posts
    Registered:
    16 Jan 2013
    14 Aug 2013 in reply to Daniel Plomp
    Link to this post
    Hi Daniel,

    Thank you!  This took care of the issue. 


  4. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    19 Aug 2013
    Link to this post
    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
4 posts, 1 answered