Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9616
  • Last Modified:

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

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
Starr Duskk
Asked:
Starr Duskk
2 Solutions
 
Göran AnderssonCommented:
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
 
nisarkhanCommented:
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
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
thanks guys!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now