0

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

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by serkan sendur
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.