C# DNN将文件附加到通知

C# DNN将文件附加到通知,c#,dotnetnuke,attachment,messaging,dnn9,C#,Dotnetnuke,Attachment,Messaging,Dnn9,我正在使用DNN 9,我想发送一个带有附件文件的通知,但DNN似乎不允许这样做 有没有办法(或解决办法)做到这一点? 这是NotificationsController的DNN代码 这是我调用DNN代码的代码 //... Notification dnnNotification = new Notification { NotificationTypeID = notification.NotificationTypeId, From = notification.From,

我正在使用DNN 9,我想发送一个带有附件文件的通知,但DNN似乎不允许这样做

有没有办法(或解决办法)做到这一点?

这是NotificationsController的DNN代码

这是我调用DNN代码的代码

//...
Notification dnnNotification = new Notification
{
    NotificationTypeID = notification.NotificationTypeId,
    From = notification.From,
    Subject = notification.Subject,
    Body = notification.Body
};
NotificationsController.Instance.SendNotification(dnnNotification, portalId, dnnRoles, dnnUsers);

无法将文件附加到DNN中的通知。但是,您可以向通知类型添加自定义通知操作。这些操作会导致在通知下添加链接(如将通知标记为“已读”的默认“驳回”操作)

为了发送通知,您需要创建一个NotificationType将其关联到。NotificationTypeAction被添加到类型中。因此,无论何时发送某种类型的通知,操作都会随之进行

您可以创建NotificationTypeAction并将其命名为“下载附件”。当用户单击链接时,它将调用自定义api服务。那项服务可以提供文件

下面是一些示例代码,我在其中创建了一个带有1个自定义操作的自定义类型:

public void AddNotificationType()
{
    var actions = new List<NotificationTypeAction>();
    var deskModuleId = DesktopModuleController.GetDesktopModuleByFriendlyName(Constants.DESKTOPMODULE_FRIENDLYNAME).DesktopModuleID;

    var objNotificationType = new NotificationType
    {
        Name = Constants.NOTIFICATION_FILEDOWNLOAD,
        Description = "Get File Attachment",
        DesktopModuleId = deskModuleId
    };

    if (NotificationsController.Instance.GetNotificationType(objNotificationType.Name) == null)
    {
        var objAction = new NotificationTypeAction
        {
            NameResourceKey = "DownloadAttachment",
            DescriptionResourceKey = "DownloadAttachment_Desc",
            APICall = "DesktopModules/MyCustomModule/API/mynotification/downloadfile",
            Order = 1
        };
        actions.Add(objAction);

        NotificationsController.Instance.CreateNotificationType(objNotificationType);
        NotificationsController.Instance.SetNotificationTypeActions(actions, objNotificationType.NotificationTypeId);
    }
}
public void AddNotificationType()
{
var actions=新列表();
var deskModuleId=DesktopModuleController.GetDesktopModuleByFriendlyName(Constants.DESKTOPMODULE\u FRIENDLYNAME).DesktopModuleID;
var objNotificationType=新通知类型
{
Name=Constants.NOTIFICATION\u文件下载,
Description=“获取文件附件”,
DesktopModuleId=deskModuleId
};
if(NotificationsController.Instance.GetNotificationType(objNotificationType.Name)==null)
{
var objAction=新的NotificationTypeAction
{
NameResourceKey=“下载附件”,
DescriptionResourceKey=“下载附件”,
APICall=“DesktopModules/MyCustomModule/API/mynotification/downloadfile”,
订单=1
};
动作。添加(对象);
NotificationsController.Instance.CreateNotificationType(objNotificationType);
NotificationsController.Instance.SetNotificationTypeActions(actions,objNotificationType.NotificationTypeId);
}
}
然后使用如下代码发送通知:

public void SendNotification(UserInfo userToReceive)
{
    // Get the notification type; if it doesn't exist, create it
    ModuleController mCtrl = new ModuleController();
    var itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
    if (itemAddedNType == null) 
    { 
        AddNotificationType();
        itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
    }


    if (itemAddedNType != null)
    {
        Notification msg = new Notification
        {
            NotificationTypeID = itemAddedNType.NotificationTypeId,
            Subject = "A file is ready to download.",
            Body = alertBody,
            ExpirationDate = DateTime.MaxValue,
            IncludeDismissAction = true,
        };

        List<UserInfo> sendUsers = new List<UserInfo>();
        sendUsers.Add(userToReceive);

        NotificationsController.Instance.SendNotification(msg, itemModule.PortalID, null, sendUsers);
    }
}
public void发送通知(UserInfo userToReceive)
{
//获取通知类型;如果它不存在,则创建它
ModuleControl mCtrl=新的ModuleControl();
var itemaddendtype=notificationscocontroller.Instance.GetNotificationType(Constants.NOTIFICATION\u FILEDOWNLOAD);
if(itemAddedNType==null)
{ 
AddNotificationType();
itemAddedNType=NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION\u文件下载);
}
if(itemAddedNType!=null)
{
通知消息=新通知
{
NotificationTypeID=itemAddedNType.NotificationTypeID,
Subject=“已准备好下载文件。”,
Body=alertBody,
ExpirationDate=DateTime.MaxValue,
IncludeDismissAction=true,
};
List sendUsers=新列表();
添加(userToReceive);
NotificationsController.Instance.SendNotification(msg,itemModule.PortalID,null,sendUsers);
}
}
关于DNN通知的完整教程,我强烈建议订阅DNNHero.com并观看这个由三部分组成的系列,其中包含示例代码


您不能将文件附加到DNN中的通知。但是,您可以向通知类型添加自定义通知操作。这些操作会导致在通知下添加链接(如将通知标记为“已读”的默认“驳回”操作)

为了发送通知,您需要创建一个NotificationType将其关联到。NotificationTypeAction被添加到类型中。因此,无论何时发送某种类型的通知,操作都会随之进行

您可以创建NotificationTypeAction并将其命名为“下载附件”。当用户单击链接时,它将调用自定义api服务。那项服务可以提供文件

下面是一些示例代码,我在其中创建了一个带有1个自定义操作的自定义类型:

public void AddNotificationType()
{
    var actions = new List<NotificationTypeAction>();
    var deskModuleId = DesktopModuleController.GetDesktopModuleByFriendlyName(Constants.DESKTOPMODULE_FRIENDLYNAME).DesktopModuleID;

    var objNotificationType = new NotificationType
    {
        Name = Constants.NOTIFICATION_FILEDOWNLOAD,
        Description = "Get File Attachment",
        DesktopModuleId = deskModuleId
    };

    if (NotificationsController.Instance.GetNotificationType(objNotificationType.Name) == null)
    {
        var objAction = new NotificationTypeAction
        {
            NameResourceKey = "DownloadAttachment",
            DescriptionResourceKey = "DownloadAttachment_Desc",
            APICall = "DesktopModules/MyCustomModule/API/mynotification/downloadfile",
            Order = 1
        };
        actions.Add(objAction);

        NotificationsController.Instance.CreateNotificationType(objNotificationType);
        NotificationsController.Instance.SetNotificationTypeActions(actions, objNotificationType.NotificationTypeId);
    }
}
public void AddNotificationType()
{
var actions=新列表();
var deskModuleId=DesktopModuleController.GetDesktopModuleByFriendlyName(Constants.DESKTOPMODULE\u FRIENDLYNAME).DesktopModuleID;
var objNotificationType=新通知类型
{
Name=Constants.NOTIFICATION\u文件下载,
Description=“获取文件附件”,
DesktopModuleId=deskModuleId
};
if(NotificationsController.Instance.GetNotificationType(objNotificationType.Name)==null)
{
var objAction=新的NotificationTypeAction
{
NameResourceKey=“下载附件”,
DescriptionResourceKey=“下载附件”,
APICall=“DesktopModules/MyCustomModule/API/mynotification/downloadfile”,
订单=1
};
动作。添加(对象);
NotificationsController.Instance.CreateNotificationType(objNotificationType);
NotificationsController.Instance.SetNotificationTypeActions(actions,objNotificationType.NotificationTypeId);
}
}
然后使用如下代码发送通知:

public void SendNotification(UserInfo userToReceive)
{
    // Get the notification type; if it doesn't exist, create it
    ModuleController mCtrl = new ModuleController();
    var itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
    if (itemAddedNType == null) 
    { 
        AddNotificationType();
        itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
    }


    if (itemAddedNType != null)
    {
        Notification msg = new Notification
        {
            NotificationTypeID = itemAddedNType.NotificationTypeId,
            Subject = "A file is ready to download.",
            Body = alertBody,
            ExpirationDate = DateTime.MaxValue,
            IncludeDismissAction = true,
        };

        List<UserInfo> sendUsers = new List<UserInfo>();
        sendUsers.Add(userToReceive);

        NotificationsController.Instance.SendNotification(msg, itemModule.PortalID, null, sendUsers);
    }
}
public void发送通知(UserInfo userToReceive)
{
//获取通知类型;如果它不存在,则创建它
ModuleControl mCtrl=新的ModuleControl();
var itemaddendtype=notificationscocontroller.Instance.GetNotificationType(Constants.NOTIFICATION\u FILEDOWNLOAD);
if(itemAddedNType==null)
{ 
AddNotificationType();
itemAddedNType=NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION\u文件下载);
}
if(itemAddedNType!=null)
{
通知消息=新通知
{
NotificationTypeID=itemAddedNType.NotificationTypeID,
Subject=“文件已准备就绪。”