internal static string ExpandDataDirectory(string keyword, string value, ref string datadir) { string fullPath = null; if ((null != value) && value.StartsWith(DataDirectory, StringComparison.OrdinalIgnoreCase)) { string rootFolderPath = datadir; if (null == rootFolderPath) { // find the replacement path object rootFolderObject = AppDomain.CurrentDomain.GetData("DataDirectory"); rootFolderPath = (rootFolderObject as string); if ((null != rootFolderObject) && (null == rootFolderPath)) { throw ADP.InvalidDataDirectory(); } else if (ADP.IsEmpty(rootFolderPath)) { rootFolderPath = AppDomain.CurrentDomain.BaseDirectory; } if (null == rootFolderPath) { rootFolderPath = ""; } // cache the |DataDir| for ExpandDataDirectories datadir = rootFolderPath; } // We don't know if rootFolderpath ends with '\', and we don't know if the given name starts with onw int fileNamePosition = DataDirectory.Length; // filename starts right after the '|datadirectory|' keyword bool rootFolderEndsWith = (0 < rootFolderPath.Length) && rootFolderPath[rootFolderPath.Length - 1] == '\\'; bool fileNameStartsWith = (fileNamePosition < value.Length) && value[fileNamePosition] == '\\'; // replace |datadirectory| with root folder path if (!rootFolderEndsWith && !fileNameStartsWith) { // need to insert '\' fullPath = rootFolderPath + '\\' + value.Substring(fileNamePosition); } else if (rootFolderEndsWith && fileNameStartsWith) { // need to strip one out fullPath = rootFolderPath + value.Substring(fileNamePosition + 1); } else { // simply concatenate the strings fullPath = rootFolderPath + value.Substring(fileNamePosition); } // verify root folder path is a real path without unexpected "..\" if (!ADP.GetFullPath(fullPath).StartsWith(rootFolderPath, StringComparison.Ordinal)) { throw ADP.InvalidConnectionOptionValue(keyword); } } return(fullPath); }