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的更多相关文章

  1. 安装InfoPath 2013后 SharePoint 2010 出现 “找不到 Microsoft.Office.InfoPath, Version=14.0.0....” 的错误的解决方案

    1. 症状 您的SharePoint 2010的服务器是不是最近一直出现这个错误呢? Could not load file or assembly 'Microsoft.Office.InfoPat ...

  2. 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 ...

  3. 创建SharePoint 2010 Timer Job

    好久没有写博客了. 近期在使用SharePoint 2010中Timer Job的功能,有了一点心得,分享一下. 我个人觉得SharePoint Timer Job和Windows Service或者 ...

  4. “Stamping” PDF Files Downloaded from SharePoint 2010

    http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2 ...

  5. Upgrading or Redeploying SharePoint 2010 Workflows

    While creating several State Machine SharePoint 2010 workflows using visual studio for a client I ha ...

  6. SCOM Visio监控 与sharepoint 2010 整合

    激活sharepoint 2010的企业版网站功能 在sharepoint 前端服务器安装:OpsMgrDataModule.msi,安装好后可以看到如下东东: 在Sharepoint前端服务器中启动 ...

  7. How to tune SharePoint 2010 Server for better performance?

    http://social.technet.microsoft.com/wiki/contents/articles/7926.sharepoint-2010-tips-for-dealing-wit ...

  8. 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 ...

  9. SharePoint 2010 master page 控件介绍(3) :页面主体内容

    转:http://blog.csdn.net/lgm97/article/details/6409217 <!-- =====  页面滚动区域开始  ====================== ...

随机推荐

  1. singleton pattern的推荐实现

    一.单例模式的C#实现: (1)使用double-checked locking的方式: public sealed class Singleton { private static volatile ...

  2. 转载:稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB

    http://www.cnblogs.com/xbinworld/p/4273506.html 稀疏矩阵是指矩阵中的元素大部分是0的矩阵,事实上,实际问题中大规模矩阵基本上都是稀疏矩阵,很多稀疏度在9 ...

  3. [转]Mac OS X El Capitan(10.11)显示隐藏文件命令失效解决方法

    在Mac全新的系统El Capitan中,原先的显示系统中所有的隐藏文件的指令似乎失效了,只有重启以后才能显示,其实还有一个更简单的办法: 先在终端输入: defaults write com.app ...

  4. xcode下载

    http://adcdownload.apple.com/Developer_Tools/Xcode_7.3.1/Xcode_7.3.1.dmg http://adcdownload.apple.co ...

  5. 关于HTML的FORM上传文件问题

    首先,大家可以测试后一段代码 <form id="form1" runat="server"> <input type="file& ...

  6. Android测试之 APK重签名方法

    方法一:命令行重签名 D:\>keytool -helpkeytool 用法: -certreq [-v] [-protected] [-alias <别名>] [-sigalg & ...

  7. Bulk_Collect 调用方式集锦

    事先申明,本文所有示例都皆源于<Expert PL SQL Practices>这本电子书的第六章.小陈觉得在学习PLSQL的过程中,将来或许会用到,在此笔记一番. 正文如下: 首先准备基 ...

  8. 二十四点算法 java实现

    问题: 给出四个数,不可以重复使用,可以用+ - * /和括号,怎么得出24? 代码: //return -1 表示当前方法不行 private int workByStep(int op,int n ...

  9. Javascript并发模型和事件循环

    Javascript并发模型和事件循环 JavaScript的"并发模型"是基于事件循环的,这个并发模型有别于Java的多线程, javascript的并发是单线程的. Javas ...

  10. C#_Express-ickd接口

    爱查快递接口使用 using System; using System.Collections.Generic; using System.IO; using System.Net; using Sy ...