{
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. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  2. Drop user 报ORA-00600 [KTSSDRP1]

    一客户删除一个数据库用户THH时报错: 说明在获取seg$时没有找到相应的条目,先来解释下这个600错误的参数含义: Arg [a] Tablespace number Arg [b] File nu ...

  3. kindeditor使用记录

    --------------------------资源 百度下载包  kindeditor-4.1.11-zh-CN 解压后根据需要选择asp / asp.net / jsp / php 文件夹之一 ...

  4. lintcode - 房屋染色

    class Solution { public: /* * @param costs: n x 3 cost matrix * @return: An integer, the minimum cos ...

  5. NAS与SAN RAID

    存储区域网络 SAN 存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通道)技术,通过FC ...

  6. Paw —— 比Postman更舒服的API利器

    特点: 颜值高本地应用,流畅有收藏夹,管理请求可使用环境变量.比如用来一键切换开发环境请求和线上环境请求.即不同环境的同个接口只有host不一样,其它都是一样的,所以就把host抽离出来弄成一个环境变 ...

  7. js input复选框选中父级同时子级也选中

    js实现复选框选中父级元素子级元素也选中,没有子级元素选中父级也不选中的效果 HTML <tr> <td> <label> <input name=" ...

  8. Message Unable to connect to SQL Server '(local)'

    最近在sql server 加了一些job,但是run job的时候发生了一下错误: ssage Unable to connect to SQL Server '(local)' 问题根源:调用 T ...

  9. drop_caches控制page cache

    drop_caches Writing to this will cause the kernel to drop clean caches, as well as reclaimable slab ...

  10. 硬盘和显卡的访问与控制(一)——《x86汇编语言:从实模式到保护模式》读书笔记01

    本文是<x86汇编语言:从实模式到保护模式>(电子工业出版社)的读书实验笔记. 这篇文章我们先不分析代码,而是说一下在Bochs环境下如何看到实验结果. 需要的源码文件 第一个文件是加载程 ...