Click here to Skip to main content
15,909,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string root = Server.MapPath("~");
                string path = "\\Brands\\" + Session["brandname"].ToString() + "\\" + Session["departmentname"].ToString() + "\\" + Seasonfolders.SelectedItem.Text + "\\" + Session["groupname"].ToString() + "\\" + item;
                string originalpath = System.IO.Path.Combine(root, path);
                bool isExists = System.IO.Directory.Exists(Server.MapPath(@"~\\" + originalpath));
                if (!isExists)
                {
                    chkstyles.Items.RemoveAt(i);
                    File.Delete(@originalpath); 
                }



Expected Output:
root=E:\sg
path=\Brands\a\b\c
originalpath=E\sg\a\b\c\d

but produced C\a\b\c .... Didn't get the current accessing folder path. But with this, I worked in all codes which worked fine but hectic at one module alone. Doesn't know how it worked there and not working here.
Posted

1 solution

Well no...it's not going to work.
Look at what you are doing:
C#
string root = Server.MapPath("~");
Which gives you "E:\sg"
C#
string originalpath = System.IO.Path.Combine(root, path);
Which gives you "E:\sg\a\b\c\d"
Then, you do this:
C#
bool isExists = System.IO.Directory.Exists(Server.MapPath(@"~\\" + originalpath));
Which is checking to see if a file exists called "E:\sgE:sg\a\b\d\c"

Which is going to fail...

Why are you trying to include the root folder twice?
 
Share this answer
 
Comments
Sriram Ramachandran 25-Jun-14 4:12am    
ok but when checked with breakpoint: I got the output mapped to C:\ only- before checking file Exists code.
Sriram Ramachandran 25-Jun-14 5:12am    
Can I know what the problem is?

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