{
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>" +

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这页面是维护页面

超链接或图片类型栏的值,对应的对象模型为SPFieldUrlSPFieldUrlValue,可以这样读取:

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字段,特别方便,暂时没发现出错误~

SharePointLookUp字段的使用

赋值

如何在代码中使用lookup字段

 
   

对于lookup字段在可视界面时,感觉挺方便,但是在写代码的时候,对它进行赋值的时候,就感觉很麻烦。不知道哪位高手对这个赋值有更好的方法,谢谢。
方法一(听11同学说的)
SPFieldLookupValueCollection lookupValues;

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

lookupValues.Add(new SPFieldLookupValue(1, "SomeLookupValue"));
listItem["MyLookupField"] = lookupValues;

listItem.Update();

这方法感觉赋值就是受罪,写这么多代码。
方法二。直接用
listItem["MyLookupField"] =1,2,3
但这此方法要知道字符串所对应的Id。,有什么最有效的方法。。请教高手

实际使用如下代码(经过测试):

 

                                 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;

LookUpUser读取

    如果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

sharepoint知识点总结的更多相关文章

  1. Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录

        Sharepoint学习笔记—习题系列--70-576习题解析  为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是:     1. ...

  2. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q142-Q143)

    Question 142You have a Feature that contains an image named ImageV1.png.You plan to create a new ver ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q128-Q130)

    Question  128 You are designing a SharePoint 2010 solution that includes a custom site definition an ...

  4. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q116-Q120)

    Question  116 You are helping a corporate IT department create a SharePoint 2010 information archite ...

  5. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q112-Q115)

    Question  112 You are designing a public-facing SharePoint 2010 Web site for an elementary school th ...

  6. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q105-Q108)

    Question  105   You are designing a SharePoint 2010 application that contains a single list named Us ...

  7. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q99-Q101)

    Question  99 You have designed a new SharePoint 2010 Web Part that was deployed to the testing envir ...

  8. 无废话SharePoint入门教程四[创建SharePoint母版页]

    一.前言 文章成体系,如果有不明白的地方请查看前面的文章. 二.目录 1.创建HTML页面 2.将HTML文件转换为SharePoint母版页 3.在 SPD中修改母版页“PlaceHolderMai ...

  9. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q1-Q3)

    这里我把从网上搜集到的针对Sharepoint 70-576的有关练习进行系统的解析,整理成一个系列, 分期.分批次共享出来,供大家研究. 70-573考试注重的是"知道"相关知识 ...

随机推荐

  1. shell学习(12)- jq

    jq命令允许直接在命令行下对JSON进行操作,包括分片.过滤.转换等 ,jq是用C编写,没有运行时依赖,所以几乎可以运行在任何系统上.预编译的二进制文件可以直接在Linux.OS X和windows系 ...

  2. APP设计规范

    设计师DPI指南 本指南旨在为初级到中级设计人员提供“入门”或介绍性阅读,他们希望从一开始就学习或获得有关跨DPI和跨平台设计的更多知识. 尽可能少的数学和没有不可解析的图形,只需在简短的部分中订购直 ...

  3. react 中文文档案例四 (登陆登出按钮)

    import React from 'react'; import ReactDOM from 'react-dom'; class LoginControl extends React.Compon ...

  4. powdesigner建表

    默认打开powerDesigner时,创建table对应的自动生成sql语句没有注释. 方法1.comment注释信息 在Columns标签下,一排按钮中找到倒数第2个按钮:Customize Col ...

  5. 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_8.1实例构造器和类A

    public class SomeType { } //等价于 public class SomeType { public SomeType():base(){} } [解释]如果定义的类没有显示定 ...

  6. APP微信支付实现

    参考官方文档 设计到的API: 统一下单API.支付结果通知API和查询订单API 下面代码是请求预支付ID // 构建下单bean final WxPayUnifiedOrderBean unifi ...

  7. Eclipse + Git + 码云

    1. 进入码云个人首页 点击自己的名称即可 2. 添加一个项目 3. 在Eclipse中创建一个本地Git Eclipse不建议git目录创建在项目的目录下,因此另选一个目录作为本地Git目录 选择一 ...

  8. Subarray Sum K

    Given an nonnegative integer array, find a subarray where the sum of numbers is k. Your code should ...

  9. (转)轻松应对IDC机房带宽突然暴涨问题

    原文:http://blog.51cto.com/oldboy/909696

  10. linux shell 将多行文件转换为一行

    说实话,虽然对shell编程包括awk有所了解,但是对sed的多行与一行的处理还是不甚理解,在网上搜罗了一篇文章觉得还不错,记录一下: 今天一个工程师问我,怎么将一个文件中的多行转换成一行. 我给出了 ...