c# - How to check if file exists while downloading from server? -


i have excel sheet written , saved in server , downloading server using following code

            byte[] filebytes = system.io.file.readallbytes(excelpath);             system.web.httpcontext context = system.web.httpcontext.current;             context.response.clear();             context.response.clearheaders();             context.response.clearcontent();             context.response.appendheader("content-length", filebytes.length.tostring());             context.response.contenttype = "application/vnd.ms-excel";             context.response.appendheader("content-disposition", "attachment; filename=" + "export.xlsx");             context.response.binarywrite(filebytes);             context.applicationinstance.completerequest(); 

the file gets downloaded in downloads. want know whether can check file same name exists or not?if delete , download file

you can try below

system.io.file.exists(excelpath) 

Comments