Is there a way to detect if the file is open already and close it if it is? Even if another program has that file open?
C#
Last Comment
silemone
8/22/2022 - Mon
silemone
are you trying to close that process or that file? Can you show a little more code, please.
What exactly is Process? Anyway, I have example code for opening closing file
I am running my code in Debug mode, which saves the PDF out to the hard drive, then proceeds to open it.
Sometimes I forget to close the file before I repeat the above process (run the debugger again). So I get an exception that the file is in use by another process (which makes sense).
I want to programmatically close the file, then proceed with stepping through my code.
silemone
This is me just posing questions, but:
And there's No Process.Stop or Process.Close, Process.End?
Can you go Process.Dispose() or Process = null? and if you did, would that leave a file open on your screen?
use a try...catch to handles that exception. and maybe you can Use FileStream to Close the File.
What exactly is Process? Anyway, I have example code for opening closing file
FileInfo objFI = new FileInfo(@"c:\myFile2.txt"
FileStream objFS = objFI.Open(FileMode.Create
StreamWriter objSW = new StreamWriter(objFS);
objSW.Write(strResult.ToSt
objSW.Write(strResult2.ToS
objSW.Close();
objFS.Close();
objSW.Dispose();
objFS.Dispose();