HI All,

I have ollowing code to delete the image by using File.Delete(fileNamefordel + ".jpg"); function. It works fine on local server but not on uploaded server.

string fileNamefordel = Server.MapPath("StdImage") + "\\" + (Session["lCandidateID"]).ToString();
if (File.Exists(fileNamefordel + ".png")) { File.Delete(fileNamefordel + ".png"); }

if (File.Exists(fileNamefordel + ".gif")) { File.Delete(fileNamefordel + ".gif"); }
if (File.Exists(fileNamefordel + ".jpg")) { File.Delete(fileNamefordel + ".jpg"); }

if (File.Exists(fileNamefordel + ".jpeg")) { File.Delete(fileNamefordel + ".jpeg"); }
if (File.Exists(fileNamefordel + ".tif")) { File.Delete(fileNamefordel + ".tif"); }

Please if anybody helps in this regard.

Thanks

Shakeel

HI All,

I have ollowing code to delete the image by using File.Delete(fileNamefordel + ".jpg"); function. It works fine on local server but not on uploaded server.

string fileNamefordel = Server.MapPath("StdImage") + "\\" + (Session["lCandidateID"]).ToString();
if (File.Exists(fileNamefordel + ".png")) { File.Delete(fileNamefordel + ".png"); }

if (File.Exists(fileNamefordel + ".gif")) { File.Delete(fileNamefordel + ".gif"); }
if (File.Exists(fileNamefordel + ".jpg")) { File.Delete(fileNamefordel + ".jpg"); }

if (File.Exists(fileNamefordel + ".jpeg")) { File.Delete(fileNamefordel + ".jpeg"); }
if (File.Exists(fileNamefordel + ".tif")) { File.Delete(fileNamefordel + ".tif"); }

Please if anybody helps in this regard.

Thanks

Shakeel

if you open one of those images and make some operations on them and forget to dispose the image object after the operations, you will not be able to delete them, make sure you dispose any image objects before deletion.

This article has been dead for over six months. Start a new discussion instead.