• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Problem with relative path in C#

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?
0
RakeshBhandari
Asked:
RakeshBhandari
  • 5
  • 4
1 Solution
 
Paul JacksonCommented:
try :
string path = @"~\otherfolder\otherfile";
0
 
RakeshBhandariAuthor Commented:
nope

that doesnt work either
0
 
Paul JacksonCommented:
why do you have an @ ?
does this work :
string path = "~\otherfolder\otherfile";
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
RakeshBhandariAuthor Commented:
i obviously need "@" to make sure that c# doesnt treat the  "\"  as an escape character
0
 
Paul JacksonCommented:
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.
0
 
RakeshBhandariAuthor 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
0
 
Paul JacksonCommented:
ok try:
string path = Server.MapPath("~\otherfolder\otherfile");
0
 
RakeshBhandariAuthor Commented:
yes... finally that worked!
0
 
RakeshBhandariAuthor Commented:
thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now