Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How can Server.Mappath read a file?

I have a Visual Studio 2008 solution that contains a handful of projects. One project contains a WCF Service I'm deploying. That WCF Service references some code in one of the other projects. That code is trying to read a file that's in a folder in the WCF project. Pseudo-project structure:

Solution
 Project1
  myclass.cs
    string file = Server.Mappath("");


 Project2
  filefolder
    myfile.txt

What is the correct syntax to put in the Mappath? I've tried all different variations such as:

".filefolder/myfile.txt"
"/filefolder/myfile.txt"
"./filefolder/myfile.txt"
"~/filefolder/myfile.txt"

None seem to be able to reach the file. One thing I thought of: Visual Studio 2008 runs the project and WCF in its own sandbox in IIS. Could that be the issue? Would it work if setup and deployed in regular IIS?

like image 859
Blaze Avatar asked Nov 28 '22 04:11

Blaze


1 Answers

var serverPath =
       System.Web.Hosting.HostingEnvironment.MapPath("~/filefolder/myfile.txt"); 
like image 120
wildcat Avatar answered Dec 04 '22 14:12

wildcat