Using FileStream
-
Hi, I have written a webservice the purpose being is to convert the sent docu to pdf. Steps involved are as follows: 1)The to be converted doc is sent to the webservice in the form of bytes 2)In the web service a file is created using the bytes received. 3)This file is then printed using a printer driver(Nova PDF) which saves the sent file in pdf file in required folder. 4)Then the pdf is opened using filestream and then bytes are sent from the web service to the caller. Problem occurs when large sized files! I guess even before the filestream is completely done we are trying to read the file again as a resultant it throws an error: File cannot be accessed as it is being used by another process.... Is there a way that i could do filestream read only once the pdf document is completely loaded by the printer driver? Thanks,
gauthee
-
Hi, I have written a webservice the purpose being is to convert the sent docu to pdf. Steps involved are as follows: 1)The to be converted doc is sent to the webservice in the form of bytes 2)In the web service a file is created using the bytes received. 3)This file is then printed using a printer driver(Nova PDF) which saves the sent file in pdf file in required folder. 4)Then the pdf is opened using filestream and then bytes are sent from the web service to the caller. Problem occurs when large sized files! I guess even before the filestream is completely done we are trying to read the file again as a resultant it throws an error: File cannot be accessed as it is being used by another process.... Is there a way that i could do filestream read only once the pdf document is completely loaded by the printer driver? Thanks,
gauthee
Did the Writer object close the Stream and got nulled before the StreamReader attempted to open it?
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Did the Writer object close the Stream and got nulled before the StreamReader attempted to open it?
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
There is no writerstream! On sending the file to the printer driver a pdf file is created and saved in respective folder, after this operation(print operation) then iam trying to open the pdf file using the filestream and at this point it thows error: file cannot be accessed as it is being used by another process.....
gauthee
-
There is no writerstream! On sending the file to the printer driver a pdf file is created and saved in respective folder, after this operation(print operation) then iam trying to open the pdf file using the filestream and at this point it thows error: file cannot be accessed as it is being used by another process.....
gauthee
Hi, if your producer does not signal it is done producing the file, the only things you can do are: - wait a very long time; - or loop {wait a short time; try; exit on success;} BTW: if the web service is going to send the PDF back to the client, it will have to delete the file also; that too can fail because the file is being read by another process (Antivirus, Google desktop, whatever). The remedy is: loop {try; exit on success; wait a short time;} :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi, I have written a webservice the purpose being is to convert the sent docu to pdf. Steps involved are as follows: 1)The to be converted doc is sent to the webservice in the form of bytes 2)In the web service a file is created using the bytes received. 3)This file is then printed using a printer driver(Nova PDF) which saves the sent file in pdf file in required folder. 4)Then the pdf is opened using filestream and then bytes are sent from the web service to the caller. Problem occurs when large sized files! I guess even before the filestream is completely done we are trying to read the file again as a resultant it throws an error: File cannot be accessed as it is being used by another process.... Is there a way that i could do filestream read only once the pdf document is completely loaded by the printer driver? Thanks,
gauthee
You can use a FileSystemWatcher for this. This class is used to monitor a certain folder on the filesystem (disk) where your service runs. It fires events when something changes to the filesystem (eg. file created, renamed, deleted,...) Say your PDF printer saves the file as c:\temp\pdf\someName.pdf, then you can monitor the c:\temp\pdf folder with the FileSystemWatcher. When a file is created in that directory (by your pdf printer) an event is thrown. You can catch this event and then send the newly generated file. For more info on this class please visit the MSDN site here[^]. Hope this helps! Tim Wuytens
-
You can use a FileSystemWatcher for this. This class is used to monitor a certain folder on the filesystem (disk) where your service runs. It fires events when something changes to the filesystem (eg. file created, renamed, deleted,...) Say your PDF printer saves the file as c:\temp\pdf\someName.pdf, then you can monitor the c:\temp\pdf folder with the FileSystemWatcher. When a file is created in that directory (by your pdf printer) an event is thrown. You can catch this event and then send the newly generated file. For more info on this class please visit the MSDN site here[^]. Hope this helps! Tim Wuytens
Tim, Thanks for the reply! It is indeed a valid suggestion, though i have few questions. When the PDF printer starts printing a file would be at a location so the filewatcher checks that a file is created and the event gets fired thereby. The filewatcher can identify creation, deletion, modification but i guess my requirement is something like creation complete. Something should be fired once the file is created and completly loaded!
gauthee
-
Tim, Thanks for the reply! It is indeed a valid suggestion, though i have few questions. When the PDF printer starts printing a file would be at a location so the filewatcher checks that a file is created and the event gets fired thereby. The filewatcher can identify creation, deletion, modification but i guess my requirement is something like creation complete. Something should be fired once the file is created and completly loaded!
gauthee
I took a quick look at the documentation of Nova PDF and found that you can catch events from the printer driver self. There is an event NOVAPDF2_ENDDOC which fires when the job is done. Maybe this could be of use for you? I've used the PDF document found on http://www.novapdf.com/download/pdf/novasdk.pdf[^] See on page 28 of this document for the events. See heading 4.5 on page 20 to see how to register to the events. There's even something about e-mailing the converted documents in this guide. Hope this helps as well! Tim Wuytens