将内容中的 DNN HTML Pro 模块复制到另一个模块

Copy DNN HTML Pro module in content to another module

以下代码适用于 HTML 模块但不适用于 HTML PRO 模块。

HtmlTextController htmlTextController = new HtmlTextController();
WorkflowStateController workflowStateController = new WorkflowStateController();
int workflowId = htmlTextController.GetWorkflow(ModuleId, TabId, PortalId).Value;

List<HtmlTextInfo> htmlContents = htmlTextController.GetAllHtmlText(ModuleModId);
htmlContents = htmlContents.OrderBy(c => c.Version).ToList();

foreach (var content in htmlContents)
{
    HtmlTextInfo htmlContent = new HtmlTextInfo();
    htmlContent.ItemID = -1;
    htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId);
    htmlContent.WorkflowID = workflowId;
    htmlContent.ModuleID = ModuleId;
    htmlContent.IsPublished = content.IsPublished;
    htmlContent.Approved = content.Approved;
    htmlContent.IsActive = content.IsActive;
    htmlContent.Content = content.Content;
    htmlContent.Summary = content.Summary;
    htmlContent.Version = content.Version;
}
htmlTextController.UpdateHtmlText(htmlContent, htmlTextController.GetMaximumVersionHistory(PortalId));

这是由于 HTMLPro 模块有不同的方法。这与 DNN HTML 模块有部分不同。下面是代码。

            HtmlTextController htmlTextController = new HtmlTextController();
            WorkflowStateController workflowStateController = new WorkflowStateController();
            WorkflowStateInfo wsinfo = new WorkflowStateInfo();

            int workflowId = wsinfo.WorkflowID;

            HtmlTextInfo htmlContents = htmlTextController.GetLatestHTMLContent(ModuleModId);

                HtmlTextInfo htmlContent = new HtmlTextInfo();
                htmlContent.ItemID = -1;
                htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId);
                htmlContent.WorkflowID = workflowId;
                htmlContent.ModuleID = ModuleId;
                htmlContent.IsPublished = htmlContents.IsPublished;
                htmlContent.Approved = htmlContents.Approved;
                htmlContent.IsActive = htmlContents.IsActive;
                htmlContent.Content = htmlContents.Content;
                htmlContent.Summary = htmlContents.Summary;
                htmlContent.Version = htmlContents.Version;

                if (Tags != null && Tags.Count > 0)
                {
                    foreach (KeyValuePair<string, string> tag in Tags)
                    {
                        if (htmlContent.Content.Contains(tag.Key))
                        {
                            htmlContent.Content = htmlContent.Content.Replace(tag.Key, tag.Value);
                        }
                    }
                }

                htmlTextController.SaveHtmlContent(htmlContent, newModule);

并且请在下面添加对代码的引用以引用这些方法。

using DotNetNuke.Modules.HtmlPro;
using DotNetNuke.Professional.HtmlPro;
using DotNetNuke.Professional.HtmlPro.Components;
using DotNetNuke.Professional.HtmlPro.Services;

如果您只想 "copy" 从一个到另一个的内容,您可以研究作为这些模块一部分的 "Import" 和 "Export" 函数的用法。

我建议使用这条路线,以帮助您确保随着时间的推移更好的兼容性。如果他们更新字段或其他数据元素,您将不必调查,然后更新您的代码作为其中的一部分。

您可以简单地查看每个模块的 .dnn 清单,找到 BusinessControllerClass,它有两个您可以使用的方法 "ImportModule" 和 "ExportModule"。