我是SharePoint 2010的新手。

我想在用户单击相对于列表中的元素的指定自定义按钮时发送电子邮件。

我想在电子邮件中添加一些关于所选元素的信息,如列“标题”或“作者”。

我发现这段代码发送电子邮件,我已将它复制到.aspx页面中。此页面还通过QueryString接收一个参数。该参数是“list_name”,它指定单击按钮的列表的名称。我认为这可以用来在代码中的某处指定SP列表,但我不确定在哪里以及如何进行。

StringDictionary headers = new StringDictionary();
string bodyTxt = "<b>Test Mail Bold</b>"; //for html mail body, you can send unformatted text too…

headers.Add("to", "mailadressfor_cc@domainname.com");
headers.Add("from", "mailadress_from@domainname.com");
headers.Add("subject", "Richiesta scambio prenotazione");
headers.Add("content-type", "text/html"); //for html mail body

SPUtility.SendEmail(properties.web, headers, bodyTxt);
.

但我(可能是愚蠢的)问题是:如何从列表中检索数据并在发送电子邮件的这个.aspx页面中使用它。

谢谢!

有帮助吗?

解决方案

Since you have the list name in the query string use it to get SPList as below

SPWeb web = SPContext.Current.Web;
SPList list = web.GetListFromUrl(web.Url + “/Lists/ListName/Forms/AllItems.aspx“);

Then you can get properties from list.

Example:

String listTitle = list.Title;

If you want to get properties from a list item, you can pass item’s ID in the query string too, and get the item as below:

SPListItem item = list.GetItemByID(id);
String itemTitle = item.Title;
String itemFieldValue = item[“fieldname”] == null ? null : item[“fieldname”].ToString();
许可以下: CC-BY-SA归因
scroll top