Solved displaying error and not opening file even after success