Point8020 Learning Solutions from SharePoint: http://www.point8020.com/Training.aspx
Tag Archives: SharePoint
Trying to report error to Sharepoint ToolPane
1 2 3 4 5 6 | /// <summary> /// A custom editor part for picking data fields for a table web part /// </summary> class CustomEditorPart:EditorPart { #region Declarations |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | // In addition to other controls, etc, declare an error variable string _errorText = string.Empty; #endregion Declarations #region Apply Changes /// <summary> /// Applies the changes to the web part properties /// </summary> /// <returns></returns> public override bool ApplyChanges() { try { // You code goes here return true; } catch (Exception ex) { _errorText = ex.Message; return false; } } #endregion Apply Changes #region Rendering (Error Text) /// <summary> /// Update the error text if needed /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { if (_errorText != string.Empty) { this.Zone.ErrorText += Environment.NewLine + _errorText; } base.OnPreRender(e); } |
1 2 | #endregion Rendering (Error Text) } |
来源: http://goo.gl/IbOo
读取SharePoint的SMTP设置, 发送邮件
private static String GetSmtpHost()
{
SPOutboundMailServiceInstance instance = SPContext.Current.Site.WebApplication.OutboundMailServiceInstance;
if (instance != null)
{
return instance.Server.Address;
}
instance = SPAdministrationWebApplication.Local.OutboundMailServiceInstance;
if (instance != null)
{
return instance.Server.Address;
}
return String.Empty;
}
SmtpClient smtpClient = new SmtpClient(smtpServer);
MailMessage mail = new MailMessage(FromEmail, ToEMail)
{
Subject = MailSubject,
Body =
“<html><head><meta http-equiv=\”Content-Type\” content=\”text/html; charset=UTF-8\”><title>” + MailSubject + “</title></head>”
+ “<body style=\”font-family: Verdana; font-size: 12px\”>” + MailBody + “</body></html>”,
IsBodyHtml = true
};
smtpClient.Send(mail);