Writing modified date of a document library item through CSOM.

I´m working on an application which is replicating files from one document library to another. Since it is a replication, I want the modified date to be preserved when I copy the file from the source library to the target, so that the user will see the real
modified date in the target library and not the date of the replication run.
I access SharePoint through the client side object model and I have been able to set the modified date on a SharePoint 2010 on-premise using the following straght-forward code:
var listItem = list.GetItemById(id);
context.Load(listItem);
context.ExecuteQuery();
listItem["Modified"] = "03/11/1999";
listItem.Update();
context.ExecuteQuery();
Unfortunately when I execute the same code on any other SharePoint (2013 On-Premise, 2013 Online or 2010 Online) the code will execute without any errors, but the modified date will not be changed at all.
My actual question is: Is there any possibility to change the modified date throught CSOM on all of these SharePoint-versions?

I got a work around for this problem..
Before updating the Modified, Modified By values, First we need to Disable the version settings for document library. Once the fields updated then again we need to enable the version settings. 
find the updated code below..
                                      //Disable Version settings for DOC LIB
before update Metadata
                                        _List.EnableVersioning
= false;
                                        _List.Update();
                                        _cContext.ExecuteQuery();
                                       ListItem item = newFile.ListItemAllFields;
                                       _cContext.Load(item);
                                        //Updating Metadata Created,
CreatedBy, Modified, Modified By
                                         item["Created"]
= "8/10/2013 7:04 PM";
                                         item["Author"] = CreatedUserValue;
                                         item["Modified"] = "8/10/2013 7:04 PM";
                                         item["Editor"] = ModifiedUserValue;
                                         item.Update();
                                        _cContext.ExecuteQuery();
                                        //Enable Version settings
for DOC LIB after update Metadata
                                           _List.EnableVersioning
= true;
                                          _List.Update();
                                        _cContext.ExecuteQuery();
Rajendra

Similar Messages

  • How to extract audit log data from every document library in site collection using powershell?

    Hi All,
    I have n number of document library in one site collection,
    My query is- How to extract audit log data from every document library in a site collection using powershell?
    Please give solution as soon as possible?

    Hi inguru,
    For SharePoint audit log data, These data combine together in site collection. So there is no easy way to extract audit log data for document library.
    As a workaround, you can export the site collection audit log data to a CSV file using PowerShell Command, then you can filter the document library audit log data in Excel.
    More information:
    SharePoint 2007 \ 2010 – PowerShell script to get SharePoint audit information:
    http://sharepointhivehints.wordpress.com/2014/04/30/sharepoint-2007-2010-powershell-script-to-get-sharepoint-audit-information/
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • SharePoint 2013 : Add annotation to document library item

    Hi all,
    Is there a possibility to add annotation to library items. Example, I am sharing a document library item to a user then the user add an annotation and share to another user.  The other user also should add his/her comments on the item.
    Can anyone help me how to achieve this?
    Many thanks & regards
    Vinay

    We've done this in the past using a Rich Text Field in the metadata of the document.  You can set it up so it Appends new entries to the bottom of the field instead of replacing the existing content.  When a user edits the metadata they see a
    blank field.  When they save it their comments are added to the bottom with their name and a timestamp.  We've used it primarily on issues lists, but it should work on a document also.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Document Library + Items Color

    Hi All,
    Welcome to SharePoint products & Technologies.
    How to Change the color of the Document library items based on the field values? for eg., I have a column called "Status", based on this field values the color of the items should change accordingly.
    Can any one help me out on this issue.
    Let me know if you are not clear or need more information
    Regards,
    SpUser.

    Hi,
    Sorry for the late reply .Could not check the blogs.Here is the script to be put in content editor webpart:-
    <script language="javascript" type="text/javascript">
      var x = document.getElementsByTagName("td") // find all of the TDs
      var i=0;
      for (i=0;i<x.length;i++)
        if (x[i].className=="ms-vb2") //find the TDs styled for lists
          if (x[i].innerHTML=="In Process")
            x[i].parentNode.style.backgroundColor='lightyellow'; // set the color
    if (x[i].innerHTML=="Accepted")
            x[i].parentNode.style.backgroundColor='lightgreen'; // set the color
    if (x[i].innerHTML=="Not Accepted")
            x[i].parentNode.style.backgroundColor='red'; // set the color
    if (x[i].innerHTML=="Need More Info")
            x[i].parentNode.style.backgroundColor='lightblue'; // set the color
      } </script>

  • How to set Document Library Item Limit at Site Collection level?

    Hi,
    I have SharePoint which contains one Site collection with many Sites. Each sites has many document library.
    Actually my requirement is, End Users  wants to see only 10 items per page in document library. We can manually set by using "Item Limit" option but i could not set that for around 150 document libraries.
    Is there any possible to set that in Site Collection level?
    Thanks & Regards
    Poomani Sankaran

    You can run for each loop and use below code
    http://get-spscripts.com/
    #Get the site and list
    $web = Get-SPWeb "http://portal/sites/testsite"
    $list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Shared Documents"))
    #Get the list view to be changed
    $newview = $list.Views["Sort by modified date"]
    #Set the mobile and default mobile view properties
    $newview.MobileView = $true
    $newview.MobileDefaultView = $true
    #Update the view configuration
    $newview.Update()
    $web.Dispose()
    $web.Lists[0].Views[0].RowLimit=30
    $web.Lists[0].Views[0].Update()
    How you can get all list using powershell
    http://sharepointrelated.com/2011/11/28/get-all-sharepoint-lists-by-using-powershell/
    If this helped you resolve your issue, please mark it Answered

  • Archive/Move files based on Modified Date range to another Library Using PowerShell while retaining Metadata

    Hi,
    I am trying to archive files from a SharePoint 2010 document library by moving them to another library that's a dedicated archive/folder/library. The files to be moved are selected based on their modified date column value that should range between any time
    in the past to January 1st 2012. 
    Also, to be able to retain the tags and cloumn values after the move. Open in explorer does not bring along the user added tags.
    I tried to edit this script
    $WebURL = "http://mysite.com/";
    $ListDisplayName = "Crawl Test Library";
    $ArchiveFolderName = "Crawl Test Library Archive";
    function moveItems ()
    trap
    #make sure we dispose of these in the event of an error to avoid memory leaks:
    write-host "Error - disposing of objects...";
    $Web.Dispose();
    $Site.Dispose();
    [Microsoft.SharePoint.SPSite] $Site = New-Object Microsoft.SharePoint.SPSite($WebURL);
    [Microsoft.SharePoint.SPWeb] $Web = $Site.OpenWeb();
    [Microsoft.SharePoint.SPList] $List = $Web.Lists[$ListDisplayName];
    $FolderToMoveTo = $List.RootFolder.Url + "/" + $FolderName;
    $ItemMoveCount=0;
    $Query = New-Object Microsoft.SharePoint.SPQuery;
    $Query.Folder = $list.RootFolder;
    $camlQuery = "<Where><Leq><FieldRef Name='Modified' /><Value Type='DateTime'>2012-01-01T00:00:00Z</Value></Leq></Where>"
    $Query.Query = $camlQuery
    $Query.RowLimit = 2200; #limit query because of large folder
    $List.GetItems($Query) |
    Where {$_.ContentType.Name -ne "Folder"} |
    foreach-object {
    #Line below will simply output to console and demonstrates another .NET call
    [System.String]::format("Moving Item {0} with ID {1}...",$_.Name, $_.ID.ToString());
    $Web.GetFile($_.Url).MoveTo([System.String]::format("{0}/{1}",$FolderToMoveTo,$_.Name));
    write-host "Success...";
    $ItemMoveCount++;
    write-host "==============================================================================";
    write-host "Complete! -> Moved " $ItemMoveCount " Items to directory " $FolderName;
    write-host "==============================================================================";
    #dispose:
    $Web.Dispose();
    $Site.Dispose();
    #garbage collection
    [GC]::Collect()
    to do that but it doesn't seem to work. I am no guru in powershell yet so any help is appreciated.
    Thanks.

    This solution gets the job done. Much thanks to
    Ian Hayse
    NB...The Modified and Created dates are gonna reflect runtime dates now 
    $web = Get-SPWeb "http://sharepointed.com/"
    $list = $web.Lists["Shared Documents"]
    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $spQuery.ViewAttributes = "Scope='Recursive'";
    $spQuery.RowLimit = 2000
    $caml = '<Where><Lt><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2014-01-01T04:06:45Z</Value></Lt></Where> '
    $spQuery.Query = $caml
    do
    $listItems = $list.GetItems($spQuery)
    $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    $listTotal = $listItems.Count
    for ($x=$listTotal-1;$x -ge 0; $x--)
    try
    $listItems[$x].CopyTo("http://sharepoint/Docs/Documents/"+ $listItems[$x].name)
    Write-Host("DELETED: " + $listItems[$x].name)
    $listItems[$x].Recycle()
    catch
    Write-Host $_.Exception.ToString()
    while ($spQuery.ListItemCollectionPosition -ne $null)

  • Sharepoint 2013 / Office 365 Document library item level permissions problem

    Hello,
    I'm looking for a solution to enable users to upload documents to a document library, the ability to view other documents uploaded to the same document library, but able to edit or delete those other documents.
    With a list you can use Item-Level security in Advanced Settings but this is not available for Document libraries. I could use workflows to assign individual permissions to document, but the the library already contains over 2,000 documents and will continue
    to expand so I don't like the idea of having that many individual permissions set.
    Are there any 3rd party plug-ins or solutions to this issue?
    Thanks,

    Try below:
    http://www.hersheytech.com/Blog/SharePoint/tabid/197/entryid/28/Default.aspx
    As it turns out the, setting Item-Level Permissions in a library is fully supported with PowerShell!
    The PowerShell commands for changing this are very simple:
    $web = Get-SPWeb http://YourSite/
    $list = $web.Lists[“Your Document Library Name”]
    $list.ReadSecurity = 2
    $list.Update()
    $web.Dispose()
    Note the 3rd line which is where you determine the value for this setting using the following values:
    1 = “Read all items”
    2 = “Read items that were created by the user”
    If you wish to modify the values for Create and Edit access instead, replace .ReadSecurity with .WriteSecurity with
    the following values:
    1 = “Create and edit All items”
    2 = “Create items and edit items that were created by the user”
    4 = “None”
    For example:
    $web = Get-SPWeb http://YourSite/
    $list = $web.Lists[“Your Document Library Name”]
    $list.WriteSecurity = 2
    $list.Update()
    $web.Dispose()
    Also check 
    http://sppermissions.codeplex.com/
    If this helped you resolve your issue, please mark it Answered. You can reach me through http://freeit-support.com/

  • Not able to create sub folder using SharePoint web service in large SharePoint document library (Item count view threshold limit)

    We are trying to create folder & subfolder in a SharePoint document library using SharePoint default(dws) web service. Document library has unique permission as well as item level permission. It was working as expected. Once item count crosses
    view threshold limit ( 5000) , create folder web method completes with an error and it creates a folder in SharePoint.
    Request:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dws="http://schemas.microsoft.com/sharepoint/soap/dws/">
       <soapenv:Header/>
       <soapenv:Body>
          <dws:CreateFolder>
             <!--Optional:-->
             <dws:url>Shared Documents/VenTest02092015v1</dws:url>
          </dws:CreateFolder>
       </soapenv:Body>
    </soapenv:Envelope>
     Response:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <CreateFolderResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/dws/">
             <CreateFolderResult>&lt;Error ID="2">Failed&lt;/Error></CreateFolderResult>
          </CreateFolderResponse>
       </soap:Body>
    </soap:Envelope>
     While trying to create subfolder under the above created folder service throws an exception saying
    FolderNotFound.
    Though we are able to create subfolder from SharePoint UI successfully. 
    Request
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dws="http://schemas.microsoft.com/sharepoint/soap/dws/">
       <soapenv:Header/>
       <soapenv:Body>
          <dws:CreateFolder>
             <!--Optional:-->
             <dws:url>Shared Documents/VenTest02092015v1/REQ-1</dws:url>
          </dws:CreateFolder>
       </soapenv:Body>
    </soapenv:Envelope>
    Response:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <CreateFolderResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/dws/">
             <CreateFolderResult>&lt;Error ID="10">FolderNotFound&lt;/Error></CreateFolderResult>
          </CreateFolderResponse>
       </soap:Body>
    </soap:Envelope>

    Yes, you're probably hitting the 5000 list item threshold (
    http://sharepoint.stackexchange.com/questions/105937/overcoming-5000-file-document-library-limits ). I assume you can do it via the UI because you're probably logged in as an admin in which case, out of memory, the threshold is 20.000 items. You can extend
    this limit, but you probably shouldn't.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Document library items are not displaying in sorted order in sharepoint 2013

    Hi,
    I have a document library , I am storing document sets on it.
    28326 items are there in the library.
    I have configured sort on Name columns. Initially items are displaying in sorted order like (A,B,C,D,E...)
    Now Items are not displaying in a sorted order it is displaying like (A, B,C,D,E,A,C...) like this.
    Please help me on this sorting issue.
    Thanks,
    Samir

    Are the documents displaying in your image inside the document sets?  If so then your sets (folders) are displaying in alphabetical order and the documents inside the sets are displaying in alphabetical order.  This is what i would expect.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • How to change column "Date" from "Text" to "Date-Time" in Document Library.

    How to change column name "Date" from "Single line of Text" to "Date and Time" in Document Library.

    Hi,
    If you would change column type, you might need to re-create column.
    If you would like a text column to display in date format, you could refer to the links below:
    http://sharepoint.stackexchange.com/questions/45774/how-to-convert-date-field-in-single-line-of-text-using-calculated-columns
    http://yasuanantha.blogspot.com/2008/06/to-convert-text-column-to-date-column.html
    Regards,
    Rebecca Tu
    TechNet Community Support

  • Document Library items delete

    Hi ,
    I have a Document Library. I created one custom view through code.
    in that, i need to show a DELETE option. i already did that.
    Question is, only document owners only should have the right to delete those doc's. Others should not delete.
    For a list, we have ITEM LEVEL PERMISSION option. Like that , is there any way to achieve  that?
    How to do that.?

    Hello,
    Just create a designer workflow for  your requirement.
    Execute that workflow when an new document gets added under library.
    The functionality of the workflow is as follows
    When a new document get added, you workflow will set contribute access to the owner of that document and will set read access to rest all other users.

  • Update document library item where a docx document uploaded using powershell script

    HI
    when i update an existing item of a document library using script i faced the issue.
    i uploaded two .txt files and two word docx files and a png file.
    where i update .txt file item there is no issues , but  for other items i have problem.
    PS C:\Scripts> C:\Scripts\UPdateDocLibrary.ps1
    Exception calling "Update" with "0" argument(s): "There is no file with URL 'Do
    cs/Emc.docx' in this Web."
    At C:\Scripts\UPdateDocLibrary.ps1:26 char:13
    + $item.Update <<<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:89"
    $listName = "Docs"
    #Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    #Get the SPList object to retrieve the "Demo List"
    $list = $web.Lists[$listName]
    $items = $list.items
    #Go through all items
    foreach($item in $items)
    if($item["NO"] -eq $null)
    $item["Title"] = "My updated edited item!"
    $item.Update()
    adil

    Please check if file is checkout or locked , and if not then checkout it and then try to update -
    $url= $webURL + $item.File.Url;
    $file = $web.GetFile($url);
    if($file.CheckOutType -eq "None" -And $file.LockType -eq "None")
    $file.CheckOut();
    also please try these option, may help -
    1. Allow unsafe update at web
    $web.AllowUnsafeUpdates=$true;
    2. try systemupdate
    $item.SystemUpdate($false)
    Thanks
    Ganesh Jat [My Blog |
    LinkedIn | Twitter ]
    Please click 'Mark As Answer' if a post solves your problem or 'Vote As Helpful' if it was useful.

  • Modifying upload.aspx on Document Library

    I am adding a cascading dropdown using spservices (from codeplex). I need to edit the upload.aspx page to enable the cascading dropdown. I created a new customedit.aspx page but can't figure out how to copy and modify the upload page.

    Hi,
    You can consider the solution of Russell Gove which can customize the SharePoint Upload Page on only a certain list :
    https://yetanothersharepointblog.wordpress.com/2012/09/30/customize-the-sharpoint-upload-page/
    http://spcustomupload.codeplex.com/
    Also you can have a look at the other solutions as below:
    https://social.msdn.microsoft.com/Forums/office/en-US/535e9448-0e1e-4b6f-9c56-cb5b133ebacc/redirect-to-a-customuploadaspx-instead-of-the-layoutsuploadaspx?forum=sharepointcustomizationlegacy
    http://byteloom.blogspot.com/2012/01/custom-upload-form-for-document-library.html
    Best Regards,
    Eric
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • View (or filter) document library items by Groups

    Hello
    I have a bunch of documents in a library.
    I would like specific groups to see specific documents.
    For example, Group 1 can read Document A and Group 2 can read Document B but Group 1 and 2 should be able to read Document C. Some of the groups can edit, some can read.
    I ended up creating a column with Target Audiences and applied each document with the correct Target Audience (group). 
    Then, I created a view for each of the target audiences.
    That seemed to work ... however, the All Documents view is sitting there. And someone can just click on it and see all the documents. 
    So, I tried to make the All Documents view filter for only Site Owners but that didn't work.
    And, what's to stop someone from searching for Site Contents and finding all the documents there?
    Does anyone have any advice on how I can lock down these files to user groups please?
    Thanks.
    Mel

    Hi
    check this doc
    http://sharepoint-community.net/profiles/blogs/how-to-security-trim-search-results-in-sharepoint-2013
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Writing binary data to ASP file from applet through URLConnection

    Hi Everybody,
    I am facing a proble with HttpURLConnection.I want to write some binary data from applet to an ASP file.The other end ASP file read this binary data and process , Here problem is I have opened URLConnection to the page and Created OutputStream and writing byte by Write() method But other end we are not getting bytes...we are not getting error too at java side..can any body help me..do we need to set any property to URLConnection...here I am giving sample code...
    OutputStream os;
    URL uConnect2;
    HttpURLConnection hucConnect2;
    uConnect2= new URL("http://webserver/vnc/sendtoserver.asp?"); hucConnect2=(HttpURLConnection)uConnect2.openConnection();
    hucConnect2.setDoOutput(true);
    hucConnect2.setRequestMethod("POST")
    os=new DataOutputStream(hucConnect2.getOutputStream());
    os.writeBytes("Hello");
    Thanks in Advance
    Madhav

    Do you remember to flush() and close() the stream?

Maybe you are looking for

  • HP 3520 e-All-in-One Printer series

    My printer calls for HP 564 ink.  I bought the combo pack of the yellow, cyan, and magenta "regular" sized cartridges.  I bought a "regular" sized black cartridge as well.  When I got home I realized that it already had a black XL cartridge.  Will th

  • Error while testing SAP Screen Personas Service!

    Hi, I am getting an error message "No system available for your user.Please contact your IT team". While testing the service "mainapp" under services SAP->bc->bsp->persos->mainapp. Please reply asap.. Thanks in advance.. Regards, Chandrababu Katta

  • Apex 3.0 in spanish

    Hello team, i was working with the Apex 3.0 sandbox and i was looking at the spanish translation of certain on-line help items, in search of inspiration as i am checking out a translation for one of my sites. I find the spanish translation of Apex ve

  • OAS 10.1.2 and 10.1.3 on same server

    Could I run OAS 10.1.2 and 10.1.3 the same time on the same Sun Solaris box (different ports of course)? Thanks

  • How to uninstall evernote application in os x?

    I tried to uninstall evernote, I removed contents folder to trash but when i tried to move application to trash I got a message 'The item "Evernote" can't be moved to the Trash because it's open'. How do I close it and remove it completely?