[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 <!-- ===== 页面滚动区域开始 ====================== ...
随机推荐
- Pfile VS Spfile (MOS Note 249664.1)
============================================================================== Until Oracle 8i DBAs ...
- C#将数据大小字节转换为MB,GB,TB
http://www.myluoluo.com/c%E5%B0%86%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%E5%AD%97%E8%8A%82%E8%BD%AC%E6 ...
- IOC装配Bean(XML方式)
Spring框架Bean实例化的方式 提供了三种方式实例化Bean 构造方法实例化(默认无参数,用的最多) 静态工厂实例化 实例工厂实例化 无参数构造方法的实例化 <!-- 默认情况下使用的就是 ...
- Node.js学习之简介
1.简单的说Node.js就是运行在服务端的javaScript: 2.Node.js是一个基于Chrome javaScript运行时建立的一个平台: 3.Node.js是一个事件驱动I/O服务端J ...
- java-集合4
浏览以下内容前,请点击并阅读 声明 对象排序 一个List对象中如果元素类型为String,则其按字母表顺序排序,而如果元素类型为Date,则按照年代排序,那如何判断元素的排序呢?String和Dat ...
- Python for Informatics 第11章 正则表达式五(译)
注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 11.4 转义字符 之前我们在正 ...
- 【BZOJ1251】序列终结者 Splay
一道模板题,一直没发现自己的快速读入读不了负数,我竟然能活到现在真是万幸. #include <iostream> #include <cstdio> #define inf ...
- QProcess怎么实时的读到output的信息
在Qt里想与子程序通信, 一般都会用到QProcess这个类, 而且手册里也提到了很多通信的方法, 比如手册里的"Communicating via Channels". 我也不例 ...
- win10 install JDK&&JRE
重装系统后,安装的java环境没了,只能重装一下~~~~ 1.下载JDK 2.这里会安装两次,其中第一次为安装 JDK,第二次安装JRE,建议不要将这两个放在同一个文件夹. 3.配置环境变量 用鼠标右 ...
- PHP与apache环境配置
最近想了解一些网页后台的东西,在看Luke Welling,laura Thomson的<php与mysql web开发>,书中环境配置的部分很庞杂,网上的各种教程也很乱,搞了一下午终于成 ...