{"id":1676,"date":"2013-07-01T10:00:05","date_gmt":"2013-07-01T10:00:05","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=1676"},"modified":"2024-04-26T12:48:27","modified_gmt":"2024-04-26T12:48:27","slug":"inconsistent-sharepoint-timestamps-with-webdav","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/inconsistent-sharepoint-timestamps-with-webdav\/","title":{"rendered":"Inconsistent SharePoint timestamps with WebDAV"},"content":{"rendered":"<p>There are situations when moving documents using Explorer mode can retain the correct \u201cModified\u201d timestamp in the browser, yet show an updated timestamp in Explorer Mode.<\/p>\n<p>This is due to WebDAV showing the date associated with the File (SPFile) rather than the date associated with the SPItem. Explorer mode can update the modified date in the SPFile.<\/p>\n<p>When you probe further, the \u201cItem\u201d has the correct timestamp (item[\u201cModified\u201d] is in the local timezone. However the SPFile has a property called vti_timelastmodified that has the GMT timestamp.<\/p>\n<p>Note the File has a property called vti_nexttolasttimemodified as well.<\/p>\n<p>Both item.file.properties[\u201cvti_timelastmodified\u201d] and item[\u201cModified\u201d] are the same type (DateTime) so I can compare them, which is precisely what I did in a special report looking for such timestamp divergence. I generated a filtered report custom written in PowerShell to show files that are more or less than 4 or 5 hours off (depending on the time of year, the hours diverge by either 4 or 5 hours) given my ET timezone. I only look to the \u201cminute\u201d and not the \u201csecond\u201d on purpose, so I don\u2019t flag false positives.<br role=\"presentation\" data-uw-rm-sr=\"\" \/>Here is how to fix a single instance of this issue:<\/p>\n<pre lang=\"php\">\r\n$docurl = \"http :\/\/SharePoint\/site\/list\/TimestampTest\/test2.docx\"\r\n$site = New-Object Microsoft.SharePoint.SPSite($docurl)\r\n$web = $site.OpenWeb()\r\n$item = $web.GetListItem($docurl)\r\n$list = $item.ParentList\r\n \r\n[System.DateTime]$date = $item[\"Modified\"]\r\n $user = New-Object microsoft.SharePoint.SPFieldUserValue($web, $item[\"Editor\"])\r\n $item[\"Modified\"] = $date;\r\n $item[\"Editor\"] = $user;\r\n $item.Update()\r\n try { $item.Versions[1].delete() } catch {write-host -foregroundcolor red \"Error (1) could not delete old version of $($item['Name'])\"}\r\n<\/pre>\n<p>Here\u2019s a function that reports on all URLs that suffer from this issue.  Note the use of date comparison, and the check for timestamp being off by either 4 or 5 hours, and matching on the delta of both days and minutes:<\/p>\n<pre lang=\"php\">\r\nfunction Reset-Dates ($WebUrl, $ListName)\r\n{\r\n #Get web, list and content type objects\r\n $web = Get-SPWeb $WebUrl\r\n $list = $web.Lists[$ListName]\r\n IF ($ReportFile -eq $null) {$reportFile = C:report.csv\"}\r\n \r\n #Check if the values specified for the content types actually exist on the list\r\n $xSit=$WebUrl;\r\n $xLis=$ListName;\r\n \r\n #Go through each item in the list\r\n $list.Items | ForEach-Object {\r\n $item = $_;\r\n \r\n $fd = $item.file.properties[\"vti_timelastmodified\"]\r\n $id = $item[\"Modified\"]\r\n \r\n$dd = ($id-$fd)\r\n \r\n$hoursMatch = (($dd.hours -eq -4) -or ($dd.hours -eq -5))\r\n $daysMatch = ($dd.days -eq 0)\r\n $minutesMatch = ($dd.minutes -eq 0)\r\n \r\n if ($hoursMatch -and $daysMatch -and $minutesMatch)\r\n {\r\n Write-Host '.' -NoNewline\r\n }\r\n else\r\n {\r\n $xURL=$item.url;\r\n $xNam=$item['Name']\r\n \r\n $xMod=$item[\"Modified\"]\r\n $xfMod = $item.file.properties[\"vti_timelastmodified\"]\r\n try {$xEdi=$item[\"ows_Modified_x0020_By\"].replace(\"DOMAIN\",$null)} catch {$xEdi=$item[\"ows_Modified_x0020_By\"]}\r\n try {$xAut=$item[\"ows_Created_x0020_By\"].replace(\"DOMAIN\",$null)} catch {$xAut=$item[\"ows_Created_x0020_By\"]}\r\n \r\n $Line1=$xURL+$sep+$xSit+$sep+$xLis+$sep+$xNam+$sep+$xAut+$sep+$xEdi+$sep+$xMod+$sep+$xfMod+$sep+$dd.days+$sep+$dd.hours+$sep+$dd.minutes+$sep+'1';\r\n $Line1 | Out-file -Filepath $ReportFile -Append\r\n $Line1=$null;\r\n }\r\n \r\n}\r\n \r\n$web.Dispose()\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are situations when moving documents using Explorer mode can retain the correct \u201cModified\u201d timestamp in the browser, yet show an updated timestamp in Explorer Mode. This is due to WebDAV showing the date associated with the File (SPFile) rather than the date associated with the SPItem. Explorer mode can update the modified date in [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":1677,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1676","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-architecture"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=1676"}],"version-history":[{"count":1,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1676\/revisions"}],"predecessor-version":[{"id":1679,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1676\/revisions\/1679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/1677"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=1676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=1676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=1676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}