Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
i created one folder under solution explorer called subimg (subimg is not under any folder. it is under solution explorer).

In my project i need show different images for the product.
so,i need to save and delete images from folder .

Below code works exctaly what i want when i am running in localhost.

But after hosting in IIS Server, it is not working.

to save image into folder
showimage.ashx.cs
*****************

C#
string path23 = context.Server.MapPath("~/subimg");
                bmpToSave1.Save("" + path23 + "/"+ ".jpg");

to delete image from folder
product.aspx.cs(pageload)
************************

C#
try
                    {
                        var fileimgpath = Directory.GetFiles(Server.MapPath("~/subimg"));

                        foreach (string s1 in fileimgpath)
                        {
                            if (File.Exists(s1))
                            {
                                File.Delete(s1);
                            }
                        }
                    }
                    catch(Exception ex)
                    {

                    }

i tried ../, only / , without / too instead of '~'. but not working.

help needed.
Posted
Updated 9-Mar-15 18:08pm
v2
Comments
Richard Deeming 9-Mar-15 12:59pm    
Define "not working", and update your question with the code which creates bmpToSave1.
Arkadeep De 9-Mar-15 13:03pm    
according to your 1st 2 line your img is saving into a path ~/subimg/.jpg like this.. rectify this...

1 solution

C#
var fileimgpath = Directory.GetFiles(Server.MapPath("~/subimg/"));

Note: The last slash (/) in Server.MapPath("~/subimg/") is important to get into that directory and find all the files from that directory.
 
Share this answer
 
Comments
christhuxavier 12-Mar-15 7:09am    
Thank you!,
there is no issue in giving path. we have to give read/write permission in IIS users after hosting.

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



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