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

Recommended Answers

All 2 Replies

Is ASP.NET user has permission to delete files on the server?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.