vb.net - When writing to a file, how do I correctly resolve access to path is denied? -


here code:

dim htmlfile = "\\folder\test.htm" if file.exists(htmlfile)     file.delete(htmlfile) end if using strwriter streamwriter = new streamwriter(htmlfile, false)     strwriter.write("content") end using 

it works of time i'll exception of "access path '\folder\test.htm' denied." exception occurs on line:

using strwriter streamwriter = new streamwriter(filename, false) 

how can ensure creates new file , never causes exception?

this routine waits time in case of error betweens 2 servers writing same file:

retry_it:  try       dim htmlfile = "\\folder\test.htm"       if file.exists(htmlfile)          file.delete(htmlfile)       end if       using strwriter streamwriter = new streamwriter(htmlfile, false)          strwriter.write("content")       end using catch exception       thread.sleep(2000)   '2 seconds       goto retry_it end try 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -