我想使用代码将新收件人添加到现有的收件人列表中。我试过下面的代码,但它没有工作。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Test acc = new Test();
private void button1_Click(object sender, EventArgs e)
{
acc.SerialPortEvent()
}
private void button2_Click(object sender, EventArgs e)
{
acc.stop();
}
}
class Test
{
public System.Timers.Timer theTimer1;
public void SerialPortEvent()
{
theTimer1 = new System.Timers.Timer(10000);
theTimer1.Elapsed += timer_Tick;
theTimer1.Start();
}
void timer_Tick(object sender, EventArgs e)
{
//Perform some calculations here.
if (something like counter)
{
stop();
}
}
public void stop()
{
theTimer1.Stop();
theTimer1.Dispose();
}
}
请帮助我实现这个目标,
提前致谢
答案 0 :(得分:3)
您可以从用户的用户名获取联系人。 此方法通过电子邮件地址获取联系人,并包含从电子邮件地址获取用户名的代码。
public Contact GetContact(string email)
{
// managerRoot is the top level ECM item
ManagerRoot managerRootFromId = Factory.GetManagerRootFromID(managerRoot.ID.ToString());
var username = Util.AddressToUserName(email);
string commonDomain = managerRootFromId.Settings.CommonDomain;
string fullName = commonDomain + "\\" + Util.AddressToUserName(username);
if (User.Exists(fullName))
{
return Contact.FromName(fullName);
}
return null;
}
然后,您应该可以将联系人添加到订阅列表中。
或者,如果您有联系人,则可以设置配置文件值并使用订阅方法。
contact.InnerUser.Profile["Fullname"] = string.Format("{0} {1}",person.Firstname,person.Surname);
contact.Subscribe(subscriptionLists);
您还可以使用以下代码添加ECM用户,并将电子邮件地址作为localname。
protected static Contact CreateAnonymousECMUser(string localName, ManagerRoot root)
{
Contact contact = (Contact)null;
if (root != null && !string.IsNullOrEmpty(localName))
{
string commonDomain = root.Settings.CommonDomain;
Assert.IsNotNullOrEmpty(commonDomain, EcmTexts.Localize("The Common Domain setting is not set.", new object[0]));
string str = commonDomain + "\\" + Util.AddressToUserName(localName);
while (User.Exists(str))
str = str + "_";
string password = new PasswordGenerator()
{
MinimumCharacters = 14
}.Generate();
System.Web.Security.Membership.CreateUser(str, password, localName);
contact = Contact.FromName(str);
contact.Profile.ProfileItemId = root.Settings.SubscriberProfile;
contact.Profile.Save();
}
return contact;
}