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

Forums / Developing with Sitefinity / Creating Dynamic content and set parent not working

Creating Dynamic content and set parent not working

1 posts, 0 answered
  1. Anju
    Anju avatar
    19 posts
    Registered:
    22 Jul 2014
    08 Oct 2015
    Link to this post

    Hi, 

    I am trying to create a dashboard widget to import data from a CSV to a dynamic content which is in a hierarchical pattern. 

    I have manually created the parent dynamic content and in my widget i use a dropdown to select the parent content and upload the CSV to create the data a child of that particular Parent. 

    Please find the code i have used for creating dynamic content through API's.

     public void CreateChildContentFromCSV(Record csvDataObj,Guid parentId)
            {
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.ConstantVariables.ProviderName);
                DynamicContent dataContentItem = dynamicModuleManager.CreateDataItem(Constants.ModuleTypes.dataContentItemType);

                // Set item parent
                Type admissionType = Constants.ModuleTypes.admissionType;
                dataContentItem .SetParent(parentId, admissionType.FullName);

                // This is how values for the properties are set
                dataContentItem .SetValue("Title", licensure.LicensureTitle);
                licensureItem.SetValue("Description", licensure.Description);
                string UrlName = Regex.Replace(licensure.LicensureTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                licensureItem.SetString("UrlName", UrlName);
                licensureItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                licensureItem.SetValue("PublicationDate", DateTime.Now.ToUniversalTime());

                ILifecycleDataItem publishedItem = dynamicModuleManager.Lifecycle.Publish(dataContentItem);
                licensureItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
                dynamicModuleManager.SaveChanges();
            }

     

    I am getting the content created but only the parent is not set. When i set it manually it works. Can somebody help me figure out what am i doing wrong? 

     

1 posts, 0 answered