[SharePoint 2010] Copy list item with version history and attachment
private void MoveItem(SPListItem sourceItem, SPListItem destinationItem)
{
if (sourceItem == null || destinationItem == null) return; destinationItem = GetDestinationItem(sourceItem.ID, destinationItem); SPFieldLookup lkpField = null;
SPFieldLookupValue lkpFieldVal=null;
object fieldVal = null;
SPUser systemAccount = destinationItem.Web.AllUsers["SHAREPOINT/system"];
SPWeb sourceWeb = sourceItem.Web;
SPWeb destWeb = destinationItem.Web; Log("-----Begin of handle item-----"); Log(string.Format("----------Source item [{0}/{1}]----------", sourceItem.Title, sourceItem.ID)); #region Handle version history for (var i = sourceItem.Versions.Count - ; i >= ; i--)
{
foreach (SPField sourceField in sourceItem.Fields)
{
SPListItemVersion version = sourceItem.Versions[i];
fieldVal = version[sourceField.InternalName]; Log(string.Format("----------Handle field[{0}/{1}]----------", sourceField.InternalName, sourceField.Type.ToString())); if (sourceField.Type == SPFieldType.User)
{
fieldVal = GetSPUserFromString(new SPFieldUserValue(sourceWeb, fieldVal.ToString()), destWeb);
Log(string.Format("----------user field[{0}/{1}]----------", sourceField.InternalName, fieldVal));
} if (sourceField.Id == SPBuiltInFieldId.Created ||
sourceField.Id == SPBuiltInFieldId.Created_x0020_By ||
sourceField.Id == SPBuiltInFieldId.Modified ||
sourceField.Id == SPBuiltInFieldId.Modified_x0020_By ||
sourceField.Id == SPBuiltInFieldId.Author ||
sourceField.Id == SPBuiltInFieldId.Editor)
{
destinationItem[sourceField.InternalName] = fieldVal;
}
else if (!sourceField.ReadOnlyField && sourceField.Type != SPFieldType.Attachments)
{
if (sourceField.Type != SPFieldType.Lookup)
{
destinationItem[sourceField.InternalName] = fieldVal;
}
else
{
lkpField = sourceField as SPFieldLookup; Log(string.Format("----------source field value[{0}]----------", fieldVal)); if (lkpField != null && fieldVal != null && fieldVal.ToString().Length > )
{
lkpFieldVal = new SPFieldLookupValue(fieldVal.ToString());
destinationItem[sourceField.InternalName] = lkpFieldVal;
}
}
}
} //update destination item
destinationItem.Update(); Log("----------End of handle field----------");
}
private SPListItem GetDestinationItem(int sourceItemID, SPListItem destinationItem)
{
SPList list = DestinationList; if (sourceItemID - CurrentItemID > )
{
for (int i = CurrentItemID + ; i < sourceItemID; i++)
{
SPListItem item = list.Items.Add();
item[SPBuiltInFieldId.Title] = "-1"; item.Update();
}
return list.Items.Add();
}
else
{
return destinationItem;
}
}
private SPUser GetSPUserFromString(SPFieldUserValue userVal, SPWeb web)
{
try
{
if (userVal != null)
return web.EnsureUser(userVal.User.LoginName);
else
return null;
}
catch
{
return null;
}
}
[SharePoint 2010] Copy list item with version history and attachment的更多相关文章
- 安装InfoPath 2013后 SharePoint 2010 出现 “找不到 Microsoft.Office.InfoPath, Version=14.0.0....” 的错误的解决方案
1. 症状 您的SharePoint 2010的服务器是不是最近一直出现这个错误呢? Could not load file or assembly 'Microsoft.Office.InfoPat ...
- Searching External Data in SharePoint 2010 Using Business Connectivity Services
from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...
- 创建SharePoint 2010 Timer Job
好久没有写博客了. 近期在使用SharePoint 2010中Timer Job的功能,有了一点心得,分享一下. 我个人觉得SharePoint Timer Job和Windows Service或者 ...
- “Stamping” PDF Files Downloaded from SharePoint 2010
http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2 ...
- Upgrading or Redeploying SharePoint 2010 Workflows
While creating several State Machine SharePoint 2010 workflows using visual studio for a client I ha ...
- SCOM Visio监控 与sharepoint 2010 整合
激活sharepoint 2010的企业版网站功能 在sharepoint 前端服务器安装:OpsMgrDataModule.msi,安装好后可以看到如下东东: 在Sharepoint前端服务器中启动 ...
- How to tune SharePoint 2010 Server for better performance?
http://social.technet.microsoft.com/wiki/contents/articles/7926.sharepoint-2010-tips-for-dealing-wit ...
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
转:http://msdn.microsoft.com/en-us/library/gg252010(v=office.14).aspx Summary: Learn how to create a ...
- SharePoint 2010 master page 控件介绍(3) :页面主体内容
转:http://blog.csdn.net/lgm97/article/details/6409217 <!-- ===== 页面滚动区域开始 ====================== ...
随机推荐
- [笔记]HTML
链接 <a href="链接地址">链接显示名</a> <a name="C4">target</a> < ...
- UWP 图片剪切旋转工具
好久没撸随笔了,明天终于放假休息了..准备去进行信仰充值,看<魔兽>去(话说surface phone 好久出,让我这个做UWP的也充点信仰..) 先上下效果图: 在设计中,遇到一个问题, ...
- 使用samba实现linux与windows共享(测试成功)
samba服务器搭建 实现linux与windows文件共享有很多种方法,诸如wpc,vmtools等,今天我来介绍我在rehat系统中实验成功并且现在在用的的方法,直接给出操作步骤: ...
- ubuntu更新软件源
更新源方法: 1. 打开终端.单击主菜单中的“应用程序 - 附件 - 终端”. 2. 修改更新服务器列表.请在终端中执行下面的两条命令: sudo cp /etc/apt/sources.list / ...
- 分布式缓存技术redis学习系列(一)——redis简介以及linux上的安装
redis简介 redis是NoSQL(No Only SQL,非关系型数据库)的一种,NoSQL是以Key-Value的形式存储数据.当前主流的分布式缓存技术有redis,memcached,ssd ...
- jQuery学习之:Validation表单验证插件
http://polaris.blog.51cto.com/1146394/258781/ 最近由于公司决定使用AJAX + Struts2来重构项目,让我仔细研究一下这两个,然后集中给同事讲讲,让每 ...
- 【转】ArrayList循环遍历并删除元素的常见陷阱
转自:https://my.oschina.net/u/2249714/blog/612753?p=1 在工作和学习中,经常碰到删除ArrayList里面的某个元素,看似一个很简单的问题,却很容易出b ...
- [Leetcode] Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- [BZOJ3139][HNOI2013] 比赛
Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各 ...
- 在list_*页面显示出一级栏目下的所有二级栏目
<ul class="nav nav-pills nav-stacked"> {dede:channelartlist typeid='1,1'} <div cl ...