Example #1
0
        public override DirectoryInfoBase GetParent(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException(StringResources.Manager.GetString("PATH_CANNOT_BE_THE_EMPTY_STRING_OR_ALL_WHITESPACE"), "path");
            }

            if (VirtualPath.HasIllegalCharacters(path, false))
            {
                throw new ArgumentException("Path contains invalid path characters.", "path");
            }

            var absolutePath = VirtualFileDataAccessor.Path.GetFullPath(path);
            var sepAsString  = string.Format(CultureInfo.InvariantCulture, "{0}", VirtualFileDataAccessor.Path.DirectorySeparatorChar);

            var lastIndex = 0;

            if (absolutePath != sepAsString)
            {
                var startIndex = absolutePath.EndsWith(sepAsString, StringComparison.OrdinalIgnoreCase) ? absolutePath.Length - 1 : absolutePath.Length;
                lastIndex = absolutePath.LastIndexOf(VirtualFileDataAccessor.Path.DirectorySeparatorChar, startIndex - 1);
                if (lastIndex < 0)
                {
                    return(null);
                }
            }

            var parentPath = absolutePath.Substring(0, lastIndex);

            if (string.IsNullOrEmpty(parentPath))
            {
                return(null);
            }

            var parent = new VirtualDirectoryInfo(VirtualFileDataAccessor, parentPath);

            return(parent);
        }
Example #2
0
        private DirectoryInfoBase CreateDirectoryInternal(string path, DirectorySecurity directorySecurity)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException(StringResources.Manager.GetString("PATH_CANNOT_BE_THE_EMPTY_STRING_OR_ALL_WHITESPACE"), "path");
            }

            path = EnsurePathEndsWithDirectorySeparator(VirtualFileDataAccessor.Path.GetFullPath(path));

            if (!Exists(path))
            {
                VirtualFileDataAccessor.AddDirectory(path);
            }

            var created = new VirtualDirectoryInfo(VirtualFileDataAccessor, path);

            created.SetAccessControl(directorySecurity);
            return(created);
        }