Hello.
In one of my workflows, via the "Script" object (C#), I need to copy/paste a PDF file from a Windows folder "A" to another Windows folder "B".
The problem I'm encountering is that the same PDF file is already being used by another process, which generates an error.
The process cannot access the 'C:\...' file because it is in use by another process.
I've tried to work around this with the "Try/Catch" tool, but it doesn't seem to work.
Here is the C# code
namespace WorkflowActivity.Scripting.CopieNATIFfromPIXItoLF { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Text; using System.IO; /// <summary> /// Offre une ou plusieurs méthodes qui peuvent être exécutées au moment de l'exécution de l'activité de scriptage du flux de travail. /// </summary> public class Script1 : ScriptClass90 { /// <summary> /// Cette méthode est exécutée quand l'activité est effectuée. /// </summary> protected override void Execute() { // Ecrivez ici votre code. // Get the token values for source filename, source path, and target path... String sourcePath = this.GetTokenValue("SourcePathN").ToString(); String sourceFileName = this.GetTokenValue("SourceFileNameN").ToString(); String targetPath = this.GetTokenValue("TargetPathN").ToString(); String sourcePathAndName = Path.Combine(sourcePath, sourceFileName); String targetPathAndName = Path.Combine(targetPath, sourceFileName); Boolean fileExists = false; try { // Check to see if the source file exists... if (File.Exists(sourcePathAndName)) { fileExists = true; // Check to see if the target path exists. If not then create it... if (Directory.Exists(targetPath) == false) { Directory.CreateDirectory(targetPath); } // Copy the souorce file to the target directory... File.Copy(sourcePathAndName, targetPathAndName, true); } } catch (System.Exception e) { this.WorkflowApi.TrackError(e.Message); } // Set the result token for later processing... this.SetTokenValue("FileExists", fileExists); } } }
How can I resolve this please ?
Thanks in advance.
Regards