>I am creating a PDF programmatically. The ActiveX component basically acts as a printer driver and I can't figure out how to know when it is done so I know the file exists for certain so I can read it into a byte array to store.
>
>I am trying now to do this with system.io.filesystemwatcher but I can't seem to get the syntax right
>
As far as I know, there isn't a nice easy way to only get notified when the file is closed (which is essentially what you want). Instead, I'd wait until the file has been created, then call out to another method which loops until you can get an exclusive lock on the new file (or times out), ex: (sorry, C# code and may not work as-is)
bool IsFileComplete(string fileName, TimeSpan timeout)
{
bool complete = false;
DateTime endTime = DateTime.Now.Add(timeout);
while (endTime > DateTime.Now)
{
try
{
using (FileStream newFile = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
complete = true;
break;
}
}
catch (IOException) { }
System.Threading.Thread.Sleep(100);
}
return complete;
}