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

    Netty的ChannelPipeline和ChannelHandler机制类似于Servlet和Filter过滤器,这类拦截器实际上是职责链模式的一种变形,主要是为了方便事件的拦截和用户业务逻辑的定 ...

  2. DataTable.RowFilter 用法

    /// <summary> /// 处理DataRow筛选条件的特殊字符 /// </summary> /// <param name="rowFilter&q ...

  3. 【JAVA】JDK -Calendar 遇到的 一个坑

    Calendar是JDK 1.1增加的类 最近使用了下Calendar发现几个很让人抓狂的问题 源码: public final static int SUNDAY = 1; public final ...

  4. jQuery 利用 parent() parents() 寻找父级 或祖宗元素

    $(this).parent().parent().parent().parent().parent().remove(); //此方法通过parent()一级一级往上找   $(this).pare ...

  5. Tickets——H

    H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...

  6. phpcmsv9 阿里云OSS云存储整合教程

    该教程算不上是phpcmsv9阿里云oss插件,所以整个修改及其代码覆盖前请一定记得备份.还有一点就是后台发布文章时上传的附件还是会保存在你的服务器上,基于以下原因:1.个人的需求是前台页面需要使用t ...

  7. jQuery插件入门

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"),("#"),("."),写了几年就对别人说非常熟悉JQ ...

  8. ZK 页面间参数传递

    1.execution.sendRedirect(url) 当使用方法execution.sendRedirect(url)进行页面跳转时,在url中添加参数:url?test=5: 跳转页面获取参数 ...

  9. mysql 定时任务

    mysql 5.1以上支持定时任务. SHOW VARIABLES LIKE 'event_scheduler';   检查是否已开启该功能 开启计划任务功能: SET GLOBAL event_sc ...

  10. dup和dup2用法小结

    今天和同学探讨了一下关于重定向输出到文件的问题,其中需要用到dup和dup2函数,因此来小小的总结一下. 首先来man一下: dup直接返回一个新的描述符和原来的描述符一样代表同一个资源,描述符的值就 ...