paths in code

Discussion in 'ASP.NET / ASP.NET Core' started by JerSchneid, Mar 11, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I'm not quite sure what you are asking, but I think this may be helpful:

    When you want to convert a relative web URL to the local path on the machine you can do:

    string localPath = HttpContext.Current.Server.MapPath(relativeUrl);

    (note, that's C# syntax)

    You use then when you want to save a file to the file system.
     
  2. Excuse the simplicity of this, but I have looked all through the asp.net2 book I am working through as well as seached this forum (path brings up no results, maybe I'm the first one to need it [​IMG] .

    My normal way of dealing with pictures (when I used old fashioned php that is [​IMG] ) is to build the picture database in an admin section of the code, so all I have to do is upload a picture, resfresh the database and the other code fits the picture into a group. (I'm a firm believer in letting the code do the mundane work).

    But for some reason I can not work out a path that works in a directory search. This is on my local machine, haven't uploaded to the site yet.

    Protected Sub Page_Load( ... )
    If Not Page.IsPostBack Then
    picCollectionPersonal = New Collection
    fillPictureCollections()
    End If
    End

    (I know the 'new collection' is in the wrong place really, just wanted to show you what I have done)



    Private Sub fillPictureCollections()
    Dim lString As String
    Dim iCount As Integer


    Dim lPath as String


    lPath = "~/images/personal/*.jpg"



    lString = Dir(lPath, FileAttribute.Normal)
    iCount = 0
    Do While lString <> ""
    picCollectionPersonal.Add(lString, iCount.ToString)
    iCount += 1
    lString = Dir()
    Loop
    End Sub


    I have tried alsorts in 'lPath' but don't get any list. But, if I use 'lPath = "*.*" I get the list of the files in,


    C:\Program Files\Microsoft Visual Studio 8\Common7\IDE


    So any relative path isn't going to work. Can I not use relative paths like this on the local machine, or is there some secret trick you all know about but I have missed?




    Rassler
    One of those dreaded IT/Programmer types.
    Which generally means, failed to make a decent living at programming so do IT too.
     
  3. rassler,

    Another useful path specifier is "~". which maps to the root of the application.

    Keith Payne
    Technical Marketing Solutions
    http://www.tms-us.com
     
  4. You can also use Request.ApplicationPath to get the application path of the app.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page