July 13, 2009

Search File Properties of Office Document

I got a request to find a way to search the properties of office documents on a network drive that was created or modified by a specific user and copy that to a new location. I searched the web and did not really find anything that stood out until I came across a codeproject article that does something like what I needed, but it did not filter for one specific user or get all office doc extensions. I figured that someone else would probably need need this....you can find the code here.

I am not sure exactly why this was needed, but the idea was find the files created or authored by this user and then copy them from sourceA to sourceB. When the copy was done, it was also not to be modified in terms of date/time stamps. The code for that was actually easy:
private void CopyFile(string file, string target)
{
string targetFile = GetTargetPath(file, target);
Directory.CreateDirectory(Path.GetDirectoryName(targetFile));

File.Copy(file, targetFile, true);

File.SetCreationTime(targetFile, File.GetCreationTime(file));
File.SetLastAccessTime(targetFile, File.GetLastAccessTime(file));
File.SetLastWriteTime(targetFile, File.GetLastWriteTime(file));
File.SetLastAccessTime(targetFile, File.GetLastAccessTime(file));
}
The hard part was searching the properties...

No comments:

Post a Comment