Copying Documents With Version History

Hello,
I am working on a ribbon button for SharePoint 2013 with which users (with contribute permissions) can open a dialog to move selected documents to a different library (with the same content type) and enter soms Metadata to be set for the document.
One of the requirements for this is that the version History should be copied along with the document. Of course I googled for some code that allready does what I want to do and i stumbled upon this blog:
http://sharepointvenividivici.typepad.com/sharepoint-customization/2011/06/maintain-file-version-history-when-movingcopying-files-between-sharepoint-sites.html
Because this code also sets the modified and created information for the document the code runs under elevated priviliges because the users do not have the rights to modify that data.
At first this seemed to be the perfect solution, but after a while we found something truly annoying. The first time you copy the document it works perfectly and the document including version history is being transferred. But the second time the document
does get copied with the version history but in the version history the modified by is set to System Account for every version.
Does anyone know what can cause this?
After doing some more digging, I believe that the problem lies with the following function
SPFile fileDest = libDest.RootFolder.Files.Add(
                 urlDestFile,
                 streamFile,
                 hashSourceProp,
                 userCreatedBy,
                 userModifiedBy,
                 dateCreatedOn,
                 dateModifiedOn,
                 strVerComment,
                 true);
This function apparently sets the Created, Created By, Modified and Modified By properties to the values you provide, but when you later try to read this properties with code you get the userwith which you ran the code and not the user you provided. Does
anyone know a way to fix this?

Hi,
According to your post, my understanding is that you wanted to copy documents with version history.
I had written a simple demo to copy files to another library, and modified the code as below,  you can refer to the following code snippets to check whether it works.
public static void CopyFileWithVersion()
using (SPSite site = new SPSite("YourSiteURL"))
using (SPWeb web = site.OpenWeb())
SPList sourceLib = web.Lists["Lib1"];
SPList DestinationLib = web.Lists["Lib2"];
SPListItem itemSource = sourceLib.GetItemById(2);
SPFile fileSource = itemSource.File;
SPUser userCreatedBy = fileSource.Author;
DateTime dateCreatedOn = fileSource.TimeCreated.ToLocalTime();
//Get the versions
int countVersions = itemSource.File.Versions.Count;
for (int i = 0; i <= countVersions; i++)
Hashtable hashSourceProperties;
Stream streamFile;
SPUser userModifiedBy;
DateTime dateModifiedOn;
string strVersionComment = "";
bool bolMajorVerison = false;
if (i < countVersions)
SPFileVersion fileSourceVerison = itemSource.File.Versions[i];
hashSourceProperties = fileSourceVerison.Properties;
userModifiedBy = (i == 0) ? userCreatedBy : fileSourceVerison.CreatedBy;
dateModifiedOn = fileSourceVerison.Created.ToLocalTime();
strVersionComment = fileSourceVerison.CheckInComment;
bolMajorVerison = fileSourceVerison.VersionLabel.EndsWith("0") ? true : false;
streamFile = fileSourceVerison.OpenBinaryStream();
else
userModifiedBy = fileSource.ModifiedBy;
dateModifiedOn = fileSource.TimeLastModified;
hashSourceProperties = fileSource.Properties;
strVersionComment = fileSource.CheckInComment;
bolMajorVerison = fileSource.MinorVersion == 0 ? true : false;
streamFile = fileSource.OpenBinaryStream();
string urlDestinationFile = DestinationLib.RootFolder.Url + "/" + fileSource.Name;
SPFile fileDestination = DestinationLib.RootFolder.Files.Add(
urlDestinationFile,
streamFile,
hashSourceProperties,
userCreatedBy,
userModifiedBy,
dateCreatedOn,
dateModifiedOn,
strVersionComment,
true);
SPListItem itmNewVersion1 = fileDestination.Item;
itmNewVersion1["Created"] = dateCreatedOn;
itmNewVersion1["Modified"] = dateModifiedOn;
itmNewVersion1.UpdateOverwriteVersion();
Thanks,
Jason
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Jason Guo
TechNet Community Support

Similar Messages

  • List items archival with version history using powershell

    HI
    Is there any way to work with site and content structure in SharePoint 2010 with power-shell.
    I want to run a automated task(power shell script) to move list items from source to destination in the same site with version history.
    I know i can do it from site and content organizer but i have to do manually and SharePoint designer workflows doesn't retain the version history.
    Please give me  your valuable tips.

    Hi Manikanta,
    Archive ListItem with Version History in SharePoint, I suggesting you the best links for your solution here
    http://techno-sharepoint.blogspot.sg/2012/10/moving-sharepoint-list-items-to-archive.html
    http://get-spscripts.com/2011/10/copy-sharepoint-lists-and-document.html
    For more details, reach us at
    <a href="http://staygreenacademy.com/sharepoint-2013-training/">SharePoint 2013 Online Training</a>

  • Issue related to "Document Set Version History" option for Video uploaded in Asset library

    Hi,
    When user clicks on ‘Document Set Version History’ option from context menu (ellipsis) of a particular video, ‘Sorry, something went wrong’ message is shown. The error message also says,
    versions are currently disabled for this document library.
    When we enabled version history for the video library, the functionality started working as expected.
    Ideally the context menu of video should not show ‘Document Set Version History’ option. But we are not sure why it is showing that option.
    Can anybody please explain, is it bug in sharepoint ? or any other approach we have to use.

    Hi Sanket,
    We need to configure the send to connections for the corresponding web application in Central Administration and then the locations will be available when clicking the Send To Other Location.
    Please go to Central Administration > General Application Settings > Configure send to connections.
    After configuring the send to connections for the web application where you need to use the Send To Other Location, the location will be available.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Can't open version 3 documents with version 5

    Hello,
    My company didn't upgrade me to version 4 so I'm trying to open my version 3 .cp files with version 5. Every time I try to open one, it crashes.
    I'm using a different computer (still Windows XP, though) than I had when I last used the version 3 files and am accessing them on a remote server via VPN.
    Any ideas? I've tried restarting my computer when it doesn't open and looking for a version 4 to download so I can try opening it that way, saving it, and then opening it in version 5, but I haven't had any luck so far.
    Thanks for your help,
    Elaine

    Hi Elaine
    I see this is your second post here in the forums. So it occurs to me that you may be unaware of one of Captivate's "golden rules" that help keep you out of trouble.
    That rule?
    always, Always, ALWAYS work with projects ONLY when you have them stored on your local C drive.
    never, Ever, NEVER EVER consider opening Captivate, then clicking File > Open and navigating to a network drive and try to make edits while the project is on a network.
    Sometimes your IT peeps will help you aim the shotgun squarely at your leg and tell you to pull the trigger. They want you to work with your files on the LAN because their precious servers are backed up and your local hard drives typically aren't. It's perfectly fine to store your projects on the LAN if the only purpose is for backup. So consider copying the projects there at the end of each day to satisfy those backup requirements.
    Cheers... Rick
    Helpful and Handy Links
    Begin learning Captivate 5 moments from now! $29.95
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcererStone Blog
    Captivate eBooks

  • How to know whether file is modified or metadata from SharePoint Document Library version history

    I have uploaded a document in document library. I am writing code to retrieve the items from the library only if document is modified, not the metadata.
    So if for an item only metadata is modified then it should not come, if document is modified then it should come. I tried from version history but it doesnt work. Any idea?
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

    Each file has an associated SPListItem which contains the metadata. See if the SPFile.TimeLastModified reflects the file and not the metadata.
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.timelastmodified.aspx
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Managing signature page on a document with revision history

    We are trying to migrate our drawing approval process from paper to digital using PDF's digital signatures.  To release a version of a document, we need 3 sign-offs (creator, checker, approver).  This was straightforward to implement using the digital signatures form field.  All signatures reside on a signature appendix page that gets appended to the end of the PDF document we want to sign-off.
    When we want to release the next revision of the document, we again need all 3 sign-offs, but we want to include the previous signature history.  We understand that the earlier signatures will be invalid, but it is important for us to be able to print the signature appendix showing the full change history.  We thought we'd be able to copy the signature page from the released PDF to the new revision, but when we copy this, the signature fields are blank.
    Is it possible to achieve this functionality?

    I need to create something similar to this.  Did you find a solution?

  • SharePoint 2013 - Document Set Capture Version History. Does each version captured for each document set keep a copy of all the document stored in the document set?

    Hi All,
    We have currently encountered an issue where even though version control is turned on in a document library, changes made to the metadata of a document set is not tracked in a version history. 
    We have found that in order to this a user will need to manually click on the capture version history button. 
    With this in mind, we are concerned about the impact of this on our storage. The question we have been trying to answer is whether each document set version:
    stores the change in metadata of the document set and a copy of all the documents stored in the document set
    stores the change in metadata of the document set and a reference to the documents stored in the document set (making use of SharePoint 2013's shredded storage)
    The reason we ask this is that if a document set version stores a copy of all the document stored in a document set, a change in one of the fields in the document set could result in the storage used to grow exponentially. e.g. if the document set contains
    documents totaling 30MB, and if we have 10 versions of the document set, we could take up 300 MB in the content database for just one document set.
    We have tried to some searching around Google but wasn't able to find any answers around this question. Would appreciate some assistance from anyone who has knowledge around how document set version history works. 
    Thanks in advance.
    John

    i had a long thing written out, but submit failed.  suffice to say it does "2".  it only stores the changes with pointers to the documents. 
    Christopher Webb | Microsoft Certified Master: SharePoint 2010 | Microsoft Certified Solutions Master: SharePoint Charter | Microsoft Certified Trainer| http://tealsk12.org Volunteer Teacher | http://christophermichaelwebb.com

  • Document set items Version history

    Hi,
    I'm trying to to retrieve document set version history. here i need to retrieve all modified versions of a document in document set ? Can any body help?
    I have tried but didnt find anyway .. how to get version history of a document in document set.
    Thanks in advance.
    SPSite site = SPContext.Current.Site;
    SPWeb web = site.OpenWeb();
    string ver = web.Url + "/" + sharedDocs;
    //Get the selected document
    SPListItem listItem = SPContext.Current.Web.Lists["Contract Documents"].GetItemById(99);
    if (listItem.FileSystemObjectType == SPFileSystemObjectType.Folder)
    //Get the folder
    SPFolder myFolder = listItem.Folder;
    //Make sure the folder has items
    if (myFolder.ItemCount > 0)
    //For each item get the document name
    foreach (SPFile item in myFolder.Files)
    string name = item.Name;
    foreach (SPListItem vh in myFolder.Files)
    SPListItemVersionCollection coll = vh.Versions;
    foreach (SPListItemVersion version in coll)
    var VersionLabel =version.VersionLabel;

    No Jenkis,, No thats my fault.. I forgot to add code below.
    And I have tried the below code which is fine getting versions but it is not retrieving current version.
    My case, i have a document with versions 1.0, 1.1 but here 
    filecollection.Count is showing 1. that is 1.0 version. Is any other way to get current version?
    SPSite site = SPContext.Current.Site;
    SPWeb web = site.OpenWeb();
    //Get the selected document
    SPListItem listItem = SPContext.Current.Web.Lists["Contract Documents"].GetItemById(99);
    if (listItem.FileSystemObjectType == SPFileSystemObjectType.Folder)
    //Get the folder
    SPFolder myFolder = listItem.Folder;
    //Make sure the folder has items
    if (myFolder.ItemCount > 0)
    //For each item get the document name
    foreach (SPFile item in myFolder.Files)
    string name = item.Name;
    SPFileVersionCollection filecollection = item.Versions;
    if (filecollection.Count > 0)
    foreach (SPFileVersion v in filecollection)
    var VersionLabel =v.VersionLabel;
    Thanks in advance.

  • How to move offline files to sharepoint with same version history

    Hi,
    We have downloaded some of the file from sharepoint in our computer, now we have migrated the site to 2013 from 2010.
    Can we upload the offline files to new site with version history maintained.
    tks,
    vidhu

    I am not sure you can do this OOTB, either you need custom development or 3rd party tools.
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

  • SharePoint Document Set Version Extension

    Before reading further, please note this is not a simple 'how do I enable versioning' and, as far as I can tell, nothing similar has been asked before...
    Instead I am looking for any solutions (3rd party or OOTB) or novel suggestions for an extension to document set versions so that users are presented with a friendlier user interface than the default version history dialogue that we all know and love.  
    This is a very specific request from a senior stakeholder at my company who requires the highlighting/comparison of document set versions in which we are already displaying a custom ASPX page of properties and lookups against other data in the site. The
    user has previously used (and most likely prefers) the Atlassian Confluence offering (https://www.atlassian.com/software/confluence) which provides such functionality.
    So far I have explored the following no code solutions:
    Allowing users to track their own changes through Word and then uploading the document to the correct document set. This is not an option due to the number of clicks users have to navigate through and the loss of centralised tracking etc. through the doc
    set properties
    Providing users with the ability to mark their changes in the document set with rich text highlighting (has to be enabled through SPD for document sets) which was initially promising but places the reliance on users to remember to highlight changes correctly.
    I have also noticed a frustrating feature with version control which, in the history dialogue box, properties with a large number of characters (we have extended most fields to be greater than 250 - I know this is probably not recommended but needed to be
    done) are clipped so that the entire field is not visible. Through PowerShell I can see that the values are fully stored in the Snapshot Collection for each document set.
    Currently, I am working on the assumption that this is the only way to access version history and a custom server side solution (CSOM doesn't seem to expose these properties) will be the only option going forward. Ideally a no-code option (especially not
    server side) would be preferable so reaching out to you wonderful experts for some insights.
    Really appreciate any responses...

    Hi,
    Based on your description, my understanding is that you want to make the Document Set Version history with a friendlier user interface than the default version history dialogue.
    SharePoint seems to only expose the Document Set's metadata version in the "Version" column. I call this the metadata version because this will only increase if you make changes to the document set's properties, and not if you update the documents
    inside. This is what I mean by metadata version.
    In the Document Set Version history,  the first column displayed is No. This is not the regular version column of the library, but a totally different one. When creating a document set version the version column of the library doesn’t change,
    only the No value.   
    The version(s) of a document set are stored in the propertybag of the item itself. 
    Take a look at this article about how to retrieve document set version history:
    http://www.itidea.nl/index.php/how-to-retrieve-document-set-version-history/
    Best Regards,
    Lisa Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Lisa Chen
    TechNet Community Support

  • Get the Version history of a sharepoint 2013 Custom List item

    Hi All,
    I am having doubt to retrieve the field version information with the comments.
    For this field i am done like this
    1.Creating a custom list
    2.And enable versioning for the list
    3.And add a field with field type 'Multiple Lines of Text' and in the Addition Column Settings section 'select yes radio button option in 'Append changes to the Existing text'.
    4.If we done like this the changes to the list item are available outside of field control.
    Can any one help me regarding this field to get the all the versions of list item along with modified data.

    hi Asatish,
    Thanks for posting your issue, Kindly browse the below mentioned URLs to know about the fixes of this issue
    http://berg-henry.blogspot.in/2010/11/custom-list-form-with-version-history.html
    http://somnathmatere.blogspot.in/2013/10/sharepoint-2010-custom-display-form.html
    http://blog.qumsieh.ca/2009/01/29/understanding-the-append-changes-to-existing-text-option/
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • Automatically open document with Pages 5

    When I upgraded from Pages 4.3 to 5x, documents were automatically set by the installation to all open with version 5.0.x . Due to some initial problems with Pages 5, I changed the setting so that Pages 4.3 opened all documents. I did that by command-i, get info, open with Pages 4.3, and change all.
    Now I want to default back to opening with pages 5.0.1, but if I do the same procedure (command-i, get info, open with Pages 5, and change all), Pages is still opening documents with version 4.3.

    All Pages files no matter what version and incompatibility have the same extension .pages.
    That makes it impossible to get the System to stick with a choice in Finder.
    Trash/archive whichever one you don't want.
    Peter

  • Flattening documents with annotations

    I'm trying to flattening a PDF document with annotations using the transformPDF service method (OutputService). Unfortunately all annotations are lost after flattening the PDF document.
    The reason why we want to achieve this is that we want to ensure PDF version 1.5 compatibility. However, generating documents and importing annotations with LCES Output AssemblerService produces PDF documents with version 1.6 or higher although all source documents are compatible with PDF version 1.5...
    I'm thankful for any hint...
    Nico

    You may also want to have a look at the online quick starts at:
    http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_Output.12.12 .html

  • BAPI_DOCUMENT_CREATE2 problem with copying document-version

    Hi experts!
    I want to copy Documents from one Sap-System to another via RFC.
    So I read the documents in the source-system with 'BAPI_DOCUMENT_GETDETAIL2' via RFC. then I want to insert the documents received in the target-system with BAPI_DOCUMENT_CREATE2.
    The result is that from a document all part-documents are been copied, but only one (the first) version of a document-part.
    my coding:
    ... for reading the documents
        CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
             DESTINATION p_rfcdst
          EXPORTING
            documenttype               = gs_draw-dokar
            documentnumber             = gs_draw-doknr
            documentpart               = gs_draw-doktl
            documentversion            = gs_draw-dokvr
            getobjectlinks             = 'X'
            getcomponents              = 'X'
            getstatuslog               = 'X'
            getlongtexts               = 'X'
            getactivefiles             = 'X'
            getdocdescriptions         = 'X'
            getdocfiles                = 'X'
            getclassification          = 'X'
            getstructure               = 'X'
            getwhereused               = 'X'
        HOSTNAME                   = ' '
          IMPORTING
            documentdata               = gs_doc_data
            return                     = gs_return_get
          TABLES
            objectlinks                = gt_obj_links
            documentdescriptions       = gt_doc_desc
            longtexts                  = gt_long_texts
            statuslog                  = gt_status_log
            documentfiles              = gt_doc_files
            components                 = gt_comp
            characteristicvalues       = gt_char_val
            classallocations           = gt_class_alloc
            documentstructure          = gt_doc_struc
            whereusedlist              = gt_where_used.
    my coding:
    ... for creating the documents
      CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
        EXPORTING
          documentdata         = gs_doc_data
        IMPORTING
          documenttype         = gs_create-dokar
          documentnumber       = gs_create-doknr
          documentpart         = gs_create-doktl
          documentversion      = gs_create-dokvr
          return               = gs_return_create
        TABLES
          characteristicvalues = gt_char_val
          classallocations     = gt_class_alloc
          documentdescriptions = gt_doc_desc
          objectlinks          = gt_obj_links
          documentstructure    = gt_doc_struc
          documentfiles        = gt_doc_files
          longtexts            = gt_long_texts
          components           = gt_comp.
    Result:
    eg. - Source Document
    Document   AUF/N4711/xxx/xx
    Part      Version    Status      Description
    010       00           FR           Cond.-010-00
    011       00           FR           Cond.-011-00
    011       01           FR           Vers-011-01
    011       02           FR           Vers-011-02
    012       00           FR           Cond.-012-00
           Target Document
    Document   AUF/N4711/xxx/xx
    Part      Version    Status      Description
    010       00           FR           Cond.-010-00
    011       00           FR           Cond.-011-00
    012       00           FR           Cond.-012-00
    Is there only the possibility to create one version of a document with BAPI_DOCUMENT_CREATE2 ?
    Thanks in advance for helping me!
    Franz

    Hi Avinash,
    a
    Thanks for the reply.
    I am able to create document number in IDES system. I am getting error development system while creating document number with the FM. Configuration settings and the test data are same for both IDES and Dev. system.
    What could be the problem and how to rectify it.
    Regards
    SP Raj

  • Sharepoint 2013 Document library view show version history

    Hello everyone,
    I have a document library view with many folders. Each folder is a procedure and have document attached to it.
    When I add a new version, I would like to show version history for each document contained in the folder. For example:
    There is a folder Procedure 123 which has three files ( File1, File2, and File3). After a week the user the user created new revisions for each document.
    I would like to have a document view with the following information
    File Name   version
    ======  ======
    File 01         0
    File 02         0
    File 03         0
    File 01         1
    File 02         1
    File 03         1
    File 01         2
    File 02         2
    File 03         2
    Thanks for your help.
    Jhonny Marcelo

    This is quite simple, you have to modify the current view (Modify this view) of document library and then you can select version column from available column list (make sure version is enabled). please check below picture for detail.
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer.

Maybe you are looking for

  • Can't see data in InfoSet

    All, I'm having an issue with several InfoSets that I created. When I first created the InfoSets I was able to view data with not problem. But now that I've loaded some new data and in some cases completely reloaded all of the data to my InfoProvider

  • How to hook DVI screen to ThunderBolt MBPro?

    I have an old but beautiful CinemaDisplay HD 23" with ADC connection, I bought back then an ADC to DVI converter when I upgraded the video board of my old PowerMac G4, now I'd like to reutilize the screen with my MBPro 15" early 2012 which has a thun

  • Imac crashes while downloading mountain lion

    The first two times I downloaded Mountain Lion, the download was successful, but it would not install. I got the "lion application cannot be verified" message as the installer was loading. So, I went online and found someone suggested going into safe

  • Program download

    Greetings all you ABAP guru's, My question is simple......is there a std program I can use to download all the customer specifc abap programs and thier related coding i.e. all the Z programs ????? Thanks Mark

  • Shared Services, using openldap to query MSAD

    Hello, I would like to know if this is possible to configure. I would like to setup an openldap server and use that to query MSAD. Shared Services would have a connection to that openldap server and the openldap server would query MSAD and in return