In an SSIS package I have a script task that is trying to get the Author information for a file. When run from Visual Studio the code works as expected, returning the Authors information from the file metadata. When run on the server as a scheduled job against the same file no Authors information is found.
private static void GetDocAuthor(object param)
{
try
{
DocAuthor = "Unknown";
object[] args = (object[])param;
string folderPath = (string)args[0];
string fileName = (string)args[1];
fileName = fileName.Trim('\\');
// Filename: Column 0
// Authors: Column 20
var folder = new Shell32.Shell().NameSpace(folderPath);
foreach (Shell32.FolderItem item in folder.Items())
{
string retrievedFilename = folder.GetDetailsOf(item, 0);
if (retrievedFilename == fileName)
{
DocAuthor = folder.GetDetailsOf(item, 20);
}
}
}
catch (Exception ex)
{
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry(string.Format("Error getting Authors. Error message = {0}", ex.Message), EventLogEntryType.Information, 107);
}
}
}
The GetDocAuthor method is being executed as an STA thread since I read about the Shell COM object not working in SSIS due to it being run as an MTA thread. This is how it is being called:
object[] args = new object[] { folderPath, fileName };
Thread staThread = new Thread(new ParameterizedThreadStart(GetDocAuthor));
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start(args);
staThread.Join();
folderPath is the folder where the file I want the information on resides. fileName is the name of the specific file I want the author of.
The folderPath is a UNC path so I don't expect that to be the issue. I'm missing something that must be different from when it runs locally as opposed to on the server. When running on the server the script is able to find the file, it just isn't able to get the metadata.
Anyone have a direction to explore?
After doing some more testing between the local execution and server execution here is what I know.
The SSIS package is running in 32 bit mode both locally and on the server.
Locally it's running in VS 2017 on Windows 10. On the server it's running on SQL server 2014 on a Windows Server 2012 R2 box.
Using some application logging what I've determined is that GetDetailsOf(item, 10) is the same on both computers, being the NT User ID for the person who created the file, while for GetDetailsOf(item, 20) contains the Author information on Windows 10 but is blank on Windows Server 2012 R2.
Unfortunately the NT User ID is not what I need, it's the Author information.
Sounds like the issue has to do with what's available on Windows Server 2012 R2 and not the file itself. Can anyone confirm that the Authors metadata isn't available on Server 2012?