79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
using Microsoft.SharePoint;
|
|
using SPSolutions.Net.Mail;
|
|
using SPSolutions.SharePoint.Resources;
|
|
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Configuration;
|
|
namespace SPSolutions.SharePoint.Net.Mail
|
|
{
|
|
public class SPListMailBodyProvider : MailBodyProvider
|
|
{
|
|
private SPContext m_context;
|
|
private string m_listName;
|
|
private string m_title;
|
|
private SPContext Context
|
|
{
|
|
get
|
|
{
|
|
if (this.m_context == null)
|
|
{
|
|
return SPContext.Current;
|
|
}
|
|
return this.m_context;
|
|
}
|
|
set
|
|
{
|
|
this.m_context = value;
|
|
}
|
|
}
|
|
private string ListName
|
|
{
|
|
get
|
|
{
|
|
return this.m_listName;
|
|
}
|
|
}
|
|
private string Title
|
|
{
|
|
get
|
|
{
|
|
return this.m_title;
|
|
}
|
|
}
|
|
public override void Initialize(string name, NameValueCollection config)
|
|
{
|
|
if (config == null)
|
|
{
|
|
throw new ArgumentNullException("config");
|
|
}
|
|
base.Initialize(name, config);
|
|
this.m_listName = config["ListName"];
|
|
if (string.IsNullOrEmpty(this.m_listName))
|
|
{
|
|
throw new ConfigurationErrorsException(ErrorsRes.ConfigurationErrorsException_NoListName);
|
|
}
|
|
config.Remove("ListName");
|
|
this.m_title = config["Title"];
|
|
config.Remove("Title");
|
|
}
|
|
public override string RetrieveMailBody(string bodyContainerName)
|
|
{
|
|
SPContext context = this.Context;
|
|
SPList sPList = context.Web.Lists[this.ListName];
|
|
SPQuery sPQuery = new SPQuery();
|
|
sPQuery.Query=(string.Format("<Where><Eq><FieldRef Name='MailBodyContainerName' /><Value Type='Text'>{0}</Value></Eq></Where>", bodyContainerName));
|
|
SPListItemCollection items = sPList.GetItems(sPQuery);
|
|
if (items == null || items.Count == 0)
|
|
{
|
|
throw new SPException(string.Format("Mail Definition '{0}' could not be found.", bodyContainerName));
|
|
}
|
|
object obj = items[0]["MailBody"];
|
|
if (obj == null)
|
|
{
|
|
return null;
|
|
}
|
|
return (string)obj;
|
|
}
|
|
}
|
|
}
|