0

I'm trying to use Server.MapPath instead of the complete path which basically looks like this

CsvFile= @"D:\web\finalsa\en\csr\download_center\Click_Counter.csv";

The file where i write this line is located in :

D:\web\finalsa\en\include";

Therefore i tried to write this without any success:

CsvFile= Server.MapPath("../csr/download_center/Click_Counter.csv");

Can anyone tell me what i'm doing wrong ? Thanks in advance

  • What's wrong? Is the path returned different from what you expect? Is an exception thrown? What is the problem? Also, wouldn't it be better to use a application root relative path, eg. `~/en/csr/...`? What file is this in? ASPX? ASCX? ASMX? – Luaan Mar 05 '14 at 13:35
  • @ArnaudAd could you describe what exactly you are doing. I had a similar problem before when I was using a static method from utility class from the controller. It turns out that I can't use `Server.MapPath` in the utility class, so I had to execute it in the controller and pass a string. I feel that maybe you are trying something similar, if that's the case, just take the path in your controller, and pass a string argument. – Leron Mar 05 '14 at 13:47

1 Answers1

0

NOone can as you do not tell us how the web server is configured.

BUt what you can do is map "." and see where this ends up. That is the current directory. Likely you have an issue that you think that is somewhere else than you think - a 1 minute debugging run will help you to find out whether you are right or wrong.

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • 2
    that is supposed to be a comment – Amit Joki Mar 05 '14 at 13:34
  • @AmitJoki Actually no as it has the solution. THe sultion is "get the current path with . and then adjust your code accordingly as you then know the problem exactly. Obviously, Amit, in your world programmers are not supposed to even think and use some work and just copy/paste ready made solutions. I feel sorry for you. – TomTom Mar 05 '14 at 13:36
  • Ok, What if, he is in a class, other than code behind, then he should use `HttpContext.Current.Server.MapPath()`. I thought it like that., Ok, I won't downvote any one ! – Amit Joki Mar 05 '14 at 13:39
  • Yeah, in `Amit Joki's` defend I will say that it's much likely that the OP is trying to use `Server.MapPath()` outside the parent class and most probably the problem is not the incorrect path but the incorrect using of of the extension. – Leron Mar 05 '14 at 13:42