I'm exporting my Dataset to an excel file, and I want to make sure I keep any file errors under control. One in particular that I'm concerned about is accessing a file that's already open. A general IOException occurs that says "The process cannot access the file 'C:\Reports\report300.csv' because it is being used by another process." Here is the line in which the error will occur:
Dim output As New IO.StreamWriter(path, False, UnicodeEncoding.Default)
I guess I could just throw a try catch around it, but what if an IOException happens that isnt related to this particular incident? Is there a way I can check to see if the file is already open before allowing this code to run? I looked on google but couldn't find a straight answer, especially when I'm using excel.
Thanks in advance.