It seems like a lot of third party tools do this but obviously they don't make it known. I've used quite a few open source tools for bulk file upload from file/network shares into SharePoint but it seems like most of them don't quite capture the user information when you're talking about uploading FROM these shares (and not from library to library within SharePoint).
The SPFileCollection.Add method contains an pretty appropriate overload:
SPFileCollection.Add method (String, Stream, SPUser, SPUser, DateTime, DateTime)
public SPFile Add(
string urlOfFile,
Stream file,
SPUser createdBy,
SPUser modifiedBy,
DateTime timeCreated,
DateTime timeLastModified)
Now, I know you can get timeCreated and timeLastModified by referencing properties of an instance of FileInfo
. And I know that you can "sort of" get a created-by value by looking at the security info of a file and getting the owner:
string user = System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();
The reason I ask is because I suspect, after looking at SPFileZilla2013's source, that it uses this overload. In that project's code it gets the timeCreated and LastWriteTime from an instance of FileInfo
as previously mentioned but after combing through it some more I'm not 100% sure on what values it uses for both instances of SPUser and my best guess is that it gets the principal for the user account supplied to it in the GUI for connecting to your site.
Has anyone run across a method or know of a way they can share where you could get the most accurate values of the created by and last modified by user values from the file system to use in this method? Third party tools seem to do it (ShareGate, Metalogix, etc) so there has to be a way.