Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to delete an image file dynamically from an .aspx form but everytime though the path is being retrieved correctly (~/img/DisplayItems/Electronics/Computers/D003.png), while executing File.Delete(path) - it is adding a strange path (C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\) before the path given by me and thus throwing exception as:

Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\img\DisplayItems\Electronics\Computersg\'.

Please help me resolve this problem and correct me where i am going wrong.

Thanks

IB
Posted
Comments
Aravindba 18-Feb-14 4:10am    
r u store image file in server ? did u use server.mappath("~/img/DisplayItems/Electronics/Computers/D003.png") ?
Indrojeet_Bhattacharya 18-Feb-14 4:13am    
yes i am storing the image files in server. No I have not used server.mappath .. please let me know about it ..

thanks
Indrojeet_Bhattacharya 18-Feb-14 8:18am    
Thanks Mr.Aravindba, it worked.


While deletion your relative path need to be converted to actual path as deletion is done using actual path.

Try using Server.Mappath("<your relative="" path="">") before you call delete method to delete it.
 
Share this answer
 
Hai

i am explain in vb u try to convert ur coding language

Dim name = Server.MapPath("~\KEY\" + stringFileName)

in above Server.MapPath have root of website folder like ur website folder in IIS
"~\KEY\" is folder name inside in roor folder
stringFileName is file name.

in my eg website have Key folder and inside have files.

if i open in physically it look like C:\inetpub\wwwroot\Website\KEY in that key folder have D003.png file.


in ur code try to give like
Dim path as String = Server.MapPath("~/img/DisplayItems/Electronics/Computers/D003.png")
File.Delete(path)

Regards
Aravind
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900