Пример #1
0
        public object doJSONPAction(string callback, string json)
        {
            object             Data       = null;
            var                serializer = new JavaScriptSerializer();
            FileExplorerParams args       = (FileExplorerParams)serializer.Deserialize(json, typeof(FileExplorerParams));

            try
            {
                if (args.ActionType != "Paste" && args.ActionType != "GetDetails")
                {
                    string FilePath = FileExplorerOperations.ToPhysicalPath(FileExplorerOperations.ToAbsolute(args.Path));
                }
                switch (args.ActionType)
                {
                case "Read":
                    Data = FileExplorerOperations.ReadData(args.Path, args.ExtensionsAllow);
                    break;

                case "Search":
                    Data = FileExplorerOperations.Search(args.Path, args.ExtensionsAllow, args.SearchString, args.CaseSensitive);
                    break;

                case "CreateFolder":
                    Data = FileExplorerOperations.NewFolder(args.Path, args.Name);
                    break;

                case "Paste":
                    Data = FileExplorerOperations.Paste(args.LocationFrom, args.LocationTo, args.Names, args.Action, args.CommonFiles);
                    break;

                case "Remove":
                    Data = FileExplorerOperations.Remove(args.Names, args.Path);
                    break;

                case "Rename":
                    Data = FileExplorerOperations.Rename(args.Path, args.Name, args.NewName, args.CommonFiles);
                    break;

                case "GetDetails":
                    Data = FileExplorerOperations.GetDetails(args.Path, args.Names);
                    break;
                }
                HttpContext.Current.Response.Write(string.Format("{0}({1});", callback, serializer.Serialize(Data)));
                return("");
            }
            catch (Exception e)
            {
                FileExplorerResponse Response = new FileExplorerResponse();
                Response.error = e.GetType().FullName + ", " + e.Message;
                HttpContext.Current.Response.Write(string.Format("{0}({1});", callback, serializer.Serialize(Response)));
                return("");
            }
        }
Пример #2
0
        public object doJSONAction()
        {
            FileExplorerParams args = FileExplorerOperations.GetAjaxData(Request);

            if (args.ActionType == "Upload")
            {
                FileExplorerOperations.Upload(args.Files, args.Path);
                return(new HttpResponseMessage()
                {
                    Content = new StringContent("ok", Encoding.UTF8, "text/plain")
                });
            }
            try
            {
                if (args.ActionType != "Paste" && args.ActionType != "GetDetails")
                {
                    var FilePath = FileExplorerOperations.ToPhysicalPath(FileExplorerOperations.ToAbsolute(args.Path));
                }
                switch (args.ActionType)
                {
                case "Read":
                    return(FileExplorerOperations.ReadData(args.Path, args.ExtensionsAllow));

                case "Search":
                    return(FileExplorerOperations.Search(args.Path, args.ExtensionsAllow, args.SearchString, args.CaseSensitive));

                case "CreateFolder":
                    return(FileExplorerOperations.NewFolder(args.Path, args.Name));

                case "Paste":
                    return(FileExplorerOperations.Paste(args.LocationFrom, args.LocationTo, args.Names, args.Action, args.CommonFiles));

                case "Remove":
                    return(FileExplorerOperations.Remove(args.Names, args.Path));

                case "Rename":
                    return(FileExplorerOperations.Rename(args.Path, args.Name, args.NewName, args.CommonFiles));

                case "GetDetails":
                    return(FileExplorerOperations.GetDetails(args.Path, args.Names));
                }
                return("");
            }
            catch (Exception e) {
                FileExplorerResponse Response = new FileExplorerResponse();
                Response.error = e.GetType().FullName + ", " + e.Message;
                return(Response);
            }
        }
Пример #3
0
        public FileExplorerResponse Search(string path, string filter, string searchString, bool caseSensitive)
        {
            FileExplorerResponse SearchResponse = new FileExplorerResponse();

            try
            {
                string          physicalPath   = GetPath(path);
                FileAccessRules RootPermission = GetPathPermission(path);
                if (!RootPermission.Read)
                {
                    throw new ArgumentException("'" + path + "' is not accessible. Access is denied.");
                }
                SearchResponse = FileExplorerOperations.Search(path, filter, searchString, caseSensitive);
                var items = SearchResponse.files.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    FileAccessRules PathPermission = GetPathPermission(path + items[i].filterPath.Replace("\\", "/"));
                    if (!PathPermission.Read)
                    {
                        items = items.Where((val, idx) => idx != i).ToArray();
                        i--;
                        continue;
                    }
                    items[i].permission = GetFilePermission(physicalPath + items[i].filterPath, items[i].name, items[i].isFile);
                    if (items[i].isFile)
                    {
                        items[i].permission.EditContents = PathPermission.EditContents;
                        items[i].permission.Upload       = PathPermission.Upload;
                    }
                }
                SearchResponse.files = items;
                return(SearchResponse);
            }
            catch (Exception e)
            {
                SearchResponse.error = e.GetType().FullName + ", " + e.Message;
                return(SearchResponse);
            }
        }