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

Discussion in 'ASP .Net' started by dgk, Mar 18, 2007.

  1. dgk

    dgk Guest

    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.
    dgk, Mar 18, 2007
    #1
    1. Advertising

  2. The "~" syntax is inderstood by aspx pages only. Try just
    MapPath("text/thefile.txt").

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "dgk" <> wrote in message
    news:...
    >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.
    Eliyahu Goldin, Mar 18, 2007
    #2
    1. Advertising

  3. dgk

    dgk Guest

    On Sun, 18 Mar 2007 10:26:38 +0200, "Eliyahu Goldin"
    <> wrote:

    >The "~" syntax is inderstood by aspx pages only. Try just
    >MapPath("text/thefile.txt").


    Yes, that works. Thanks.
    dgk, Mar 18, 2007
    #3
  4. dgk

    sloan Guest

    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.



    "dgk" <> wrote in message
    news:...
    > 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.
    sloan, Mar 19, 2007
    #4
  5. dgk

    dgk Guest

    On Mon, 19 Mar 2007 10:30:47 -0400, "sloan" <> wrote:

    > 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?
    dgk, Mar 20, 2007
    #5
  6. dgk

    sloan Guest

    Did you test against

    IIS vs Casino deployment?



    "dgk" <> wrote in message
    news:...
    > On Mon, 19 Mar 2007 10:30:47 -0400, "sloan" <> wrote:
    >
    > > 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?
    sloan, Mar 20, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brett Sheeran
    Replies:
    0
    Views:
    2,902
    Brett Sheeran
    Jul 15, 2003
  2. RedHair
    Replies:
    4
    Views:
    737
    RedHair
    Nov 15, 2006
  3. Shelves

    Deploy To Dev and Production

    Shelves, Jul 17, 2007, in forum: Java
    Replies:
    4
    Views:
    337
  4. Andrew Morton

    Dev and production web.configs

    Andrew Morton, Jun 26, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    320
    Andrew Morton
    Jun 30, 2009
  5. Replies:
    2
    Views:
    140
Loading...

Share This Page