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 5639
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |