public static int GetSearchCount(string SearchQuery, string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        List <ATTFile>      lstFiles   = new List <ATTFile>();
        AuthenticateService objService = new AuthenticateService();

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

            if (Directory.Exists(FilePath))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
                foreach (FileInfo file in dirInfo.GetFiles(SearchQuery + "*"))
                {
                    ATTFile obj = new ATTFile();
                    obj.FileName = file.Name;
                    lstFiles.Add(obj);
                }
            }
        }
        return(lstFiles.Count);
    }
    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 int GetSearchCount(string SearchQuery, int UserModuleID, string UserName, string FilePath)
    {
        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;
                lstFiles.Add(obj);
            }
        }
        return(lstFiles.Count);
    }
Пример #4
0
    public void AddFileToDatabase(string fileName, string extension, string folder, int folderId, bool isDatabase, int saveMode)
    {
        string newFileName = fileName;

        if (saveMode == 1)
        {
            newFileName = fileName + ".resources";
        }
        FileInfo file = new FileInfo(GetAbsolutePath(folder + newFileName));
        ATTFile  obj  = new ATTFile();

        obj.PortalId        = fb.GetPortalID;
        obj.UniqueId        = Guid.NewGuid();
        obj.VersionGuid     = Guid.NewGuid();
        obj.FileName        = fileName;
        obj.Extension       = extension;
        obj.Size            = int.Parse(file.Length.ToString());
        obj.ContentType     = FileManagerHelper.ReturnExtension(extension);
        obj.Folder          = folder;
        obj.FolderId        = folderId;
        obj.IsActive        = 1;
        obj.StorageLocation = saveMode;
        obj.AddedBy         = fb.GetUsername;
        if (isDatabase)
        {
            byte[] _fileContent = FileManagerHelper.FileToByteArray(GetAbsolutePath(folder + fileName));
            obj.Content = _fileContent;
        }
        try
        {
            FileManagerController.AddFile(obj);
            if (saveMode == 2)
            {
                file.Delete();
            }
        }
        catch (Exception ex)
        {
            fb.ProcessException(ex);
        }
    }
    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());
    }