Hi All
I have a scenario where I need capture FileName, File Created Date and file size in to a sql table. I was able to use a script component. But unfortunately the file creation time is not the actual file created date but its capturing the modified date.
Consider a file was created on source folder at 2.30 PM and I copied the file to target folder at 2.45 Pm , My code is pulling up the copied timestamp not the actual file created time stamp. Below is the code , Can you please how do I capture the actual creation date
public void Main()
{
{
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(Dts.Connections["GetFileInfo_Target"].AcquireConnection(Dts.Transaction) as SqlConnection);
//MessageBox.Show(myADONETConnection.ConnectionString, "ADO.NET Connection");
string DirPath = Dts.Variables["User::VarDirectoryPath"].Value.ToString();
//get all files from directory
string[] files = Directory.GetFiles(DirPath);
SqlCommand sqlCmd= new SqlCommand();
sqlCmd.Connection = myADONETConnection;
//get all files from directory
string[] files = Directory.GetFiles(DirPath);
SqlCommand sqlCmd= new SqlCommand();
sqlCmd.Connection = myADONETConnection;
//loop through files
foreach (string filename in files)
{
foreach (string filename in files)
{
FileInfo file = new FileInfo(filename);
sqlCmd.CommandText = "INSERT INTO [dbo].[FileAttributes] ([Filename],[FileCreatedDateTime],[FileSize]) Values('" +
file.Name + "','" + file.CreationTime + "','" + file.Length + "')";
//MessageBox.Show(sqlCmd.CommandText);
file.Name + "','" + file.CreationTime + "','" + file.Length + "')";
//MessageBox.Show(sqlCmd.CommandText);
sqlCmd.ExecuteNonQuery();
}
}
Dts.TaskResult = (int)ScriptResults.Success;