It could be possible that file was already open or in use. Could you please show what’s the file path?
Can you show if the File variable has a value or not @Swagasmini_Jena or try to initialize it.If you use .ToString it will throw exception if you dont have any value on it please check thanks.
If you catch the exception and then print
exception.InnerException.Message you should get a more specific error message.
Take closer look at the error message in here: