VS2005 - how to specify location of a text file in dev and production?

D

dgk

I have a few text files that I read in at run time into label
controls; they're stored in a Text folder in the app. At run time I
try to read them in by using "~/text/thefile.txt" but it doesn't work
in the editor or when published. I've tried a few appgetpath type
things and can't get one to work.

Any help greatly appreciated.
 
S

sloan

I use this function:


I find it easier to wrap this up in a function for maintenance , debugging
and consistency issues.
Its probably a little overkill, but I'm come to trust it, for than random
MapPaths all over the place.




public static string FindPhysicalRootDirectory(Page p)
{
string rootDir;
rootDir = p.Server.MapPath("~/");
return rootDir;
}




Public Shared Function FindPhysicalRootDirectory(ByVal p As Page) As
String

Dim rootDir As String

rootDir = p.Server.MapPath("~/")

Return rootDir

End Function


I have another counter part:

public static string FindVirtualRootDirectory(Page p)
{
return "~/";
}

It seems to work.


Remember , in 2.0 remember to test against IIS deployment and the casino web
server deployment. (the local non iis port-number deployment)

If you wait to test IIS until deployment, you may be surprised it doesn't
work.
 
D

dgk

Public Shared Function FindPhysicalRootDirectory(ByVal p As Page) As
String

Dim rootDir As String

rootDir = p.Server.MapPath("~/")

Return rootDir

End Function

Thanks, I select this one being a VB guy. But is there some reason not
to just do:

Dim rootDir as String = p.Server.MapPath("~/")

or even just

Return p.Server.MapPath("~/")


I'm not sure what any of them get you over just throwing MapPath("~/")
into the code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top