We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Problem with relative path in C#

Medium Priority
493 Views
Last Modified: 2012-05-11
Dear Experts,

i am accessing my aspx file from here :

c:\inetpub\wwwroot\ctm\admin\page.aspx from the web browser like this :
http://serverip/ctm/admin/page.aspx

now, i wish to access a file which is located over here :
c:\inetpub\wwwroot\ctm\otherfolder\otherfile

how do i write c# code to get to that file?

the following ways have FAILED :

string path = @"..\otherfolder\otherfile";
string path = @"../otherfolder/otherfile";
string path = @"\otherfolder\otherfile";

i am stuck

can you please help me?
Comment
Watch Question

Paul JacksonSoftware Engineer
CERTIFIED EXPERT
Top Expert 2011

Commented:
try :
string path = @"~\otherfolder\otherfile";

Author

Commented:
nope

that doesnt work either
Paul JacksonSoftware Engineer
CERTIFIED EXPERT
Top Expert 2011

Commented:
why do you have an @ ?
does this work :
string path = "~\otherfolder\otherfile";

Author

Commented:
i obviously need "@" to make sure that c# doesnt treat the  "\"  as an escape character
Paul JacksonSoftware Engineer
CERTIFIED EXPERT
Top Expert 2011

Commented:
ok this should work and you don't need the @
string path = "~/otherfolder/otherfile";

If this doesn't work please post what is being put into the address bar.

Author

Commented:
unfortunately, even that hasn't worked

it tries to find the file from here :


Could not find a part of the path 'd:\Setups\Visual Studio 2008\Common7\IDE\~\otherfolder\otherfile'.


the path which is being shown is where i have my visual studio installed
Software Engineer
CERTIFIED EXPERT
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
yes... finally that worked!

Author

Commented:
thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.