Apr 29, 2011

Sharepoint list items detail about Author,Editor , assignto with mutiple values , Duedate

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

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
}

}

Get sharepoint user name or email address

c# get sharepoint user name or email address
-------
static public string GetUserEMail(object user, ClientContext context)
{
Dictionary userNameCache = new 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 = "" + spUser.LookupId + "" };
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;
}

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

Feb 22, 2011

SQL Server using decode / instr function

1. "charindex('Taiwan',description)" can be act as instr.
2. "case WHEN charindex('Taiwan',description) > 0 then 'Taiwan Local' else 'Other contury' end as location" can be act as decode.
3. full sql is like :
select mac,description,case WHEN charindex('Taiwan',description) > 0 then 'Taiwan Local' else 'Other contury' end as location from tmpdata

Jan 7, 2011

Sharepoint 2010 disable user "alert me"

There are two ways to disable "alert me"
1. Sharepoint administration -> application management -> Web Application -> Manage web application -> Application Ex. 80 , then "general Settings"
-> set "Alerts" option as "off"

2. Through permission level , remove "alert me".

Sharepoint 2010 master page layout , fix content display width .

1.
## Copy v4.master as custom.master , and set as default master page , and then under <head> , above </head> add following code -> style type="text/css" ...

<style type="text/css">
.s4-specialNavLinkList
{
display:none !important;
}
.ms-cui-ribbonTopBars > DIV {
MARGIN: 0px auto; WIDTH: 1000px; FLOAT: none
}
UL.ms-cui-tabBody {
MARGIN: 0px auto; WIDTH: 1000px; FLOAT: none
}
BODY #s4-titlerow > DIV {
MARGIN: 0px auto; WIDTH: 1000px; FLOAT: none
}
#s4-bodyContainer > DIV {
MARGIN: 0px auto; WIDTH: 1000px; FLOAT: none
}
.s4-help {
DISPLAY: none !important;
}
.s4-search {
DISPLAY: none !important;
}
.s4-titletext {
DISPLAY: none !important;
}
body #s4-leftpanel{font-size: 10pt !important; font-family: Verdana !important;}
</style>


2. Hide the left panel at all.
1. Site Actions > Edit Page >
2. # Insert > Web Part (or add a Web Part to a Web Part zone)
3. # Under Media and Content select Content Editor and click Add , then save
4. Enter the following HTML / CSS into content and click OK

<style type="text/css">
body #s4-leftpanel { display: none; }
.s4-ca { margin-left: 0px; }
</style>


## There is a good reference doc for sharepoint 2010 layout component at http://erikswenson.blogspot.com/2010/01/sharepoint-2010-base-css-classes.html