473,779 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSystemWatch er file in use problem

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(o bject sender, System.EventArg s e)
{
FileSystemWatch er objFSW = new FileSystemWatch er();
objFSW.Path = "c:\\BizDocs\\v ault";
objFSW.Filter = "*.tif";
label1.Text = "Watching " + objFSW.Path;
//Setup Events
objFSW.Created += new FileSystemEvent Handler(FileCre ated);
//Start Things up
objFSW.EnableRa isingEvents = true;
}
public static void FileCreated(obj ect source, FileSystemEvent Args e)
{

#region WAIT FOR IT TO BE DONE CREATING...
Stream stream = null;
while (true)
{
try
{
if ((stream = File.Open(e.Ful lPath, FileMode.Open, FileAccess.Read ,
FileShare.None) ) != null)
break;
}
catch (IOException ex)
{
System.Threadin g.Thread.Sleep( 1000 );
}
}

if ( stream == null )
throw new ApplicationExce ption("can't open file");

#endregion WAIT FOR IT TO BE DONE CREATING...

//give the output a stream to write to
System.IO.Strea mWriter sw =
new StreamWriter(e. Name.ToString() .Substring(0,e. Name.ToString() .Length-3)
+ "ps");

//DEFINE A NEW PROCESS
System.Diagnost ics.Process procTiff2ps = new
System.Diagnost ics.Process);
System.Diagnost ics.ProcessStar tInfo i = new
System.Diagnost ics.ProcessStar tInfo();

i.FileName = "tiff2ps.ex e";
i.Arguments = e.FullPath.ToSt ring();//"C:\\BizDocs\\V ault\\401.TIF";
i.RedirectStand ardOutput = true;
i.CreateNoWindo w = true;
i.UseShellExecu te = false;
procTiff2ps.Sta rtInfo = i;
}

Help!

//START THE PROCESS
procTiff2ps.Sta rt();
Jul 21 '05 #1
2 5680
Tom
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***********@g mail.com (Charlie Kunkel) wrote in message news:<24******* *************** ***@posting.goo gle.com>...
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(o bject sender, System.EventArg s e)
{
FileSystemWatch er objFSW = new FileSystemWatch er();
objFSW.Path = "c:\\BizDocs\\v ault";
objFSW.Filter = "*.tif";
label1.Text = "Watching " + objFSW.Path;
//Setup Events
objFSW.Created += new FileSystemEvent Handler(FileCre ated);
//Start Things up
objFSW.EnableRa isingEvents = true;
}
public static void FileCreated(obj ect source, FileSystemEvent Args e)
{

#region WAIT FOR IT TO BE DONE CREATING...
Stream stream = null;
while (true)
{
try
{
if ((stream = File.Open(e.Ful lPath, FileMode.Open, FileAccess.Read ,
FileShare.None) ) != null)
break;
}
catch (IOException ex)
{
System.Threadin g.Thread.Sleep( 1000 );
}
}

if ( stream == null )
throw new ApplicationExce ption("can't open file");

#endregion WAIT FOR IT TO BE DONE CREATING...

//give the output a stream to write to
System.IO.Strea mWriter sw =
new StreamWriter(e. Name.ToString() .Substring(0,e. Name.ToString() .Length-3)
+ "ps");

//DEFINE A NEW PROCESS
System.Diagnost ics.Process procTiff2ps = new
System.Diagnost ics.Process);
System.Diagnost ics.ProcessStar tInfo i = new
System.Diagnost ics.ProcessStar tInfo();

i.FileName = "tiff2ps.ex e";
i.Arguments = e.FullPath.ToSt ring();//"C:\\BizDocs\\V ault\\401.TIF";
i.RedirectStand ardOutput = true;
i.CreateNoWindo w = true;
i.UseShellExecu te = false;
procTiff2ps.Sta rtInfo = i;
}

Help!

//START THE PROCESS
procTiff2ps.Sta rt();

Jul 21 '05 #2
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(10 00);
}

Sunny

In article <63************ *************@p osting.google.c om>, 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***********@g mail.com (Charlie Kunkel) wrote in message news:<24******* *************** ***@posting.goo gle.com>...
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(o bject sender, System.EventArg s e)
{
FileSystemWatch er objFSW = new FileSystemWatch er();
objFSW.Path = "c:\\BizDocs\\v ault";
objFSW.Filter = "*.tif";
label1.Text = "Watching " + objFSW.Path;
//Setup Events
objFSW.Created += new FileSystemEvent Handler(FileCre ated);
//Start Things up
objFSW.EnableRa isingEvents = true;
}
public static void FileCreated(obj ect source, FileSystemEvent Args e)
{

#region WAIT FOR IT TO BE DONE CREATING...
Stream stream = null;
while (true)
{
try
{
if ((stream = File.Open(e.Ful lPath, FileMode.Open, FileAccess.Read ,
FileShare.None) ) != null)
break;
}
catch (IOException ex)
{
System.Threadin g.Thread.Sleep( 1000 );
}
}

if ( stream == null )
throw new ApplicationExce ption("can't open file");

#endregion WAIT FOR IT TO BE DONE CREATING...

//give the output a stream to write to
System.IO.Strea mWriter sw =
new StreamWriter(e. Name.ToString() .Substring(0,e. Name.ToString() .Length-3)
+ "ps");

//DEFINE A NEW PROCESS
System.Diagnost ics.Process procTiff2ps = new
System.Diagnost ics.Process);
System.Diagnost ics.ProcessStar tInfo i = new
System.Diagnost ics.ProcessStar tInfo();

i.FileName = "tiff2ps.ex e";
i.Arguments = e.FullPath.ToSt ring();//"C:\\BizDocs\\V ault\\401.TIF";
i.RedirectStand ardOutput = true;
i.CreateNoWindo w = true;
i.UseShellExecu te = false;
procTiff2ps.Sta rtInfo = i;
}

Help!

//START THE PROCESS
procTiff2ps.Sta rt();

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3009
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 a week. Then suddenly the monitored network server starts to behave crazily. It sends to my Sync Server dozens of replicated file change events. Say one file was changed two days ago, but the monitored server still keeps sending me many many...
2
2061
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 when you try to process the same file name twice. I get the generic problem "file is being used by another process". What is really stange is it will report the same problem when the name is different but the first 10 letters are the same. I have...
1
4210
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 process. I ran into trouble when trying to process a group of files at a time. The code below fixed my problem for about 15 large files ( around 100k each ). However when I tried to use it on a group of small files ( 90 files ) it crashes ( around 6k...
1
1588
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 some time it not get fired. also this happens with muliple files dropping in same folder . the count of events not equal to number of files droped.Follwing i scode snippet. please do the needfull for me. thank in advance.
1
1833
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) when a monitored file is deleted from a COMMAND CONSOLE window yet display correctly when deleted from Windows Explorer. Further more, many examples about FileSystemWatcher usage I've found the OnDelete event does not get triggered at all if a...
2
372
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 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) {
3
2207
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 to test my current project on the main production server its giving an error saying "Could not load collection5". the page directive of the .aspx file is <%@ Page Language="C#" MasterPageFile="~/home.master" AutoEventWireup="true"...
3
2931
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 brings me to the dir: C:\Visual Studio 2005\WebSites\WebSite1, it creates default.aspx and default.aspx.vb and I pasted the following code into default.aspx. I go to build to build web site and it says:------ Build started: Project:
0
1750
by: valdas | last post by:
Hi, I have a problem in accessing "sqlServerCatalogNameOverwrites" section in app.config file. <configuration> <configSections> <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" /> </configSections> <sqlServerCatalogNameOverwrites>
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.