public override object CreateFolder(string path = null, string name = null, IEnumerable <object> selectedItems = null)
        {
            AddFolder(selectedItems, name, String.Empty, null);
            SQLFileExplorerResponse         CreateResponse = new SQLFileExplorerResponse();
            SQLFileExplorerDirectoryContent content        = new SQLFileExplorerDirectoryContent();

            content.name = name;
            var directories = new[] { content };

            CreateResponse.files = (IEnumerable <SQLFileExplorerDirectoryContent>)directories;
            return(CreateResponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads all immediate files and sub-folders from the specified path and it returns the matched type of files, which are specified in “filter” parameter.
        /// </summary>
        /// <param name="path">Path of the selected folder.</param>
        /// <param name="filter">File types to filter.</param>
        /// <returns>System.Object.</returns>
        public virtual object Read(string path, string filter, IEnumerable <object> selectedItems = null)

        {
            SQLFileExplorerResponse ReadResponse = new SQLFileExplorerResponse();

            try
            {
                object ReadRes = operation.Read(path, filter, selectedItems);
                ReadResponse = (SQLFileExplorerResponse)ReadRes;
                string physicalPath = GetPath(path);
                ReadResponse.cwd.permission = GetPathPermission(path);
                if (!ReadResponse.cwd.permission.Read)
                {
                    SQLFileExplorerDirectoryContent[] fileDetails = new SQLFileExplorerDirectoryContent[0];
                    ReadResponse.files = fileDetails;
                    return(ReadResponse);
                }
                var items = ReadResponse.files.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    items[i].permission = GetFilePermission(physicalPath, items[i].name, items[i].isFile);
                    if (items[i].isFile)
                    {
                        items[i].permission.EditContents = ReadResponse.cwd.permission.EditContents;
                        items[i].permission.Upload       = ReadResponse.cwd.permission.Upload;
                    }
                }
                ReadResponse.files = items;
                return(ReadResponse);
            }
            catch (Exception e)
            {
                ReadResponse.error = e.GetType().FullName + ", " + e.Message;
                return(ReadResponse);
            }
        }
        public override object Read(string path = null, string filter = null, IEnumerable <object> selectedItems = null)
        {
            try
            {
                List <SQLFileExplorerDirectoryContent> details = new List <SQLFileExplorerDirectoryContent>();
                SqlDataReader myReader = null, myReader1 = null;
                int           ID     = RootNode;
                filter = filter.Replace(" ", "");
                var extensions       = (filter ?? "*").Split(",|;".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                if (selectedItems != null)
                {
                    foreach (SQLFileExplorerDirectoryContent item in selectedItems)
                    {
                        ID = item.itemId;
                        break;
                    }
                }
                SqlCommand myCommand = new SqlCommand("select ItemID, Name, ParentID, Size, IsFile, MimeType, Content From Product P INNER JOIN NameDetail N ON P.ItemID = N.FileId where ParentId =" + ID, Connection);
                // SqlCommand myCommand = new SqlCommand("select * from " + TableName + " where ParentId =" + ID, Connection);
                myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    bool canAdd = false;
                    if (extensions[0].Equals("*.*") || extensions[0].Equals("*"))
                    {
                        canAdd = true;
                    }
                    else if (myReader["IsFile"].ToString() == "True")
                    {
                        var names = myReader["Name"].ToString().Trim().Split('.');
                        if (Array.IndexOf(extensions, "*." + names[names.Count() - 1]) >= 0)
                        {
                            canAdd = true;
                        }
                        else
                        {
                            canAdd = false;
                        }
                    }
                    else
                    {
                        canAdd = true;
                    }
                    if (canAdd)
                    {
                        SQLFileExplorerDirectoryContent entry = new SQLFileExplorerDirectoryContent();
                        entry.itemId     = (int)myReader["ItemId"];
                        entry.name       = myReader["Name"].ToString().Trim();
                        entry.type       = myReader["IsFile"].ToString() == "True" ? myReader["MimeType"].ToString() : "Directory";
                        entry.isFile     = (bool)myReader["IsFile"];
                        entry.size       = (myReader["Size"].ToString() != "" ? (long)myReader["Size"] : 0);
                        entry.parentID   = (int)myReader["ParentId"];
                        entry.hasChild   = false;
                        entry.filterPath = "";
                        details.Add(entry);
                    }
                }
                myReader.Close();
                for (int i = 0; i < details.Count; i++)
                {
                    details[i].hasChild = HasChildDirectory(details[i].itemId);
                }

                SQLFileExplorerResponse ReadResponse = new SQLFileExplorerResponse();
                ReadResponse.files = (IEnumerable <SQLFileExplorerDirectoryContent>)details;
                SQLFileExplorerDirectoryContent cwd = new SQLFileExplorerDirectoryContent();
                SqlCommand myCommand1 = new SqlCommand("select ItemID, Name, ParentID, Size, IsFile, MimeType, Content From Product P INNER JOIN NameDetail N ON P.ItemID = N.FileId where ItemId =" + ID, Connection);
                // SqlCommand myCommand1 = new SqlCommand("select * from " + TableName + " where ItemId =" + ID, Connection);
                myReader1 = myCommand1.ExecuteReader();
                while (myReader1.Read())
                {
                    cwd.itemId       = (int)myReader1["ItemId"];
                    cwd.name         = myReader1["Name"].ToString().Trim();
                    cwd.type         = myReader1["IsFile"].ToString() == "True" ? myReader1["MimeType"].ToString() : "Directory";
                    cwd.isFile       = (bool)myReader1["IsFile"];
                    cwd.size         = (myReader1["Size"].ToString() != "" ? (long)myReader1["Size"] : 0);
                    cwd.parentID     = (int)myReader1["ParentId"];
                    cwd.hasChild     = true;
                    cwd.filterPath   = "";
                    ReadResponse.cwd = cwd;
                }
                return(ReadResponse);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(null);
        }