SPListCollection转Datatable
SPListItemCollection unprocessedItems = List.GetItems(query);
DataTable dt1 = unprocessedItems.GetDataTable();
Folder类型添加自定义属性
mySite = new SPSite("http://richsql/"); myWeb = mySite.RootWeb; SPDocumentLibrary spDoc = myWeb.Lists["JackDocuments"] as SPDocumentLibrary; SPContentTypeCollection spcontents = spDoc.ContentTypes; string strCTName = string.Empty; foreach (SPContentType spContextType in spcontents) { if (spContextType.Name == "Folder") { spContextType.Sealed = false; spContextType.Update(); } }
Sealed 属性设置成false就可以了.
多行文本取出换行
Replace(""r"n", "<br/>")
识别为垃圾邮件
来历不明的软件发的邮件都是垃圾邮件。
所以发邮件的时候要套个马甲。
这个代码就是套个OutLook作掩护。
public bool Send(string Subject, string Body, string To, string MailFrom, string MailFromName, string MailDomain, string MailServerUserName, string MailServerPassWord) { try { MailMessage msg = new MailMessage(); msg.From = new MailAddress(MailFrom, MailFromName); msg.To.Add(new MailAddress(To, To)); msg.Subject = Subject; msg.Body = Body; msg.IsBodyHtml = true; msg.Priority = MailPriority.Normal; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.BodyEncoding = System.Text.Encoding.UTF8; //以下附加头用于避免被识别为垃圾邮件 msg.Headers.Add("X-Priority", "3"); msg.Headers.Add("X-MSMail-Priority", "Normal"); msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869"); msg.Headers.Add("ReturnReceipt", "1"); //附加结束 SmtpClient client = new SmtpClient(MailDomain); client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(MailServerUserName, MailServerPassWord); //帐号密码 client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(msg); return true; } catch { return false; } }
使用MOSS自带的方法发送email
StringDictionary messageHeaders = new StringDictionary(); messageHeaders.Add("to", email); messageHeaders.Add("subject", s_subject); //messageHeaders.Add("from", ""); messageHeaders.Add("content-type", "text/html"); //messageHeaders.Add("cc", ""); SPUtility.SendEmail(this.Web, messageHeaders, s_body);
.net方式发送email
public static bool SendMail(string to,string subject,string body) { MailAddress from = new MailAddress("MOSS-Test1@XXX.com"); MailAddress toUser = new MailAddress(to); MailMessage mailobj = new MailMessage(from, toUser); //完善MailMessage对象 mailobj.Subject = subject; mailobj.Body = body; mailobj.IsBodyHtml = true; mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8"); mailobj.Priority = MailPriority.Normal; //构建SmtpClient对象 SmtpClient smtp = new SmtpClient("mail.xxx.com"); try { smtp.Send(mailobj); return true; } catch { return false; } }
我们使用.NET类库中的API发Mail的时候,我们要配置他的SMTP Server等,但是在Sharepoint里,已经提供了相关的封装的方法:
SPUtility.SendEmail(SPWeb, false, false,"to@mail.com", "MailTitle","MailBody");
上面的方法只能以To的形式来发Mail,有的时候我们需要使用CC ,BCC,我们可以利用该函数的另一个重载来实现:
SPUtility.SendEmail(web, messageHeaders, messageBody, appendFooter)
我们需要设置messageHeaders,代码如下:
StringDictionary headers = new StringDictionary(); headers.Add("To","To@Mail.com"); headers.Add("CC","CC@Mail.com"); headers.Add("Bcc","BBC@Mail.com"); headers.Add("From","From@Mail.com"); headers.Add("subject","The Mail Title"); headers.Add("content-type","text/html");
在header中可以指定To CC BCC From等,当然使用上面的函数的前提是你在管理中心已经配置好了传出电子邮件的设置。
更新工作流状态
SPList list = web.List["TestList"]; SPListItem listItem = list.GetItemById(1); string state = listItem.Fields["审批状态"].InternalName; listItem[state] = 0; //设置列表审批状态为“已批准”(0表示 已批准) listItem.SystemUpdate(); //列表使用SystemUpDate()方法来更新审批状态。 //文档库 SPDocumentLibrary docLib = web.List["TestLib"]; SPListItem libItem = list.GetItemById(1); string state = libItem.Fields["审批状态"].InternalName; libItem[state] = 0; //设置文档库审批状态为“已批准”(0表示已批准) libItem.UpdateOverwriteVersion(); //文档库使用UpdateOverwriteVersion()方法来更新审批状态。 item["_ModerationStatus"] = (int)SPModerationStatusType.Approved; item.Update(); //这样好像就可以 //string转Guid Guid dd = new guid(str);
Content Type
Item[“ContentTypeId”]或者Item[“ContentType”]
显示个人信息
用SPD打开根站点
在根下 _catalogs 目录有 users(用户信息表)
此表是网站集所管理的用户列表。默认为隐藏。
点右键 属性--设置-- 钩掉“在浏览器中隐藏”选项。
此时,用户表 就可以像其他列表一样操作
要实现 显示照片和姓名 职务 部门等信息
可以通过webpart 显示指定列信息,转换为XSLT视图,进行定制
注意设置筛选条件 为: ID 列 = [当前用户]
最终可以自由定制。
Item.SystemUpdate();
方法 |
更改时间 |
更改者 |
事件 |
更改和审核记录 |
订阅 |
properties are not demoted into documents |
增加版本 |
SystemUpdate() |
× |
× |
√ |
√ |
× |
× |
× |
SystemUpdate(Bool) |
× |
× |
√ |
√ |
× |
× |
False不增加 |
长时间操作,不超时
SPLongOperation oparetion = new SPLongOperation(this); try { oparetion.Begin(); try { //启动工作流 //StartInitData参数为ApproveWFAssociationData类的序列化后的string web.Site.WorkflowManager.StartWorkflow(listItem, workflowAssociation, StartInitData()); } catch (Exception ex) { throw new Exception(ex.ToString()); } oparetion.End(list.DefaultViewUrl); } finally { if (oparetion != null) { oparetion.Dispose(); } }
转向
// 转向到该list的工作流设置页面 SPUtility.Redirect("WrkSetng.aspx?List=" + taskList.ID,SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
转到错误页
SPUtility.TransferToErrorPage("The CreateChildControls function of the AjaxBasePart has not been called. You probably need to add ""base.CreateChildControls()"" to the top of your CreateChildControls override.");
成员名称 |
说明 |
|
CheckUrl |
Check the redirect Uniform Resource Locator (URL). |
|
Default |
Use default settings for the redirect. |
|
DoNotEncodeUrl |
Do not encode the redirect URL. |
|
DoNotEndResponse |
Do not end the response after the redirect. |
|
RelativeToLayoutsPage |
相对Layouts的地址The redirect occurs relative to the layouts page. |
|
RelativeToLocalizedLayoutsPage |
相对触发的layouts中Page的地址The redirect occurs relative to the localized layouts page. |
|
Static |
静态地址,非相对地址The redirect is static. |
|
Trusted |
The redirect is trusted. |
|
UseSource |
使用URL中的Source的地址Use the source for the redirect. |
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.utilities.spredirectflags.aspx
内容类型
SPWeb.AvailableContentTypes得到当前web所有活动的内容类型
SPWeb.ContentTypes 得到部署到当前web上的内容类型,不要用这个。
Web的用户list
web.SiteUserInfoList
AD操作
DirectoryEntry di = new DirectoryEntry("LDAP://ADServer/OU=开发部,administrator,pass, AuthenticationTypes.Secure);
然后想在“开发部”下面增加用户,就用di.Children.Add就可以了
List附件的读取
怎么取得sharepoint表单库中的表单附件的数据,我想将附件数据单独的提取出来,但是提取的信息全是BASE64编码,有没有这方面的信息或资料,
BASE64 解码不就完了
System.Convert.FromBase64String
模拟用户代码
string siteUrl = "http://bbs.msiw.net:82/sites/sjs" ; //首先用管理员身份取到某个用户的Token,必须,非管理员无法模拟 SPSite site = new SPSite(siteUrl); //此时用户为SHAREPOINT"system Response.Write(site.RootWeb.CurrentUser); SPUser user = site.RootWeb.SiteUsers["saicmotorlab""user1"]; //利用用户Token构造新的Site对象 SPSite siteWithUser = new SPSite(siteUrl, user.UserToken); SPWeb webWithUser = siteWithUser.RootWeb; //此时用户为SAICMOTORLAB"user1 Response.Write( webWithUser.CurrentUser ); SPList listWithUser = webWithUser.Lists["simeList"]; //dother code
People Editor控件
PeopleEditor.SelectionSet = "User,DL,SecGroup";
代表可以选择用户,也可以选择组
工作流历史记录表
http://cnsh-10apl1/ProjectManagement/Lists/Workflow History/
Infopath中为下拉框添加值
testNode.AppendChildElement(testNode.Prefix, "AddElm",testNode.NamespaceURI, string.Empty);
AJAX实现
3:在相关MasterPage的<head>里添加
<script type='text/javascript'>_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;</script>
4.在你写好的UserControl的Page_load事件里添加
if (this.Page.Form != null) { string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"]; if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();") { this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();"; } } ScriptManager.RegisterStartupScript(this, typeof([你UserControl的ClassName]), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
当Person or Group字段允许多人时,通过sdk对象读取用户信息
List<SPUser> users = new List<SPUser>(); List<SPGroup> groups = new List<SPGroup>(); SPFieldUserValueCollection values = (SPFieldUserValueCollection)item["人员或组栏"]; foreach (SPFieldUserValue value in values) { if (value.User != null) { users.Add(value.User); } else { SPGroup group = web.Groups.GetByID(value.LookupId); groups.Add(group); foreach (SPUser user in group.Users) { users.Add(user); } } }
SPFieldLookupValueCollection values = (SPFieldLookupValueCollection )item["Users"]; SPFieldLookupValueCollection values = item["Users "].ToString(); string initUsers = ""; foreach (SPFieldLookupValue value in values) { int valueID = value.LookupId; string valueTitle = value.LookupValue; }
代码启动工作流
获取spworkflowmanager 获取spworkflowassociation,针对一个item启动
向Item中添加附件
if (fileUploadAttach.HasFile) { Stream stream = fileUploadAttach.PostedFile.InputStream; stream.Position = 0; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); itemNew.Attachments.Add(fileUploadAttach.PostedFile.FileName, buffer); itemNew.Update(); itemNew.ParentList.Update(); stream.Close(); }
CAML查找Lookup型
<FieldRef Name="GMP" LookupId="TRUE"/> <Value Type="Lookup">1</Value>
用户型
"<FieldRef Name=""User"" LookupId=""TRUE""/>" + "<Value Type=""User"">" + user.ID + "</Value>" +