Archive for the ‘工作’ Category

读取SharePoint的SMTP设置, 发送邮件

2009年09月17日 星期四

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);

判断是否一个SharePoint Publishing页处于编辑模式

2009年09月16日 星期三

… 并且避免 ASP.NET 验证控件错误:

This page contains content or formatting that is not valid. You can find more information in the affected sections.

or

Input string was not in a correct format.

当创建一个WebPart来显示包含验证控件的表单时, ASP.NET 验证控件会阻止你签入和发布当前的Publishing页面.

解决方案:

  • Check if the web part is in edit or design mode and only add the validator if not:if (this.WebPartManager.DisplayMode != WebPartManager.EditDisplayMode &&
    this.WebPartManager.DisplayMode != WebPartManager.DesignDisplayMode)
    {
    // in display mode
    }

    This solution applies only if you have a single web part on the page, because you can only check if the current web part is in display/edit/design mode.

  • Another solution is using the EditModePanel. It allows you to add contols to the page in display or edit mode.
    For example:

    // add the EditBox to the page in edit mode
    EditModePanelpanel = newEditModePanel();
    TextBoxtextBox = newTextBox();

    panel.Controls.Add(textBox);
    panel.PageDisplayMode = PageDisplayMode.Edit;
    this.Controls.Add(panel);

    This solution didn’t work. Some replection shows me that the panel uses this function (which is obfuscated): public staticSPControlModeGetContextualFormModeFromPostedForm()
    This function comes from the internal class ConsoleUtilities.

  • The solution that worked for me was quite simple:

    // check if the form is in display mode
    bool inDisplayMode = SPContext.Current.FormContext.FormMode == SPControlMode.Display;

Well, good luck ;)

来源: http://blogs.microsoft.co.il/blogs/justguy/archive/2008/08/13/checking-if-a-publishing-page-is-in-edit-mode.aspx

Clear upload file input field with javascript (JQuery)

2009年09月11日 星期五

<script language=”javascript” src=”jquery-1.3.2.min.js” type=”text/javascript”>
</script>

<script language=”javascript”>
function example_reset_html(id) {
$(‘#’+id).html($(‘#’+id).html());
}
</script>
<form>
<div style=”float: left;” id=”example_file”><input type=”file” /></div>
<input type=”button” value=”Clear” onclick=”example_reset_html(‘example_file’);”  />
</form>

Link: http://www.electrictoolbox.com/clear-upload-file-input-field-jquery/

How to get SharePoint 2007 SPList Forms Url

2009年09月11日 星期五

String formUrl = String.Format(CultureInfo.InvariantCulture, "{0}/{1}?id={2}",
SPContext.Current.Web.Url,
SPContext.Current.Web.Lists[ListName].Forms[ PAGETYPE.PAGE_DISPLAYFORM].Url, item.Id);

来源: http://www.myrocode.com/post/2009/03/20/How-get-SharePoint-2007-SpListItem-DispForm-Url.aspx

Single File PHP Gallery 4.0.0

2009年08月23日 星期天

给大家推荐一款网络照片管理工具: Single File PHP Gallery. 主页是: http://sye.dk/sfpg/.

顾名思义, 这是一款由PHP编写的单文件图片管理工具. 使用和部署及其简单, 只需要将index.php拷贝到图片目录即可. 你可以按照名称或文件扩展名自由决定需要显示(或屏蔽)的文件夹或文件.

我做了一些翻译和改动, 用来支持中文相册应用. 点击这里(Single File PHP Gallery 4.0.0)下载中文版.

开始学习MVC架构

2009年08月17日 星期一

很久之前的一次北京之行, 开始接触并关注这个asp.net项目,但是一直没有花时间和精力来研究学习它。公司的最近几个项目中都或多或少应用了一些新的技术,所以我想现在是时候作点研究工作了,争取能在以后的项目中推广开来。

MVC

MVC 主页: http://asp.net/mvc
几分钟前,看到的新文章:ASP.NET MVC V2 Preview 1 Released

另外的一些动力来源:Should ASP.NET Developers Learn ASP.NET MVC?