sharepoint知识点总结

来源:互联网 发布:免费阅读漫画软件 编辑:程序博客网 时间:2024/05/18 01:02

      mySite=newSPSite("http://richsql/");。

  myWeb=mySite.RootWeb;

SPDocumentLibraryspDoc=myWeb.Lists["JackDocuments"]   as SPDocumentLibrary;

SPContentTypeCollectionspcontents=spDoc.ContentTypes;

stringstrCTName=string.Empty;

  foreach(SPContentTypespContextTypeinspcontents)。

  {if(spContextType.Name=="Folder")。

  大盘-sharepoint知识点总结。

  {。

  spContextType.Sealed=false;。

  spContextType.Update();。

  }。

  大盘-sharepoint知识点总结。

  }。

  Sealed属性设置成false就可以了.。

  多行文本取出换行。

  Replace(""r"n","br/")。

  识别为垃圾邮件。

  来历不明的软件发的邮件都是垃圾邮件。

  所以发邮件的时候要套个马甲。

  这个代码就是套个OutLook作掩护。

  publicboolSend(stringSubject,stringBody,stringTo,stringMailFrom,stringMailFromName,stringMailDomain,stringMailServerUserName,stringMailServerPassWord)。

  {。

  try。

  {。

  MailMessagemsg=newMailMessage();。

  msg.From=newMailAddress(MailFrom,MailFromName);。

  msg.To.Add(newMailAddress(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","MicrosoftOutlookExpress6.00.2900.2869");。

  msg.Headers.Add("X-MimeOLE","ProducedByMicrosoftMimeOLEV6.00.2900.2869");。

  msg.Headers.Add("ReturnReceipt","1");。

  //附加结束。

  SmtpClientclient=newSmtpClient(MailDomain);。

  client.UseDefaultCredentials=false;。

  client.Credentials=newNetworkCredential(MailServerUserName,MailServerPassWord);//帐号密码。

  client.DeliveryMethod=SmtpDeliveryMethod.Network;。

  client.Send(msg);。

  returntrue;。

  }。

  catch{returnfalse;}。

  }。

  使用MOSS自带的方法发送email。

  StringDictionarymessageHeaders=newStringDictionary();。

  messageHeaders.Add("to",email);。

  messageHeaders.Add("subject",s_subject);。

  //messageHeaders.Add("from","");。

  messageHeaders.Add("content-type","text/html");。

  //messageHeaders.Add("cc","");。

  //messageHeaders.Add("bcc","");。

  SPUtility.SendEmail(this.Web,messageHeaders,s_body);。

  .net方式发送email。

  publicstaticboolSendMail(stringto,stringsubject,stringbody)。

  {。

  MailAddressfrom=newMailAddress("MOSS-Test1@XXX.com");。

  MailAddresstoUser=newMailAddress(to);。

  MailMessagemailobj=newMailMessage(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对象。

  SmtpClientsmtp=newSmtpClient("mail.**.com");。

  try。

  {。

  smtp.Send(mailobj);。

  returntrue;。

  }。

  catch。

  {。

  returnfalse;。

  }。

  }。

  我们使用.NET类库中的API发Mail的时候,我们要配置他的SMTPServer等,但是在Sharepoint里,已经提供了相关的封装的方法:。

  SPUtility.SendEmail(SPWeb,false,false,"to@mail.com","MailTitle","MailBody");。

  上面的方法只能以To的形式来发Mail,有的时候我们需要使用CC,BCC,我们可以利用该函数的另一个重载来实现:。

  SPUtility.SendEmail(web,messageHeaders,messageBody,appendFooter)。

  我们需要设置messageHeaders,代码如下:。

  StringDictionaryheaders=newStringDictionary();。

  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","TheMailTitle");。

  headers.Add("content-type","text/html");。

  在header中可以指定ToCCBCCFrom等,当然使用上面的函数的前提是你在管理中心已经配置好了传出电子邮件的设置。

  更新工作流状态。

  SPListlist=web.List["TestList"];。

  SPListItemlistItem=list.GetItemById(1);。

  stringstate=listItem.Fields["审批状态"].InternalName;。

  listItem[state]=0;//设置列表审批状态为“已批准”(0表示已批准)。

  listItem.SystemUpdate();//列表使用SystemUpDate()方法来更新审批状态。

  //文档库。

  SPDocumentLibrarydocLib=web.List["TestLib"];。

  SPListItemlibItem=list.GetItemById(1);。

  stringstate=libItem.Fields["审批状态"].InternalName;。

  libItem[state]=0;//设置文档库审批状态为“已批准”(0表示已批准)。

  libItem.UpdateOverwriteVersion();//文档库使用UpdateOverwriteVersion()方法来更新审批状态。

  item["_ModerationStatus"]=(int)SPModerationStatusType.Approved;。

  item.Update();。

  这样好像就可以。

  string转Guid。

  Guiddd=newguid(str);。

  ContentType。

  Item[“ContentTypeId”]或者Item[“ContentType”]。

  显示个人信息。

  用SPD打开根站点。

  在根下_catalogs目录有users(用户信息表)。

  此表是网站集所管理的用户列表。默认为隐藏。

  点右键属性--设置--钩掉“在浏览器中隐藏”选项。

  此时,用户表就可以像其他列表一样操作。

  要实现显示照片和姓名职务部门等信息。

  可以通过webpart显示指定列信息,转换为XSLT视图,进行定制。

  注意设置筛选条件为:ID列=[当前用户]。

  最终可以*定制。

  Item.SystemUpdate();方法更改时间更改者事件更改和审核记录订阅propertiesarenotdemotedintodocuments增加版本SystemUpdate()√√SystemUpdate(Bool)√√False不增加长时间操作,不超时。

  SPLongOperationoparetion=newSPLongOperation(this);。

  try。

  {。

  oparetion.Begin();。

  try。

  {。

  //启动工作流。

  //StartInitData参数为ApproveWFAssociationData类的序列化后的string。

  web.Site.WorkflowManager.StartWorkflow(listItem,workflowAssociation,StartInitData());。

  }。

  catch(Exceptionex)。

  {。

  thrownewException(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("TheCreateChildControlsfunctionoftheAjaxBaseParthasnotbeencalled.Youprobablyneedtoadd""base.CreateChildControls()""tothetopofyourCreateChildControlsoverride.");。

  成员名称说明CheckUrlChecktheredirectUniformResourceLocator(URL).DefaultUsedefaultsettingsfortheredirect.DoNotEncodeUrlDonotencodetheredirectURL.DoNotEndResponseDonotendtheresponseaftertheredirect.RelativeToLayoutsPage相对Layouts的地址Theredirectoccursrelativetothelayoutspage.RelativeToLocalizedLayoutsPage相对触发的layouts中Page的地址Theredirectoccursrelativetothelocalizedlayoutspage.Static静态地址,非相对地址Theredirectisstatic.TrustedTheredirectistrusted.UseSource使用URL中的Source的地址Usethesourcefortheredirect.http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.utilities.spredirectflags.aspx内容类型。

  SPWeb.AvailableContentTypes得到当前web所有活动的内容类型。

  SPWeb.ContentTypes得到部署到当前web上的内容类型,不要用这个。

  Web的用户list。

  web.SiteUserInfoList。

  AD操作。

  DirectoryEntrydi=newDirectoryEntry("LDAP://ADServer/OU=开发部,administrator,pass,AuthenticationTypes.Secure);。

  广州㊣-jian(简)说:。

  这句应该是最关键的了。

  广州㊣-jian(简)说:。

  然后想在“开发部”下面增加用户,就用di.Children.Add就可以了。

  List附件的读取。

  怎么取得sharepoint表单库中的表单附件的数据,我想将附件数据单独的提取出来,但是提取的信息全是BASE64编码,有没有这方面的信息或资料,。

  BASE64解码不就完了。

  System.Convert.FromBase64String。

  模拟用户代码。

  stringsiteUrl="http://bbs.msiw.net:82/sites/sjs";。

  //首先用管理员身份取到某个用户的Token,必须,非管理员无法模拟。

  SPSitesite=newSPSite(siteUrl);。

  //此时用户为SHAREPOINT"system。

  Response.Write(site.RootWeb.CurrentUser);。

  SPUseruser=site.RootWeb.SiteUsers["saicmotorlab""user1"];。

  //利用用户Token构造新的Site对象。

  SPSitesiteWithUser=newSPSite(siteUrl,user.UserToken);。

  SPWebwebWithUser=siteWithUser.RootWeb;。

  //此时用户为SAICMOTORLAB"user1。

  Response.Write(webWithUser.CurrentUser);。

  SPListlistWithUser=webWithUser.Lists["simeList"];。

  //dothercode。

  PeopleEditor控件。

  PeopleEditor.SelectionSet="User,DL,SecGroup";。

  代表可以选择用户,也可以选择组。

  工作流历史记录表。

  http://cnsh-10apl1/ProjectManagement/Lists/WorkflowHistory/。

  Infopath中为下拉框添加值。

  testNode.AppendChildElement(testNode.Prefix,"AddElm",testNode.NamespaceURI,string.Empty);。

  AJAX实现。

  3:在相关MasterPage的head里添加。

  scripttype='text/javascript'_spOriginalFormAction=document.forms[0].action;。

  _spSuppressFormOnSubmitWrapper=true;/script。

  4.在你写好的UserControl的Page_load事件里添加。

  if(this.Page.Form!=null)。

  {。

  stringformOnSubmitAtt=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);。

  当PersonorGroup字段允许多人时,通过sdk对象读取用户信息。

  ListSPUserusers=newListSPUser();。

  ListSPGroupgroups=newListSPGroup();。

  SPFieldUserValueCollectionvalues=(SPFieldUserValueCollection)item["人员或组栏"];。

  foreach(SPFieldUserValuevalueinvalues)。

  {。

  if(value.User!=null)。

  {。

  users.Add(value.User);。

  }。

  else。

  {。

  SPGroupgroup=web.Groups.GetByID(value.LookupId);。

  groups.Add(group);。

  foreach(SPUseruseringroup.Users)。

  {。

  users.Add(user);。

  }。

  }。

  }。

  SPFieldLookupValueCollectionvalues=(SPFieldLookupValueCollection)item["Users"];。

  SPFieldLookupValueCollectionvalues=item["Users"].ToString();。

  stringinitUsers="";。

  foreach(SPFieldLookupValuevalueinvalues)。

  {。

  intvalueID=value.LookupId;。

  stringvalueTitle=value.LookupValue;。

  }。

  代码启动工作流。

  获取spworkflowmanager获取spworkflowassociation,针对一个item启动。

  向Item中添加附件。

  if(fileUploadAttach.HasFile)。

  {。

  Streamstream=fileUploadAttach.PostedFile.InputStream;。

  stream.Position=0;。

  byte[]buffer=newbyte[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型。

  FieldRefName="GMP"LookupId="TRUE"/。

  ValueType="Lookup"1/Value。

  用户型。

  "FieldRefName=""User""LookupId=""TRUE""/"+。

  "ValueType=""User"""+user.ID+"/Value"+。

  WEB页面显示word。

  如果想让web页面显示出word文档要加。

  Response.ContentType="application/msword";。

  Response.AddHeader("Content-Disposition","attachment;filename="+。

  HttpUtility.UrlEncode(file.FILENAME).Replace("+","%20"));//防止乱码。

  Response.Charset="UTF-8";Response.ContentEncoding=System.Text.Encoding.Default;Response.BinaryWrite(文件流);。

  Response.End();。

  多文件上传。

  SPFileCollectiondestFiles=。

  siteCollection.AllWebs["Destination_Site"]。

  .Folders["Destination_DocLib"].Files;。

  foreach(SPFilesrcFileinsrcFolder.Files)。

  {。

  if(srcFile.TimeLastModified。

  Convert.ToDateTime("12/5/200212:00:00AM"))。

  {。

  stringdestURL=destFiles.Folder.Url+"/"+srcFile.Name;。

  byte[]binFile=srcFile.OpenBinary();。

  destFiles.Add(destURL,binFile,true);。

  }。

  }。

  工作流中权限。

  先HybridDictionary一个对象叫task1permission,然后task1permission.Add(taskProps.AssignedTo,SPRoleType.Contributor),最后将task1permission赋值给task的SpecialPermissions。

  检查权限。

  publicvoidCheckPermissions(SPBasePermissionspermissionMask)。

  检查当前用户是否有permissionMask的权限,如果没有返回一个UnauthorizedAccessException的异常。

  BoolhavePermission=SPList.DoesUserHavePermissions(SPBasePermissionspermissionMask)。

  添加权限。

  SPListDTTasks=web2.Lists["DocumentTasks"];。

  SPRoleAssignmentroleAssignForMember=newSPRoleAssignment((SPPrincipal)newGroup);//为newGroup这个组分配权限。

  SPRoleDefinitionroleDefForMemberr=web2.RoleDefinitions["DTMembers"];。

  roleAssignForMember.RoleDefinitionBindings.Add(roleDefForMemberr);。

  if(!DTTasks.hasUniqueRoleAssignments)//如文件夹没有独立的权限。

  {。

  DTTasks.BreakRoleInheritance(false);//删除文件夹继承的权限true删除的同时继承false删除的同时不继承。

  }。

  DTTasks.RoleAssignments.Add(roleAssignForMember);。

  TTasks.Update();。

  无法查询文件夹下的item,只能查找根目录的解决办法:。

  query.ViewAttributes="Scope='Recursive'"MembernameDescriptionDefaultShowonlythefilesandsubfoldersofaspecificfolder.FilesOnlyShowonlythefilesofaspecificfolder.RecursiveShowallfilesofallfolders.RecursiveAllShowallfilesandallsubfoldersofallfolders.TheSPViewScopeenumerationisusedwiththeScopepropertyoftheSPViewclass.EventHandler中的AddingUpdating等操作如何赋值。

  publicoverridevoidItemAdding(SPItemEventPropertiesproperties)。

  {。

  //Demo1:在新建时取用户输入的值并作修改。

  stringnewValue="新的值是:"+properties.AfterProperties["Title"].ToString();。

  properties.AfterProperties.ChangedProperties.Add("Title",newValue);。

  }。

  如何从SPAttachmentCollection中获取到SPfile。

  SPAttachmentCollectionattachments=item.Attachments;。

  if(attachments.Count0)。

  {。

  for(inti=0;iattachments.Count;i++)。

  {。

  stringurl=attachments.UrlPrefix+attachments[i];//得到附件的共同前缀再加上附件的名称。

  SPFilefile=web.GetFile(url);。

  stringcustomerName=item["CustomerName"].ToString().Split('#')[1];。

  file.CopyTo(properties.WebUrl+"/CRMDocument/"+customerName+"/04CustomerScoring/"+attachments[i],true);。

  }。

  如何查看SharePoint未知错误。

  在MOSS开发自定义功能后,出现错误页面只显示“出现未知错误”的提示,查看很不方面,通过下面方法就可以直接在出错页面查看错误信息。

  修改Web应用程序根目录上的Web.config文件中的两个地方:。

  查找以下位置并更改即可(红色为更改前后的值)。

  一、MaxControls="200"CallStack="false"改为MaxControls="200"CallStack="true"。

  二、customErrorsmode="On"改为customErrorsmode="Off"。

  Webpart出错,无法打开页面,contents=1,会转到webpart管理页面,把出问题的删掉。

  在URL后面加入“?&toolpaneview=2”打开设计页。

  或者加“DisplayMode=Design”。

  http://cnsh-10vms1/_layouts/spcontnt.aspx?&url=/_catalogs/wp/forms/editForm.aspx这页面是维护页面。

  “超链接或图片”类型栏的值,对应的对象模型为SPFieldUrl和SPFieldUrlValue,可以这样读取:。

  SPFieldUrlValuevalue=newSPFieldUrlValue(item["URL"].ToString());。

  Console.WriteLine(value.Description);。

  Console.WriteLine(value.Url);。

  或。

  SPFieldUrlfieldUrl=(SPFieldUrl)item.Fields["URL"];SPFieldUrlValuevalue=(SPFieldUrlValue)fieldUrl.GetFieldValue(item["URL"].ToString());。

  Console.WriteLine(value.Description);Console.WriteLine(value.Url);。

  赋值。

  SPFieldUrlfieldUrl=(SPFieldUrl)supplierNew.Fields[dgi.Cells[0].Text];。

  SPFieldUrlValuefieldUrlValue=newSPFieldUrlValue();。

  fieldUrlValue.Url=web.Url+"/"+supplierDocument.RootFolder.Url+"/"+supplierNew["Title"].ToString()+"-"+supplierNew.ID;。

  fieldUrlValue.Description=dgi.Cells[0].Text;。

  supplierNew[dgi.Cells[0].Text]=fieldUrlValue;。

  将子网站移动到主网站???。

  修改子网站下的网站栏到网站集下解决了,直接到WSS_Content数据库里面,修改表ContentTypes的Scope字段,特别方便,暂时没发现出错误~。

  SharePoint中LookUp字段的使用。

  赋值如何在代码中使用lookup字段对于lookup字段在可视界面时,感觉挺方便,但是在写代码的时候,对它进行赋值的时候,就感觉很麻烦。不知道哪位高手对这个赋值有更好的方法,谢谢。

  方法一(听11同学说的)。

  SPFieldLookupValueCollectionlookupValues;。

  lookupValues=(SPFieldLookupValueCollection)listItem["MyLookupField"];。

  lookupValues.Add(newSPFieldLookupValue(1,"SomeLookupValue"));。

  listItem["MyLookupField"]=lookupValues;。

  listItem.Update();。

  这方法感觉赋值就是受罪,写这么多代码。

  方法二。直接用。

  listItem["MyLookupField"]=1,2,3。

  但这此方法要知道字符串所对应的Id。,有什么最有效的方法。请教高手实际使用如下代码(经过测试):。

  SPWebweb=SPContext.Current.Web;。

  SPListcustomerList=web.Lists["Customer"];。

  SPQueryquery=newSPQuery();。

  query.Query="WhereEqFieldRefName='Title'/ValueType='Text'"+DropDownList1.SelectedItem.Text+"/Value/Eq/Where";。

  SPListItemCollectioncustomerC=customerList.GetItems(query);。

  intcu1=customerC[0].ID;。

  SPListprojectList=web.Lists["Project"];。

  SPListItemprojectNew=projectList.Items.Add();。

  projectNew["Customer"]=cu1;。

  projectNew["Title"]=txtboxProjectName.Text;。

  projectNew.Update();。

  LookUpCollection的赋值。

  SPFieldLookupValueCollectionlvsGDE=newSPFieldLookupValueCollection();。

  foreach(ListItemiteminlbGDECurrent.Items)//lbGDECurrent为下拉框。

  {。

  SPFieldLookupValuelvGDE=newSPFieldLookupValue();。

  lvGDE.LookupId=int.Parse(item.Value);。

  lvsGDE.Add(lvGDE);。

  }。

  Item[“Lookups”]=lvsGDE;。

  LookUp和User的读取。

  如果LookUp不允许多选的时候,Item["LookUp"]得到的是一个string。

  StringC=(item["CreatedBy"]==null)?"":item["CreatedBy"].ToString().Remove(0,item["CreatedBy"].ToString().IndexOf(";#")+2);。

  否则是一个SPFieldLookUpValueCollection。

  用户类型为SPFieldUserValueCollection。

  ListSPUserUsers=newListSPUser();。

  ListSPGroupGroups=newListSPGroup();。

  using(SPSiteSite=newSPSite("http://windbell"))。

  {。

  SPWebWeb=Site.RootWeb;。

  SPListList=Web.Lists["测试列表"];。

  SPItemItem=List.Items[0];。

  SPFieldUserValueCollectionValues=(SPFieldUserValueCollection)Item["用户和用户组"];。

  foreach(SPFieldUserValueValueinValues)。

  {。

  if(User!=null)。

  {。

  SPUserUser=Value.User;。

  Users.Add(User);。

  }。

  else。

  {。

  SPGroupGroup=Web.Groups.GetByID(Value.LookupId);。

  Groups.Add(Group);。

  Users.AddRange(Group.Users);。

  }。

  }。

  }。

  定义一个Group。

  SPGroupCollectiongroups=oWebsite.SiteGroups;。

  SPUseruser=oWebsite.Users["**""****"];。

  SPMembermember=oWebsite.Users["**xx""**"];。

  groups.Add("TestGroup",member,user,"Description");。

  将一个Group分配进一个Role。

  if(SPWeb.HasUniqueRoleAssignments==true)//web是否有自己的角色分配,有True。

  {。

  SPWeb.AllowUnsafeUpdates=true;。

  SPRoleAssignmentroleAssign=newSPRoleAssignment((SPPrincipal)SPSite.RootWeb.SiteGroups["StyleResourceReaders"]);。

  SPRoleDefinitionroleDef=SPWeb.RoleDefinitions["OpenAccess"];。

  roleAssign.RoleDefinitionBindings.Add(roleDef);。

  SPWeb.RoleAssignments.Add(roleAssign);。

  }读取UserProfileServerContextspcontext2=ServerContext.GetContext(site);UserProfileManagerprofileManager=newUserProfileManager(spcontext2);stringuserName=member.Name;SPListItemnewMember=projectMember.Items.Add();newMember["UserName"]=member.Name;newMember["Project"]=Project;newMember["Group"]=newGroup.Name;newMember["E-mailAddress"]=member.Email;if(profileManager.UserExists(userName)){UserProfileprofile=profileManager.GetUserProfile(userName);newMember["BusinessPhone"]=profile["BusinessPhone"].Value;newMember["MobilePhone"]=profile["CellPhone"].Value;newMember["Fax"]=profile["Fax"].Value;//newMember["Notes"]=member[PropertyConstants.CellPhone].newMember["SkypeMSN"]=profile["SkypeMSN"].Value;newMember["Principalship"]=profile["Principalship"].Value;newMember["Location"]=profile["Location"].Value;}newMember.Update();关闭EventHandlerthis.DisableEventFiring();//关闭EventHandler,防止多重触发。

  //savechanges。

  addedItem.Update();。

  this.EnableEventFiring();。

  workflowProperties.OriginatorUser得到当前workflowinstance的发起者。

  workflowProperties.Item不就可以直接拿到SPListItem。

  SharePoint中访问AD。

  System.DictionaryService。