Solved

Server.MapPath("/") in asp.net 2.0

Posted on 2007-12-06
3
9,575 Views
Last Modified: 2010-04-21
in asp.net 2.0 I am trying to use the Server.MapPath("/") to return the root directory of the application...

it errors with:
Exception Details: System.InvalidOperationException: Failed to map the path '/'.
Label1.Text = "Mail sent: " & Server.MapPath("/")

what am I doing wrong? thanks!
0
Comment
Question by:Starr Duskk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 400 total points
ID: 20423947
That's a bit surprising.

Anyhow, the path "/" doesn't refer to the root directory of the application, but the root directory of the web site. Use "~/" to get the root directory of the application.
0
 
LVL 7

Assisted Solution

by:nisarkhan
nisarkhan earned 100 total points
ID: 20424013
RootUrl - the fully qualified path to the page that should serve as the root node in the site map. If this value isn't specified, the default value is ~/Default.aspx.

see my sample in code snippet:


server.MapPath("/IssueManagement/database/Issues.mdb")
IssueManagement is the app name/virtual directory. database is the directory under it.
This gets mapped to C:\Inetpub\wwwroot\IssueManagement\database\Issues.mdb

Hope this helps
Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
    'Need to lock to ensure thread safety, since multiple pages in the app
    'might be trying to call this method concurrently
    SyncLock Me
        'See if a root has been defined
        If _root IsNot Nothing Then
            'We have a root - but has the underlying file system been changed?
            If Not _fsMonitor.HasChanged Then
                'No change to FS, returned the cached root
                Return _root
            End If
 
            'The file system has been changed since we've last called
            'BuildSiteMap - we need to rebuild the sitemap
        End If
 
        'If we reach here, either we don't have a root or the file system has
        'been changed must build up the Site Map. Clear out the site map, if 
        'it already exists...
        Refresh()
 
        'Create a root node
        _root = CreateFolderNode(HttpContext.Current.Server.MapPath(RootUrl), RootUrl)
        _root.Title = RootTitle
 
        'Establish the cache dependency
        _fsMonitor = New CacheDependency(HttpContext.Current.Server.MapPath("~/"))
 
        AddNode(_root)  'Add the root to the site map
 
        'Recurse through the file system, adding nodes
        BuildSiteMapFromFileSystem(_root, "~/")
 
        Return _root
    End SyncLock
End Function

Open in new window

0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31413274
thanks guys!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question