public static void CreateFolder(int FolderID, string filePath, string folderName, int fileType, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (!dir.Exists)
            {
                dir.Create();
                Folder folder = new Folder();
                folder.PortalId        = fb.GetPortalID;
                folder.ParentID        = FolderID;
                folder.FolderPath      = filePath;
                folder.StorageLocation = fileType;
                folder.UniqueId        = Guid.NewGuid();
                folder.VersionGuid     = Guid.NewGuid();
                folder.IsActive        = 1;
                folder.AddedBy         = fb.GetUsername;
                try
                {
                    FileManagerController.AddFolder(folder);
                    CacheHelper.Clear("FileManagerFolders");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
    }
    public static string RecurseThroughDirectory(DirectoryInfo dir, int folderId, int UserModuleID, ref StringBuilder sb)
    {
        foreach (FileInfo file in dir.GetFiles())
        {
            ATTFile obj = new ATTFile();
            obj.PortalId        = fb.GetPortalID;
            obj.UniqueId        = Guid.NewGuid();
            obj.VersionGuid     = Guid.NewGuid();
            obj.FileName        = file.Name;
            obj.Extension       = file.Extension;
            obj.Size            = int.Parse(file.Length.ToString());
            obj.ContentType     = FileManagerHelper.ReturnExtension(file.Extension);
            obj.Folder          = FileManagerHelper.ReplaceBackSlash(dir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, ""));
            obj.FolderId        = folderId;
            obj.IsActive        = 1;
            obj.StorageLocation = 0;
            obj.AddedBy         = fb.GetUsername;

            try
            {
                if (FileManagerHelper.CheckForValidExtensions(UserModuleID, file.Extension.Replace(".", ""), fb.GetPortalID))
                {
                    FileManagerController.AddFile(obj);
                    sb.Append("File ").Append("Extraction completed successfully");
                }
                else
                {
                    sb.Append("File ").Append(file.Name).Append(" has invalid extension \n");
                }
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        foreach (DirectoryInfo childDir in dir.GetDirectories())
        {
            Folder folder = new Folder();
            folder.PortalId        = fb.GetPortalID;
            folder.ParentID        = folderId;
            folder.FolderPath      = FileManagerHelper.ReplaceBackSlash(childDir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, ""));
            folder.StorageLocation = 0;
            folder.UniqueId        = Guid.NewGuid();
            folder.VersionGuid     = Guid.NewGuid();
            folder.IsActive        = 1;
            folder.IsRoot          = false;
            folder.AddedBy         = fb.GetUsername;
            try
            {
                int FolderID = FileManagerController.AddFolderReturnFolderID(folder);
                RecurseThroughDirectory(childDir, FolderID, UserModuleID, ref sb);
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        return(sb.ToString());
    }
示例#3
0
    public static void AddRootFolder(string FolderName, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), FolderName));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (dir.Exists)
            {
                dir.Create();
                CacheHelper.Clear("FileManagerFolders");
            }
        }
    }
    public static string GetUrlPath(string path)
    {
        string relativePathInitial = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath + "/";

        relativePathInitial = (FileManagerHelper.ReplaceBackSlash(Path.Combine(relativePathInitial, path)));
        if (relativePathInitial.Contains("SageFrame/"))
        {
            string[] stringSeparators = new string[] { "SageFrame/" };
            string[] imgPath;
            imgPath = relativePathInitial.Split(stringSeparators, StringSplitOptions.None);
            string testapth = HttpContext.Current.Request.ApplicationPath + "/" + imgPath[1];
            return(HttpContext.Current.Request.ApplicationPath + "/" + imgPath[1]);
        }
        else
        {
            return(HttpContext.Current.Request.ApplicationPath);
        }
    }
        private void BindTree()
        {
            TreeView1.Nodes.Clear();
            string   rootFolder = BaseDir;
            TreeNode rootNode   = new TreeNode();

            string relativePath = FileManagerHelper.ReplaceBackSlash(Request.PhysicalApplicationPath.ToString());

            relativePath = relativePath.Substring(0, relativePath.LastIndexOf("/"));
            string root = Request.ApplicationPath.ToString();

            rootNode.Text     = Path.Combine(BaseDir.Replace(relativePath, ""), root);
            rootNode.Expanded = true;
            rootNode.Value    = rootFolder.Replace("\\", "~").Replace(" ", "|");
            TreeView1.Nodes.Add(rootNode);
            TreeView1.ShowLines = true;
            BuildTreeDirectory(rootFolder, rootNode);
        }
    public static void AddRootFolder(string FolderName)
    {
        string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), FolderName));
        DirectoryInfo dir          = new DirectoryInfo(absolutePath);

        if (dir.Exists)
        {
            dir.Create();
            Folder folder = new Folder();
            folder.PortalId        = fb.GetPortalID;
            folder.FolderPath      = FolderName;
            folder.StorageLocation = 0;
            folder.UniqueId        = Guid.NewGuid();
            folder.VersionGuid     = Guid.NewGuid();
            folder.IsActive        = 1;
            folder.AddedBy         = fb.GetUsername;
            FileManagerController.AddRootFolder(folder);
            CacheHelper.Clear("FileManagerFolders");
        }
    }
    public static string UnzipFiles(string FilePath, int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath  = GetAbsolutePath(FilePath);
            FileInfo      file          = new FileInfo(absolutePath);
            string        folderName    = file.Name;
            string        newFolderPath = FileManagerHelper.GetFilePathWithoutExtension(absolutePath);
            DirectoryInfo dir           = new DirectoryInfo(newFolderPath);
            if (!dir.Exists)
            {
                string path = string.Empty;
                FileManagerHelper.UnZipFiles(absolutePath, newFolderPath, ref path, SageFrame.Common.RegisterModule.Common.Password, false, userModuleID, fb.GetPortalID);
                Folder folder = new Folder();
                folder.PortalId        = fb.GetPortalID;
                folder.ParentID        = FolderID;
                folder.FolderPath      = FileManagerHelper.ReplaceBackSlash(FileManagerHelper.GetFilePathWithoutExtension(FilePath));
                folder.StorageLocation = 0;
                folder.UniqueId        = Guid.NewGuid();
                folder.VersionGuid     = Guid.NewGuid();
                folder.IsActive        = 1;
                folder.IsRoot          = false;
                folder.AddedBy         = fb.GetUsername;
                try
                {
                    int folderID = FileManagerController.AddFolderReturnFolderID(folder);
                    RecurseThroughDirectory(dir, folderID, userModuleID, ref sb);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
            CacheHelper.Clear("FileManagerFileList");
            CacheHelper.Clear("FileManagerFolders");
        }
        return(sb.ToString());
    }
示例#8
0
    public static void CreateFolder(int FolderID, string filePath, string folderName, int fileType, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (!dir.Exists)
            {
                dir.Create();
                try
                {
                    CacheHelper.Clear("FileManagerFolders");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
    }
 public static string GetAbsolutePath(string filepath)
 {
     return(FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filepath)));
 }
 protected static string GetRelativePath(string filePath)
 {
     return(FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.ApplicationPath.ToString(), filePath)));
 }
    public static string GetFileList(string filePath, int folderId, int UserID, int IsSort, int CurrentPage, int PageSize, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            System.IO.DirectoryInfo di       = new System.IO.DirectoryInfo(filePath);
            List <ATTFile>          lstFiles = new List <ATTFile>();
            if (filePath == "/")
            {
                filePath = HttpContext.Current.Server.MapPath("~/");
            }
            try
            {
                if (Directory.Exists(filePath))
                {
                    DirectoryInfo dirInfo = new DirectoryInfo(filePath);
                    foreach (FileInfo file in dirInfo.GetFiles())
                    {
                        ATTFile obj = new ATTFile();
                        obj.FileName  = file.Name;
                        obj.Folder    = file.Directory.ToString();
                        obj.Size      = int.Parse(file.Length.ToString());
                        obj.Extension = file.Extension;
                        lstFiles.Add(obj);
                    }
                }
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
            if (IsSort == 1)
            {
                SortList(ref lstFiles);
            }
            Dictionary <string, string> dictImages = GetImages();
            if (lstFiles.Count > 0)
            {
                lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count));
                ///Get the dictionary of images used in buttons

                sb.Append("<div class='sfGridwrapper'><table  width='100%' cellspacing='0' cellpadding='0' class=\"jqueryFileTree\" id=\"fileList\">\n");
                if (lstFiles.Count > 0 && HttpContext.Current.Session["SortDir"] == null || (string)HttpContext.Current.Session["SortDir"] == "asc")
                {
                    sb.Append("<tr><th><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span></th><th><span class='fileName'>FileName &nbsp;&nbsp;<i class='icon-ascending-order' id='imgSort'></i></span></th><th><span class='fileInfo'>FileInfo</span></th><th class='sfEdit'></th><th class='sfEdit'></th><th class='sfEdit'></th></tr>");
                }
                else if (lstFiles.Count > 0 && (string)HttpContext.Current.Session["SortDir"] == "desc")
                {
                    sb.Append("<tr><th><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span></th><th><span class='fileName'>FileName &nbsp;&nbsp;<i class='icon-descending-order' id='imgSort' ></i></span></th><th><span class='fileInfo'>FileInfo</span></th><th class='sfEdit'></th><th class='sfEdit'></th><th class='sfEdit'></th></tr>");
                }
            }
            if (lstFiles.Count == 0)
            {
                sb.Append("<div class='sfEmptyrow'>No Files</div>");
            }
            string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?")));
            // string urlPath = GetUrlPath(filePath);
            string urlPath      = GetPreviewUrlPath(filePath);
            string absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));
            int    index        = 0;
            foreach (ATTFile fi in lstFiles)
            {
                string ext   = "";
                bool   IsZip = false;
                bool   IsImg = false;

                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                try
                {
                    FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, urlPath + fi.FileName, Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages, index, secureToken);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
                index++;
            }
            sb.Append("</table></div>");
            sb.Append("<div id='divBottomControl'>");
            sb.Append("</div>");
        }
        return(sb.ToString());
    }
    public static string SearchFiles(string SearchQuery, int CurrentPage, int PageSize, string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            if (FilePath == "/")
            {
                FilePath = HttpContext.Current.Server.MapPath("~/");
            }

            List <ATTFile> lstFiles = new List <ATTFile>();
            if (Directory.Exists(FilePath))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
                foreach (FileInfo file in dirInfo.GetFiles(SearchQuery + "*"))
                {
                    ATTFile obj = new ATTFile();
                    obj.FileName  = file.Name;
                    obj.Folder    = file.Directory.ToString();
                    obj.Size      = int.Parse(file.Length.ToString());
                    obj.Extension = file.Extension;
                    lstFiles.Add(obj);
                }
            }

            Dictionary <string, string> dictImages = GetImages();
            List <string> lstPermissions           = FileManagerController.GetModulePermission(userModuleID, userName);
            int           UserPermissionKey        = lstPermissions.Contains("EDIT") ? 1 : 0;
            if (lstFiles.Count > 0)
            {
                lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count));
            }

            sb.Append("<div class='sfGridwrapper'><table  width='100%' cellspacing='0' cellpadding='0' class=\"jqueryFileTree\" id=\"fileList\">\n");
            if (lstFiles.Count > 0)
            {
                sb.Append("<tr><th><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span></th><th><span class='fileName'>FileName<img src=" + dictImages["Sort"].ToString() + "></span></th><th><span class='fileInfo'>FileInfo</span></th><th class='sfEdit'></th><th class='sfEdit'></th><th class='sfEdit'></th></tr>");
            }
            if (lstFiles.Count == 0)
            {
                sb.Append("<div class='sfEmptyrow'>No Files</div>");
            }
            string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?")));



            if (UserPermissionKey == 1)
            {
                int index = 0;
                foreach (ATTFile fi in lstFiles)
                {
                    string ext = "";
                    //bool IsZip = false;
                    bool IsImg = false;
                    if (fi.Extension.Length > 1)
                    {
                        ext = fi.Extension.Substring(1).ToLower();
                    }
                    // if (ext == "zip")
                    //     IsZip = true;
                    if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                    {
                        IsImg = true;
                    }
                    string checkId = "chk_" + fi.FileId;
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "edit", dictImages, index, secureToken);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                    index++;
                }
            }
            else
            {
                int index = 0;
                foreach (ATTFile fi in lstFiles)
                {
                    string ext = "";
                    //  bool IsZip = false;
                    bool IsImg = false;
                    if (fi.Extension.Length > 1)
                    {
                        ext = fi.Extension.Substring(1).ToLower();
                    }
                    //if (ext == "zip")
                    //   IsZip = true;
                    if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                    {
                        IsImg = true;
                    }
                    string checkId = "chk_" + fi.FileId;
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "view", dictImages, index, secureToken);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                    index++;
                }
            }
            sb.Append("</table>");
            sb.Append("<div id='divPagerNav'></div>");
            sb.Append("</div>");
        }
        return(sb.ToString());
    }
    public static string GetUrlPath(string path)
    {
        string relativePathInitial = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath + "/";

        return(FileManagerHelper.ReplaceBackSlash(Path.Combine(relativePathInitial, path)));
    }
    public static string SearchFiles(string SearchQuery, int UserModuleID, string UserName, int CurrentPage, int PageSize)
    {
        StringBuilder  sb       = new StringBuilder();
        bool           IsZip    = false;
        bool           IsImg    = false;
        List <ATTFile> lstFiles = FileManagerController.SearchFiles(SearchQuery);
        Dictionary <string, string> dictImages = GetImages();

        List <string> lstPermissions    = FileManagerController.GetModulePermission(UserModuleID, UserName);
        int           UserPermissionKey = lstPermissions.Contains("EDIT") ? 1 : 0;

        if (lstFiles.Count > 0)
        {
            lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count));
        }

        if (lstFiles.Count > 0)
        {
            sb.Append("<div id='divFileHeader'><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span><span class='fileName'>FileName</span><span class='fileInfo'>FileInfo</span></div>");
        }

        sb.Append("<ul class=\"jqueryFileTree\" id=\"fileList\">\n");
        if (lstFiles.Count == 0)
        {
            sb.Append("<div class='cssClassNoFilesDiv'>No Files</div>");
        }
        string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?")));



        if (UserPermissionKey == 1)
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                try
                {
                    FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "edit", dictImages);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
        else
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                try
                {
                    FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "view", dictImages);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
        sb.Append("</ul>");
        sb.Append("<div id='divBottomControl'>");
        sb.Append("<div id='divPagerNav'></div>");
        sb.Append("</div>");


        return(sb.ToString());
    }
    public static string GetFileList(string filePath, int folderId, int UserID, int IsSort, int UserModuleID, int CurrentPage, int PageSize)
    {
        List <string> lstPermissionKeys = FileMangerDataProvider.GetPermissionKeys(folderId, UserID, UserModuleID, "superuser");
        StringBuilder sb = new StringBuilder();

        System.IO.DirectoryInfo di         = new System.IO.DirectoryInfo(filePath);
        List <Folder>           lstFolders = new List <Folder>();

        if (!CacheHelper.Get("FileManagerFolders", out lstFolders))
        {
            lstFolders = FileManagerController.GetFolders();
            CacheHelper.Add(lstFolders, "FileManagerFolders");
        }


        List <ATTFile> lstFiles = new List <ATTFile>();

        List <FileCacheInfo> lstCache = new List <FileCacheInfo>();


        if (!CacheHelper.Get("FileManagerFileList", out lstCache))    //if the cache list does not exist,then create on
        {
            try
            {
                lstFiles = FileManagerController.GetFiles(folderId);
                List <FileCacheInfo> lstFCI   = new List <FileCacheInfo>();
                FileCacheInfo        cacheObj = new FileCacheInfo();
                cacheObj.FolderID = folderId;
                cacheObj.LSTFiles = lstFiles;
                lstFCI.Add(cacheObj);
                CacheHelper.Add(lstFCI, "FileManagerFileList");
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        else     //if the cache list exists
        {
            int cacheIndex = lstCache.FindIndex(
                delegate(FileCacheInfo obj)
            {
                return(obj.FolderID == folderId);
            }
                );
            if (cacheIndex > -1)
            {
                lstFiles = lstCache[cacheIndex].LSTFiles;
            }
            else
            {
                try
                {
                    lstFiles = FileManagerController.GetFiles(folderId);
                    List <FileCacheInfo> lstFCI   = lstCache;
                    FileCacheInfo        cacheObj = new FileCacheInfo();
                    cacheObj.FolderID = folderId;
                    cacheObj.LSTFiles = lstFiles;
                    lstFCI.Add(cacheObj);
                    CacheHelper.Add(lstFCI, "FileManagerFileList");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }


        if (IsSort == 1)
        {
            SortList(ref lstFiles);
        }
        if (lstFiles.Count > 0)
        {
            lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count));
        }

        ///Get the dictionary of images used in buttons
        Dictionary <string, string> dictImages = GetImages();

        if (lstFiles.Count > 0)
        {
            sb.Append("<div id='divFileHeader'><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span><span class='fileName'>FileName<img src=" + dictImages["Sort"].ToString() + "></span><span class='fileInfo'>FileInfo</span></div>");
        }
        sb.Append("<ul class=\"jqueryFileTree\" id=\"fileList\">\n");
        if (lstFiles.Count == 0)
        {
            sb.Append("<div class='cssClassNoFilesDiv'>No Files</div>");
        }
        string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?")));
        string test         = HttpContext.Current.Request.PhysicalApplicationPath.ToString();
        string urlPath      = GetUrlPath(filePath);
        string absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));



        ///For Users with View and Write Permissions
        bool IsZip = false;
        bool IsImg = false;

        if (((lstPermissionKeys.Contains("BROWSE") && lstPermissionKeys.Contains("VIEW")) && lstPermissionKeys.Contains("EDIT")) || lstPermissionKeys.Contains("EDIT"))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else if (fi.StorageLocation == (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                }
            }
        }
        ///For users with only browse permission
        else if (((lstPermissionKeys.Contains("BROWSE") && !lstPermissionKeys.Contains("VIEW")) && !lstPermissionKeys.Contains("EDIT")))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;

                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                }
            }
        }
        else if (((lstPermissionKeys.Contains("VIEW")) && !lstPermissionKeys.Contains("EDIT")))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                }
            }
        }
        sb.Append("</ul>");
        sb.Append("<div id='divBottomControl'>");
        sb.Append("</div>");
        return(sb.ToString());
    }
示例#16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string dir;

        HttpContext c = HttpContext.Current;

        if (c != null)
        {
            List <Folder> lstRootFolders = FileManagerController.GetActiveRootFolders();
            if (c.Request.Form["dir"] == null || c.Request.Form["dir"].Length <= 0)
            {
                dir = "/";
            }
            else
            {
                dir = c.Server.UrlDecode(c.Request.Form["dir"]);
            }

            string rootPath = c.Request.PhysicalApplicationPath.ToString();


            c.Response.Write("<ul class=\"jqueryFileTree\" style=\"display: none;\">\n");

            if (dir.Equals("/"))
            {
                foreach (Folder folder in lstRootFolders)
                {
                    if (Directory.Exists(Path.Combine(rootPath, folder.FolderPath)))
                    {
                        DirectoryInfo dirInfo = new DirectoryInfo(folder.FolderPath);
                        switch (folder.StorageLocation)
                        {
                        case 0:
                            Response.Write("\t<li class=\"directory collapsed\"><a id=" + folder.FolderId + " href=\"#\" rel=\"" + folder.FolderPath + "/\">" + dirInfo.Name + "</a></li>\n");
                            break;

                        case 1:
                            Response.Write("\t<li class=\"locked collapsed\"><a id=" + folder.FolderId + " href=\"#\" rel=\"" + folder.FolderPath + "/\">" + dirInfo.Name + "</a></li>\n");
                            break;

                        case 2:
                            Response.Write("\t<li class=\"database collapsed\"><a id=" + folder.FolderId + " href=\"#\" rel=\"" + folder.FolderPath + "/\">" + dirInfo.Name + "</a></li>\n");
                            break;
                        }
                    }
                }
            }
            else
            {
                System.IO.DirectoryInfo di         = new System.IO.DirectoryInfo(FileManagerHelper.ReplaceBackSlash(Path.Combine(rootPath, dir)));
                List <Folder>           lstFolders = new List <Folder>();
                if (!CacheHelper.Get("FileManagerFolders", out lstFolders))
                {
                    lstFolders = FileManagerController.GetFolders();
                    CacheHelper.Add(lstFolders, "FileManagerFolders");
                }


                foreach (System.IO.DirectoryInfo di_child in di.GetDirectories())
                {
                    string fullPath = di_child.FullName.Replace('\\', '/');
                    int index = lstFolders.FindIndex(
                        delegate(Folder obj)
                    {
                        return(FileManagerHelper.ReplaceBackSlash(Path.Combine(rootPath, obj.FolderPath)) == fullPath);
                    }
                        );

                    if (index > -1)
                    {
                        switch (lstFolders[index].StorageLocation)
                        {
                        case 0:
                            c.Response.Write("\t<li class=\"directory collapsed\"><a id=" + lstFolders[index].FolderId + " href=\"#\" rel=\"" + dir + di_child.Name + "/\">" + di_child.Name + "</a></li>\n");
                            break;

                        case 1:
                            c.Response.Write("\t<li class=\"locked collapsed\"><a id=" + lstFolders[index].FolderId + " href=\"#\" rel=\"" + dir + di_child.Name + "/\">" + di_child.Name + "</a></li>\n");
                            break;

                        case 2:
                            c.Response.Write("\t<li class=\"database collapsed\"><a id=" + lstFolders[index].FolderId + " href=\"#\" rel=\"" + dir + di_child.Name + "/\">" + di_child.Name + "</a></li>\n");
                            break;
                        }
                    }
                }
            }

            c.Response.Write("</ul>");
        }
    }