I need help. I have a directory I'm watching for creation of .TIF
files, whereupon creation, I need to launch a process (command line
exe) that converts the TIF file to a postscript file. (using
tif2ps.exe) The problem is, I can't open the .TIF file as long as my
application's running! tif2ps.exe always tells me "Cannot open file".
Here's the code in my Windows C# App:
private void button1_Click(object sender, System.EventArgs e)
{
FileSystemWatcher objFSW = new FileSystemWatcher();
objFSW.Path = "c:\\BizDocs\\vault";
objFSW.Filter = "*.tif";
label1.Text = "Watching " + objFSW.Path;
//Setup Events
objFSW.Created += new FileSystemEventHandler(FileCreated);
//Start Things up
objFSW.EnableRaisingEvents = true;
}
public static void FileCreated(object source, FileSystemEventArgs e)
{
#region WAIT FOR IT TO BE DONE CREATING...
Stream stream = null;
while (true)
{
try
{
if ((stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read,
FileShare.None)) != null)
break;
}
catch (IOException ex)
{
System.Threading.Thread.Sleep( 1000 );
}
}
if ( stream == null )
throw new ApplicationException("can't open file");
#endregion WAIT FOR IT TO BE DONE CREATING...
//give the output a stream to write to
System.IO.StreamWriter sw =
new StreamWriter(e.Name.ToString().Substring(0,e.Name. ToString().Length-3)
+ "ps");
//DEFINE A NEW PROCESS
System.Diagnostics.Process procTiff2ps = new
System.Diagnostics.Process);
System.Diagnostics.ProcessStartInfo i = new
System.Diagnostics.ProcessStartInfo();
i.FileName = "tiff2ps.exe";
i.Arguments = e.FullPath.ToString();//"C:\\BizDocs\\Vault\\401.TIF";
i.RedirectStandardOutput = true;
i.CreateNoWindow = true;
i.UseShellExecute = false;
procTiff2ps.StartInfo = i;
}
Help!
//START THE PROCESS
procTiff2ps.Start(); 2 5635
Thats because you are opening and locking it. Why would you open the
file if the command line tool was going to open it. ch***********@gmail.com (Charlie Kunkel) wrote in message news:<24*************************@posting.google.c om>... I need help. I have a directory I'm watching for creation of .TIF files, whereupon creation, I need to launch a process (command line exe) that converts the TIF file to a postscript file. (using tif2ps.exe) The problem is, I can't open the .TIF file as long as my application's running! tif2ps.exe always tells me "Cannot open file".
Here's the code in my Windows C# App:
private void button1_Click(object sender, System.EventArgs e) { FileSystemWatcher objFSW = new FileSystemWatcher(); objFSW.Path = "c:\\BizDocs\\vault"; objFSW.Filter = "*.tif"; label1.Text = "Watching " + objFSW.Path; //Setup Events objFSW.Created += new FileSystemEventHandler(FileCreated); //Start Things up objFSW.EnableRaisingEvents = true; }
public static void FileCreated(object source, FileSystemEventArgs e) {
#region WAIT FOR IT TO BE DONE CREATING... Stream stream = null; while (true) { try { if ((stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)) != null) break; } catch (IOException ex) { System.Threading.Thread.Sleep( 1000 ); } }
if ( stream == null ) throw new ApplicationException("can't open file");
#endregion WAIT FOR IT TO BE DONE CREATING...
//give the output a stream to write to System.IO.StreamWriter sw = new StreamWriter(e.Name.ToString().Substring(0,e.Name. ToString().Length-3) + "ps");
//DEFINE A NEW PROCESS System.Diagnostics.Process procTiff2ps = new System.Diagnostics.Process); System.Diagnostics.ProcessStartInfo i = new System.Diagnostics.ProcessStartInfo();
i.FileName = "tiff2ps.exe"; i.Arguments = e.FullPath.ToString();//"C:\\BizDocs\\Vault\\401.TIF"; i.RedirectStandardOutput = true; i.CreateNoWindow = true; i.UseShellExecute = false; procTiff2ps.StartInfo = i; }
Help!
//START THE PROCESS procTiff2ps.Start();
Ok, I see why OP is opening the file, to check if it is fully created.
But OP have to be sure to close it after that. The change should be:
while (true)
{
using (Stream stream = File.Open(...))
{
if (stream != null)
break;
}
Thread.Sleep(1000);
}
Sunny
In article <63*************************@posting.google.com> , junkmale48
@hotmail.com says... Thats because you are opening and locking it. Why would you open the file if the command line tool was going to open it.
ch***********@gmail.com (Charlie Kunkel) wrote in message news:<24*************************@posting.google.c om>... I need help. I have a directory I'm watching for creation of .TIF files, whereupon creation, I need to launch a process (command line exe) that converts the TIF file to a postscript file. (using tif2ps.exe) The problem is, I can't open the .TIF file as long as my application's running! tif2ps.exe always tells me "Cannot open file".
Here's the code in my Windows C# App:
private void button1_Click(object sender, System.EventArgs e) { FileSystemWatcher objFSW = new FileSystemWatcher(); objFSW.Path = "c:\\BizDocs\\vault"; objFSW.Filter = "*.tif"; label1.Text = "Watching " + objFSW.Path; //Setup Events objFSW.Created += new FileSystemEventHandler(FileCreated); //Start Things up objFSW.EnableRaisingEvents = true; }
public static void FileCreated(object source, FileSystemEventArgs e) {
#region WAIT FOR IT TO BE DONE CREATING... Stream stream = null; while (true) { try { if ((stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)) != null) break; } catch (IOException ex) { System.Threading.Thread.Sleep( 1000 ); } }
if ( stream == null ) throw new ApplicationException("can't open file");
#endregion WAIT FOR IT TO BE DONE CREATING...
//give the output a stream to write to System.IO.StreamWriter sw = new StreamWriter(e.Name.ToString().Substring(0,e.Name. ToString().Length-3) + "ps");
//DEFINE A NEW PROCESS System.Diagnostics.Process procTiff2ps = new System.Diagnostics.Process); System.Diagnostics.ProcessStartInfo i = new System.Diagnostics.ProcessStartInfo();
i.FileName = "tiff2ps.exe"; i.Arguments = e.FullPath.ToString();//"C:\\BizDocs\\Vault\\401.TIF"; i.RedirectStandardOutput = true; i.CreateNoWindow = true; i.UseShellExecute = false; procTiff2ps.StartInfo = i; }
Help!
//START THE PROCESS procTiff2ps.Start(); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cxw0106 |
last post by:
Hello,
I have some weird problem with the FileSystemWatcher. I have developed
an application that monitors a network directory for file changes of a
certain file type. The program runs well for...
|
by: Phil396 |
last post by:
I have a Windows service that use a FileSystemWatcher
to scan incoming html for information. The process
worked fine in a Windows Application and it also
works fine in a Windows Service except...
|
by: Phil396 |
last post by:
I have a windows service that uses a filesystemwatcher
to wait for files and process them to a database.
Sometimes a large group of files will be cut and paste
for the filesystemwatcher to...
|
by: yogesh |
last post by:
hello
I getting problem in FileSystemWatcher , I had wrriten the code for
the FileSystemWatcher , when i dropping the new file in the directory
, the WatcherEdi_Created event get fired , but...
|
by: Long Tran |
last post by:
Hello
The DirectoryMonitor sample codes demonstrate the .NET Framework System.IO FileSystemWatcher object works nicely but display only short file name (for example test.bdrg become test~1.bdr)...
|
by: Charlie Kunkel |
last post by:
I need help. I have a directory I'm watching for creation of .TIF
files, whereupon creation, I need to launch a process (command line
exe) that converts the TIF file to a postscript file. (using...
|
by: savvy |
last post by:
I'm using "Visual Studio 2005 Professional". I'm half way through in my
project development. I've created a New Website in the Visual Studio
2005 and developing my project over there. When i wanted...
|
by: =?Utf-8?B?YzY3NjIyOA==?= |
last post by:
Hi all,
I cut and paste the following code from msdn help page which it just
introduces view and multiview server controls.
Here is what I do:
in vs studio 2005, File --New Web Site, it...
|
by: valdas |
last post by:
Hi,
I have a problem in accessing "sqlServerCatalogNameOverwrites" section in app.config file.
<configuration>
<configSections>
<section name="sqlServerCatalogNameOverwrites" ...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |