我正在使用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);
答案 0 :(得分:2)
您无法将文件附加到DNN中的通知。但是,您可以将自定义通知操作添加到通知类型。这些操作会导致在通知下添加链接(例如默认的“ Dismiss”操作将通知标记为“已读”)。
为了发送通知,您需要创建一个NotificationType来关联它。 NotificationTypeAction被添加到类型中。因此,每当您发送某种类型的通知时,操作都会随之发生。
您可以创建一个NotificationTypeAction并将其命名为“ Download Attachment”。用户单击链接时,它将调用自定义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 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);
}
}
有关DNN通知的完整教程,我强烈建议您订阅DNNHero.com并观看此3部分系列文章,其中包含示例代码。
https://www.dnnhero.com/Premium/Tutorial/ArticleID/265/DNN-Notifications-Introduction-Part-1-3