Hi all ,
Now I'm trying to implement logic to check if excel file is opened or not if open send out email in Script task. Can anyone provide the code for this one? using c#
I'm using this one but it's not working fine.
public void Main()
{
Boolean FileLocked = true;
// Check if the file isn't locked by an other process
try
{
// Try to open the file. If it succeeds, set variable to false and close stream
FileStream fs = new FileStream(Dts.Variables["User::varmFilePath"].Value.ToString(), FileMode.Open);
FileLocked = false;
fs.Close();
Dts.TaskResult = (int)ScriptResults.Success;
MessageBox.Show("File is closed");
}
catch (UnauthorizedAccessException ex)
{
// If opening fails, it's probably locked by an other process
FileLocked = true;
// Wait two seconds before rechecking
Thread.Sleep(2000);
MessageBox.Show("File is opened");
}
}
Thanks