hi!
i am using datagrid to display images.(i write code using delete command). i delete a row in datagrid that row is deleted. but my problem is image is also deleted in saved directory.
my code like:
String imagePath = "~/ContentImages/Products/" + Image;
System.IO.FileInfo file1 = new System.IO.FileInfo(Server.MapPath(imagePath));
file1.Delete();
i using this code it display one error message in run time. i.e., Access to the path is denied.
if i give image name then it deleted. but i am not giving any name it takes path of datagrid image url.
urgent. please help me. give a sample code.
Thanks.
Loading
Raaj KumarPosted Mar 2, 2010, 9:54 AM
What I see from you code is like you are trying to delete the file which is an image
System.IO.FileInfo file1 = new System.IO.FileInfo(Server.MapPath(imagePath));
file1.Delete();
So this piece of code deletes your Image file.If you don't want to delete the image file then either comment or remove the code.
Next thing is the imagePath. It contains a special character "~".Remove this and try. If have any problem then try removing the "/". So the imagePath should look like this,
String imagePath = "ContentImages/Products/" + Image;
Regards,
raaj