Sage.SageContext.MapPath C# (CSharp) Method

MapPath() public method

Maps the supplied relative path to the actual, physical location of the file.
If the specified path is an absolute path, no translation will be done.
/// is null or empty. ///
public MapPath ( string path ) : string
path string The path to map
return string
        public string MapPath(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");

            if (path.ContainsAnyOf(":", "\\\\"))
                return path;

            return pathMapper.Invoke(path);
        }

Usage Example

Esempio n. 1
0
        internal static Dictionary<string, string> GetVirtualDirectories(SageContext context)
        {
            Dictionary<string, string> virtualDirectories = new Dictionary<string, string>();

            try
            {
                string serverRootPath = context.MapPath("/").ToLower().TrimEnd('\\');
                using (DirectoryEntry iis = new DirectoryEntry("IIS://Localhost/w3svc"))
                {
                    IEnumerable<DirectoryEntry> websites = iis.Children.Cast<DirectoryEntry>()
                        .Where(c => c.SchemaClassName == "IIsWebServer");

                    foreach (DirectoryEntry website in websites)
                    {
                        using (website)
                        {
                            DirectoryEntry root = website.Children.Find("Root", "IIsWebVirtualDir");
                            string sitePath = root.Properties["path"].Value.ToString().ToLower().TrimEnd('\\');

                            if (sitePath == serverRootPath)
                            {
                                virtualDirectories = Project.GetVirtualDirectories(root, string.Empty);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Could not retrieve virtual directories in the current application's web server: {0}", ex.Message);
            }

            return virtualDirectories;
        }