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();
多文件上传
SPFileCollection destFiles = siteCollection.AllWebs["Destination_Site"] .Folders["Destination_DocLib"].Files; foreach (SPFile srcFile in srcFolder.Files) { if (srcFile.TimeLastModified < Convert.ToDateTime("12/5/2002 12:00:00 AM")) { string destURL = 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
检查权限
public void CheckPermissions (SPBasePermissions permissionMask)
检查当前用户是否有permissionMask的权限,如果没有返回一个UnauthorizedAccessException的异常。
Bool havePermission = SPList.DoesUserHavePermissions(SPBasePermissions permissionMask)
添加权限
SPList DTTasks = web2.Lists["Document Tasks"]; SPRoleAssignment roleAssignForMember = new SPRoleAssignment((SPPrincipal)newGroup); //为newGroup这个组分配权限 SPRoleDefinition roleDefForMemberr = 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' "
|
Member name |
Description |
Default |
Show only the files and subfolders of a specific folder. |
|
FilesOnly |
Show only the files of a specific folder. |
|
Recursive |
Show all files of all folders. |
|
RecursiveAll |
Show all files and all subfolders of all folders. |
The SPViewScope enumeration is used with the Scope property of the SPView class.
EventHandler中的Adding Updating等操作如何赋值
public override void ItemAdding(SPItemEventProperties properties) { // Demo1: 在新建时取用户输入的值并作修改 string newValue = "新的值是:" + properties.AfterProperties["Title"].ToString(); properties.AfterProperties.ChangedProperties.Add("Title", newValue); }
如何从SPAttachmentCollection中获取到SPfile
SPAttachmentCollection attachments = item.Attachments; if (attachments.Count > 0) { for (int i = 0; i < attachments.Count; i++) { string url = attachments.UrlPrefix + attachments[i];//得到附件的共同前缀再加上附件的名称 SPFile file = web.GetFile(url); string customerName = item["Customer Name"].ToString().Split('#')[1]; file.CopyTo(properties.WebUrl + "/CRM Document/" + customerName + "/04 Customer Scoring/" + attachments[i], true); }
}
如何查看SharePoint未知错误
在MOSS开发自定义功能后,出现错误页面只显示“出现未知错误”的提示,查看很不方面,通过下面方法就可以直接在出错页面查看错误信息。
修改Web应用程序根目录上的Web.config文件中的两个地方:
查找以下位置并更改即可(红色为更改前后的值)
一、MaxControls="200" CallStack="false" 改为 MaxControls="200" CallStack="true"
二、customErrors mode="On" 改为 customErrors mode="Off"
Webpart出错,无法打开页面,contents=1 ,会转到webpart管理页面,把出问题的删掉
在URL后面加入“?&toolpaneview=2”打开设计页
或者加“DisplayMode=Design”
http://cnsh-10vms1/_layouts/spcontnt.aspx?&url=/_catalogs/wp/forms/editForm.aspx这页面是维护页面
“超链接或图片”类型栏的值,对应的对象模型为SPFieldUrl和SPFieldUrlValue,可以这样读取:
SPFieldUrlValue value = new SPFieldUrlValue(item["URL"].ToString()); Console.WriteLine(value.Description); Console.WriteLine(value.Url);
或
SPFieldUrl fieldUrl = (SPFieldUrl)item.Fields["URL"]; SPFieldUrlValue value = (SPFieldUrlValue)fieldUrl.GetFieldValue(item["URL"].ToString()); Console.WriteLine(value.Description); Console.WriteLine(value.Url);
赋值
SPFieldUrl fieldUrl = (SPFieldUrl)supplierNew.Fields[dgi.Cells[0].Text]; SPFieldUrlValue fieldUrlValue = new SPFieldUrlValue(); 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字段的使用
赋值
|
||||
|
实际使用如下代码(经过测试):
SPWeb web = SPContext.Current.Web; SPList customerList = web.Lists["Customer"]; SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + DropDownList1.SelectedItem.Text + "</Value></Eq></Where>"; SPListItemCollection customerC = customerList.GetItems(query); int cu1 = customerC[0].ID; SPList projectList = web.Lists["Project"]; SPListItem projectNew = projectList.Items.Add(); projectNew["Customer"] = cu1; projectNew["Title"] = txtboxProjectName.Text; projectNew.Update();
LookUpCollection的赋值
SPFieldLookupValueCollection lvsGDE = new SPFieldLookupValueCollection(); foreach (ListItem item in lbGDECurrent.Items) //lbGDECurrent为下拉框 { SPFieldLookupValue lvGDE = new SPFieldLookupValue(); lvGDE.LookupId = int.Parse(item.Value); lvsGDE.Add(lvGDE); } Item[“Lookups”] = lvsGDE;
LookUp和User的读取
如果LookUp不允许多选的时候,Item["LookUp"]得到的是一个string
String C = (item["Created By"] == null) ? "" : item["Created By"].ToString().Remove(0, item["Created By"].ToString().IndexOf(";#") + 2);
否则是一个SPFieldLookUpValueCollection
用户类型为SPFieldUserValueCollection
List<SPUser> Users = new List<SPUser>(); List<SPGroup> Groups = new List<SPGroup>(); using (SPSite Site = new SPSite("http://windbell")) { SPWeb Web = Site.RootWeb; SPList List = Web.Lists["测试列表"]; SPItem Item = List.Items[0]; SPFieldUserValueCollection Values = (SPFieldUserValueCollection)Item["用户和用户组"]; foreach (SPFieldUserValue Value in Values) { if (User != null) { SPUser User = Value.User; Users.Add(User); } else { SPGroup Group = Web.Groups.GetByID(Value.LookupId); Groups.Add(Group); Users.AddRange(Group.Users); } } }
定义一个Group
SPGroupCollection groups = oWebsite.SiteGroups; SPUser user = oWebsite.Users["xxx""xxxxxx"]; SPMember member = oWebsite.Users["xxxxx""xxx"]; groups.Add("TestGroup", member, user, "Description");
将一个Group分配进一个Role
if (SPWeb.HasUniqueRoleAssignments == true)//web是否有自己的角色分配,有True { SPWeb.AllowUnsafeUpdates = true; SPRoleAssignment roleAssign = new SPRoleAssignment((SPPrincipal)SPSite.RootWeb.SiteGroups["Style Resource Readers"]); SPRoleDefinition roleDef = SPWeb.RoleDefinitions["Open Access"]; roleAssign.RoleDefinitionBindings.Add(roleDef); SPWeb.RoleAssignments.Add(roleAssign); }
读取User Profile
ServerContext spcontext2 = ServerContext.GetContext(site); UserProfileManager profileManager = new UserProfileManager(spcontext2); string userName = member.Name; SPListItem newMember = projectMember.Items.Add(); newMember["User Name"] = member.Name; newMember["Project"] = Project; newMember["Group"] = newGroup.Name; newMember["E-mail Address"] = member.Email; if (profileManager.UserExists(userName)) { UserProfile profile = profileManager.GetUserProfile(userName); newMember["Business Phone"] = profile["BusinessPhone"].Value; newMember["Mobile Phone"] = 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();
关闭
EventHandler
this.DisableEventFiring();//关闭EventHandler,防止多重触发 //save changes addedItem.Update(); this.EnableEventFiring();
workflowProperties.OriginatorUser得到当前workflow instance的发起者
workflowProperties.Item不就可以直接拿到SPListItem
SharePoint中访问AD
System.DictionaryService