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. PHP的命名空间 与类是自动加载

    namespace 假设如果不使用namespace,那么每个类在一个项目中的名字就必须是固定的.因为php在new的时候不管是调用autoload还是调用已加载过的类,都存在一个类名对应的文件.所以 ...

  2. 3D场景定位的一些资源

    利用多张影像对小物体进行拍摄,进而进行三维重建,是计算机视觉中的重要问题之一. 目前对此研究最全面的网站是:http://vision.middlebury.edu/mview/eval/ 目前最优秀 ...

  3. 用JMeter进行Performance Test

    用JMeter可以对Http请求进行Performance Test,来分析哪些方法花费的时间多,哪些方法花费的时间少,有了这样的分析结果后,我们就可以集中力量来改进费时的方法. 官方文档请参考如下链 ...

  4. Can't find PHP headers in /usr/include/php

    解决办法: yum install php-devel

  5. ASP.NET 你必须知道的EF知识和经验

    原文:http://www.cnblogs.com/zhaopei/p/5721789.html

  6. Codeforces Round #363 (Div. 2)

    A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...

  7. 浏览器User-agent简史(user-agent)

    In the beginning there was NCSA Mosaic, and Mosaic called itself NCSA_Mosaic/2.0 (Windows 3.1), and ...

  8. win10 系统怎么获取最高管理员权限删除文件

    http://www.xitongcity.com/jiaocheng/win8_content_3473.html 很多win8.1系统用户在对磁盘文件进行清理时,经常会遇到“文件夹访问被拒绝,您需 ...

  9. MYSQL的常用命令和增删改查语句和数据类型【转】

    连接命令:<a href="http://lib.csdn.net/base/mysql" class='replace_word' title="MySQL知识库 ...

  10. webform 简单控件

    html中12个表单元素添加runat="server"后称为控件 Lable 编译之后是 <span></span> 属性:CssClass  编译成 c ...