c# , get sharepoint list item detail about Author,Editor , assignto with mutiple values , Duedate
// Add reference Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime
//
using Microsoft.SharePoint.Client;
ClientContext clientContext = new ClientContext("http://sharepointserver");
List list = clientContext.Web.Lists.GetByTitle("testlist");
clientContext.Load(list);
clientContext.ExecuteQuery();
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
int i = 0;
foreach (ListItem listItem in listItems)
{
var SendToList = string.Empty;
var MailSubJect = string.Empty;
var MailBody = string.Empty;
DateTime dt = Convert.ToDateTime(Convert.ToDateTime(listItem["DueDate"]).ToLocalTime().ToString("yyyy/MM/dd"));
DateTime today = Convert.ToDateTime(DateTime.Now.ToLocalTime().ToString("yyyy/MM/dd"));
if ((dt <= today) && (listItem["Status"].ToString().Equals("Finished") == false))
{
Console.WriteLine("Id: {0} Title: {1} Author : {2} Editor : {3}",
listItem.Id, listItem["Title"],
((FieldUserValue)(listItems[i]["Author"])).LookupValue,
((FieldUserValue)(listItems[i]["Editor"])).LookupValue
);
String StartDateStr = Convert.ToDateTime(listItem["StartDate"]).ToLocalTime().ToString("yyyy/MM/dd");
String DueDateStr = Convert.ToDateTime(listItem["DueDate"]).ToLocalTime().ToString("yyyy/MM/dd");
String ModifiedStr = Convert.ToDateTime(listItem["Modified"]).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
double PercentComplete = Convert.ToDouble(listItem["PercentComplete"].ToString());
PercentComplete = PercentComplete * 100;
String PercentCompleteStr = PercentComplete.ToString();
var BodyStr = string.Empty;
if (listItem["Body"]!=null)
BodyStr = listItem["Body"].ToString();
var assigntolist = string.Empty;
Type t = listItems[i]["AssignedTo"].GetType();
if (t.IsArray)
{
foreach (FieldUserValue o in listItems[i]["AssignedTo"] as FieldUserValue[])
Console.WriteLine("AssignedTo: {0}", o.LookupValue);
}
}
i = i + 1;
}
Apr 29, 2011
Sharepoint list items detail about Author,Editor , assignto with mutiple values , Duedate
標籤: Sharepoint 2010
C# send mail by smtp with html body
C# send mail by smtp with html body. (add reference System.Net)
using System.Net.Mail;
public static void Sendalertmail(string SendToList, string MailSubJect, string MailBody)
{
string fromEmail = "Administrator@test.com";//sending email from...
string ToEmail = SendToList; //destination email
string body = MailBody;
string subject = MailSubJect;
try
{
MailMessage mm = new MailMessage(fromEmail, ToEmail);
mm.Subject = MailSubJect;
mm.Body = MailBody;
mm.IsBodyHtml = true;
SmtpClient sMail = new SmtpClient("192.168.1.1");//exchange or smtp server goes here.
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Send(mm);
}
catch (Exception ex)
{
//do something
}
}
標籤: Sharepoint 2010
Get sharepoint user name or email address
c# get sharepoint user name or email address
-------
static public string GetUserEMail(object user, ClientContext context)
{
Dictionary
if (user == null)
{
return string.Empty;
}
var username = string.Empty;
var useremail = string.Empty;
var spUser = user as FieldUserValue;
if (spUser != null)
{
if (!userNameCache.TryGetValue(spUser.LookupId, out useremail))
{
var userInfoList = context.Web.SiteUserInfoList;
context.Load(userInfoList);
var query = new CamlQuery { ViewXml = "
var users = userInfoList.GetItems(query);
context.Load(users, items => items.Include(
item => item.Id,
item => item["Name"]));
var principal = users.GetById(spUser.LookupId);
context.Load(principal);
context.ExecuteQuery();
username = principal["Name"] as string;
useremail = username.Substring(username.IndexOf("\\") + 1) + "@test.com";
userNameCache.Add(spUser.LookupId, useremail);
}
}
return useremail;
}
標籤: Sharepoint 2010
Apr 14, 2011
Proxy Autoconfig , PAC
In Browser , setting as use PAC.
http://proxycfg/browser.pac
browser.pac content is as :
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) ||
shExpMatch(url, "*.mycompany.*") ||
isInNet(host, "192.168.0.0", "255.255.0.0"))
return "DIRECT";
if (isInNet(myIpAddress(), "192.168.0.0", "255.255.240.0"))
return "PROXY proxy.mycompany.com:3128; DIRECT";
else
return "PROXY proxy.othersite.com:8080; DIRECT";
}
-- Description
isPlainHostName(host) -> check if local lan server
shExpMatch(url, "*.mycompany.*") -> check url use local web site server
isInNet(host, "192.168.0.0", "255.255.0.0")) -> check server IP if in LAN
isInNet(myIpAddress(), "192.168.0.0", "255.255.240.0") -> CHeck if My IP address is in local site subnet