/// <summary>
        /// Connects to database and add file for given object of ATTFile class.
        /// </summary>
        /// <param name="file">Object of ATTFile class.</param>
        public static void AddFile(ATTFile file)
        {
            List <KeyValuePair <string, object> > ParaMeterCollection = new List <KeyValuePair <string, object> >();

            ParaMeterCollection.Add(new KeyValuePair <string, object>("@PortalId", file.PortalId));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@UniqueId", file.UniqueId));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@VersionGuid", file.VersionGuid));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@FileName", file.FileName));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@Extension", file.Extension));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@Size", file.Size));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@ContentType", file.ContentType));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@Folder", file.Folder));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@FolderId", file.FolderId));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@IsActive", file.IsActive));
            ParaMeterCollection.Add(new KeyValuePair <string, object>("@AddedBy", file.AddedBy));
            if (file.StorageLocation == 2)
            {
                ParaMeterCollection.Add(new KeyValuePair <string, object>("@Content", file.Content));
                SQLHandler sagesql = new SQLHandler();
                sagesql.ExecuteNonQuery("usp_FileManagerAddDatabaseFile", ParaMeterCollection);
            }
            else
            {
                SQLHandler sagesql = new SQLHandler();
                sagesql.ExecuteNonQuery("usp_FileManagerAddFile", ParaMeterCollection);
            }
        }
        public static List <ATTFile> SearchFiles(string SearchQuery)
        {
            List <ATTFile> lstFiles            = new List <ATTFile>();
            string         StoredProcedureName = "usp_FileManagerSearchFiles";
            SQLHandler     sagesql             = new SQLHandler();
            List <KeyValuePair <string, object> > ParaMeterCollection = new List <KeyValuePair <string, object> >();

            ParaMeterCollection.Add(new KeyValuePair <string, object>("@SearchQuery", SearchQuery));
            SqlDataReader SQLReader;

            try
            {
                SQLReader = sagesql.ExecuteAsDataReader(StoredProcedureName, ParaMeterCollection);
                while (SQLReader.Read())
                {
                    ATTFile obj = new ATTFile();
                    obj.FileId          = int.Parse(SQLReader["FileId"].ToString());
                    obj.FileName        = SQLReader["FileName"].ToString();
                    obj.Folder          = SQLReader["Folder"].ToString();
                    obj.Extension       = SQLReader["Extension"].ToString();
                    obj.Size            = int.Parse(SQLReader["Size"].ToString());
                    obj.AddedOn         = SQLReader["AddedOn"].ToString();
                    obj.Content         = SQLReader["Content"] == DBNull.Value ? null : (byte[])SQLReader["Content"];
                    obj.StorageLocation = int.Parse(SQLReader["StorageLocation"].ToString());

                    lstFiles.Add(obj);
                }
                SQLReader.Dispose();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(lstFiles);
        }
        public static void AddFile(ATTFile file)
        {
            List<KeyValuePair<string, object>> ParaMeterCollection = new List<KeyValuePair<string, object>>();
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@PortalId", file.PortalId));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@UniqueId", file.UniqueId));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@VersionGuid", file.VersionGuid));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@FileName", file.FileName));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@Extension", file.Extension));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@Size", file.Size));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@ContentType", file.ContentType));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@Folder", file.Folder));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@FolderId", file.FolderId));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@IsActive", file.IsActive));
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@AddedBy", file.AddedBy));
            if (file.StorageLocation == 2)
            {
                ParaMeterCollection.Add(new KeyValuePair<string, object>("@Content", file.Content));
                SQLHandler sagesql = new SQLHandler();
                sagesql.ExecuteNonQuery("usp_FileManagerAddDatabaseFile", ParaMeterCollection);
            }
            else
            {
                SQLHandler sagesql = new SQLHandler();
                sagesql.ExecuteNonQuery("usp_FileManagerAddFile", ParaMeterCollection);

            }
        }
Example #4
0
 public static void AddFile(ATTFile file)
 {
     try
     {
         FileMangerDataProvider.AddFile(file);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public static void AddFile(ATTFile file)
        {
            try
            {
                FileMangerDataProvider.AddFile(file);
            }
            catch (Exception)
            {
                throw;

            }
        }
        /// <summary>
        /// Connects to database and obtains file details for given FileID.
        /// </summary>
        /// <param name="FileID">FileID</param>
        /// <returns>List of ATTFile class containing file details.</returns>
        public static ATTFile GetFileDetails(int FileID)
        {
            List <KeyValuePair <string, object> > ParaMeterCollection = new List <KeyValuePair <string, object> >();

            ParaMeterCollection.Add(new KeyValuePair <string, object>("@FileID", FileID));

            SQLHandler sagesql = new SQLHandler();
            ATTFile    obj     = new ATTFile();

            obj = sagesql.ExecuteAsObject <ATTFile>("usp_FileManagerGetFileDetails", ParaMeterCollection);
            return(obj);
        }
Example #7
0
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="file">file</param>
        /// <param name="attributeString">attributeString</param>
        /// <param name="mode">mode</param>
        /// <returns>Return table column for desire class.</returns>

        public static string AddInfoSpan(ATTFile file, string attributeString, int mode)
        {
            string html = "";

            switch (mode)
            {
            case 2:
                html = "<td><span class=\"info\">" + file.AddedOn + "||" + file.Size + "bytes" + "</span></span></td>";
                break;

            default:
                html = "<td><span class=\"info\">" + file.AddedOn + "||" + file.Size + "bytes" + "||<span class=\"attr\">" + attributeString + "</span></span></td>";
                break;
            }
            return(html);
        }
Example #8
0
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="filePath">filePath</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="permission">permission</param>
        /// <param name="extension">extension</param>
        /// <returns>Return table column for desire class.</returns>
        public static string AddPopupLink(string filePath, int folderId, ATTFile file, string permission, string extension, string secureToken)
        {
            extension = string.Format("icon-{0}", extension);
            string name = file.FileName;

            if (file.FileName.Length > 40)
            {
                name = file.FileName.Substring(0, 40) + "...";
            }
            //if (permission == "edit" || permission == "view")
            //    return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");
            //else
            //    return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"#\" rel=" + file.FileName + ">" + file.FileName + "</a></td>");
            // return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");

            return("<td class='" + extension + "' width='30%'><a href=# class=\"download_link\"><span   value=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\"  id=\"spnEditImage\">" + name + "</a></span></td>");
        }
Example #9
0
        public static string AddDownloadLink(string filePath, int folderId, ATTFile file, string permission)
        {
            string name = file.FileName;

            if (file.FileName.Length > 40)
            {
                name = file.FileName.Substring(0, 40) + "...";
            }
            if (permission == "edit" || permission == "view")
            {
                return("<a class=\"download_link\" href=\"" + filePath + "FileID=" + file.FileId + "&FolderID=" + folderId + "\" rel=" + file.FileId + ">" + name + "</a>");
            }
            else
            {
                return("<a class=\"download_link\" href=\"#\" rel=" + file.FileId + ">" + file.FileName + "</a>");
            }
        }
Example #10
0
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="filePath">filePath</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="permission">permission</param>
        /// <param name="extension">extension</param>
        /// <returns>Return table column for desire class.</returns>
        public static string AddDownloadLink(string filePath, int folderId, ATTFile file, string permission, string extension, string secureToken)
        {
            extension = string.Format("ext_{0}", extension);
            string name = file.FileName;

            if (file.FileName.Length > 40)
            {
                name = file.FileName.Substring(0, 40) + "...";
            }
            if (permission == "edit" || permission == "view")
            {
                return("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");
            }
            else
            {
                return("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"#\" rel=" + file.FileName + ">" + file.FileName + "</a></td>");
            }
        }
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="filePath">filePath</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="permission">permission</param>
        /// <param name="extension">extension</param>
        /// <returns>Return table column for desire class.</returns>
        public static string AddDownloadLink(string filePath, int folderId, ATTFile file, string permission, string extension)
        {
            extension = string.Format("ext_{0}", extension);
            string name = file.FileName;
            if (file.FileName.Length > 40)
            {
                name = file.FileName.Substring(0, 40) + "...";
            }
            if (permission == "edit" || permission == "view")
                return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");
            else
                return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"#\" rel=" + file.FileName + ">" + file.FileName + "</a></td>");

        }
Example #12
0
         public static string AddDownloadLink(string filePath, int folderId, ATTFile file, string permission)
         {
             string name = file.FileName;
             if (file.FileName.Length > 40)
             {
                 name = file.FileName.Substring(0, 40) + "...";
             }
             if (permission == "edit" || permission == "view")
                 return ("<a class=\"download_link\" href=\"" + filePath + "FileID=" + file.FileId + "&FolderID=" + folderId + "\" rel=" + file.FileId + ">" + name + "</a>");
             else
                 return ("<a class=\"download_link\" href=\"#\" rel=" + file.FileId + ">" + file.FileName + "</a>");

         }
    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();
    }
 public static int GetSearchCount(string SearchQuery, string userName, string FilePath, int portalID, 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 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);
                }
                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);

                    }
                    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);
                    }
                    catch (Exception ex)
                    {

                        fb.ProcessException(ex);
                    }
                    index++;
                }
            }
            sb.Append("</table>");
            sb.Append("<div id='divPagerNav'></div>");
            sb.Append("</div>");

        }
        return sb.ToString();

    }
Example #17
0
 public static void RecurseThroughDirectory(DirectoryInfo di, int folderId, int folderType)
 {
     FileInfo[] files = di.GetFiles();
     foreach (FileInfo fi in files)
     {
         List <ATTFile> lstFile = FileManagerController.GetFiles(folderId);
         bool           exists  = false;
         int            size    = int.Parse(fi.Length.ToString());
         if (Path.GetExtension(fi.Name) == ".resources")
         {
             exists = lstFile.Exists(
                 delegate(ATTFile obj)
             {
                 return(obj.FileName == Path.GetFileNameWithoutExtension(fi.Name) && obj.FolderId == folderId);
             }
                 );
         }
         else
         {
             exists = lstFile.Exists(
                 delegate(ATTFile obj)
             {
                 return(obj.FileName == fi.Name && obj.FolderId == folderId);
             }
                 );
         }
         if (!exists)
         {
             //Add file to database
             if (folderType == 1)
             {
                 File.Move(fi.FullName, fi.FullName + ".resources");
                 ATTFile fileObj = new ATTFile(fi.Name, FileManagerHelper.ReplaceBackSlash(GetFolderPath(di.FullName.Replace(absolutePath, ""))), folderId, UserName, Path.GetExtension(fi.Name.Replace(".resources", "")), PortalID, Guid.NewGuid(), Guid.NewGuid(), size, FileManagerHelper.ReturnExtension(Path.GetExtension(fi.Name.Replace(".resources", ""))), 1, folderType);
                 FileManagerController.AddFile(fileObj);
             }
             else
             {
                 if (IsExtensionValid(Path.GetExtension(fi.Name)))
                 {
                     ATTFile fileObj = new ATTFile(fi.Name, FileManagerHelper.ReplaceBackSlash(GetFolderPath(di.FullName.Replace(absolutePath, ""))), folderId, UserName, Path.GetExtension(fi.Name), PortalID, Guid.NewGuid(), Guid.NewGuid(), int.Parse(fi.Length.ToString()), FileManagerHelper.ReturnExtension(Path.GetExtension(fi.Name)), 1, 0);
                     FileManagerController.AddFile(fileObj);
                 }
             }
         }
     }
     foreach (DirectoryInfo di_child in di.GetDirectories())
     {
         int newFolderId     = 0;
         int storageLocation = 0;
         int index           = lstFolders.FindIndex(
             delegate(Folder obj)
         {
             return(obj.FolderPath == GetFolderPath(di_child.FullName));
         }
             );
         if (index == -1)
         {
             //Add folder to the database and get the folderId into newFolderId
             Folder folder = new Folder();
             folder.PortalId        = PortalID;
             folder.FolderPath      = FileManagerHelper.ReplaceBackSlash(GetFolderPath(di_child.FullName));
             folder.StorageLocation = storageLocation;
             folder.UniqueId        = Guid.NewGuid();
             folder.VersionGuid     = Guid.NewGuid();
             folder.IsActive        = 1;
             folder.AddedBy         = UserName;
             folder.IsRoot          = false;
             newFolderId            = FileManagerController.AddFolderReturnFolderID(folder);
         }
         else if (index > -1)
         {
             newFolderId     = lstFolders[index].FolderId;
             storageLocation = lstFolders[index].StorageLocation;
         }
         RecurseThroughDirectory(di_child, newFolderId, storageLocation);
     }
 }
    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);
            }
      
        }
Example #19
0
        /// <summary>
        /// Creates a html string to be rendered based upon the dynamic conditions
        /// </summary>
        /// <param name="IsZip">IsZip</param>
        /// <param name="IsImg">IsImg</param>
        /// <param name="StorageLocation">StorageLocation</param>
        /// <param name="ext">ext</param>
        /// <param name="urlPath">urlPath</param>
        /// <param name="absolutePath">absolutePath</param>
        /// <param name="downloadPath">downloadPath</param>
        /// <param name="checkId">checkId</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="sb">sb</param>
        /// <param name="permission">permission</param>
        /// <param name="dictImages">dictImages</param>
        public static void ConstructHTMLString(bool IsZip, bool IsImg, int StorageLocation, string ext, string urlPath, string absolutePath, string downloadPath, string checkId, int folderId, ATTFile file, ref StringBuilder sb, string permission, Dictionary <string, string> dictImages, int index, string secureToken)
        {
            switch (StorageLocation)
            {
            case 0:
                string attStr = FileManagerHelper.GetAttributeString(absolutePath);
                if (IsZip)
                {
                    sb.Append(AddExtension(ext, index));
                    sb.Append(AddCheckBox(checkId));
                    sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext, secureToken));
                    sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                    sb.Append(AddExtractButton(Path.Combine(file.Folder, file.FileName), dictImages["Extract"].ToString(), permission));
                    sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                    sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));


                    sb.Append("</tr>");
                }
                else
                {
                    if (IsImg)
                    {
                        string imgpath = urlPath + file.Folder;
                        imgpath = Path.Combine(imgpath, file.FileName);
                        sb.Append(AddExtension(ext, index));
                        sb.Append(AddCheckBox(checkId));
                        //sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                        sb.Append(AddPopupLink(downloadPath, folderId, file, permission, ext, secureToken));
                        sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                        sb.Append(AddPreviewButton(urlPath, dictImages["Preview"].ToString()));
                        sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                        sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));
                        sb.Append("</tr>");
                    }
                    else
                    {
                        sb.Append(AddExtension(ext, index));
                        sb.Append(AddCheckBox(checkId));
                        //sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                        sb.Append(AddPopupLink(downloadPath, folderId, file, permission, ext, secureToken));
                        sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                        sb.Append(AddBlankSpan());
                        sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));

                        sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                        sb.Append("</tr>");
                    }
                }
                break;

            case 1:
                string attStr1 = FileManagerHelper.GetAttributeString(absolutePath + ".resources");
                sb.Append(AddExtension(ext, index));
                sb.Append(AddCheckBox(checkId));
                sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext, secureToken));
                sb.Append(AddInfoSpan(file, attStr1, StorageLocation));
                sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                sb.Append(AddBlankSpan());
                sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                sb.Append("</tr>");
                break;

            case 2:
                sb.Append(AddExtension(ext, index));
                sb.Append(AddCheckBox(checkId));
                sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext, secureToken));
                sb.Append(AddInfoSpan(file, "", StorageLocation));
                sb.Append(AddBlankSpan());
                sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                sb.Append("</li>");
                break;
            }
        }
Example #20
0
        /// <summary>
        /// Copy or Move the file to the fullToPath location
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileId"></param>
        /// <param name="toFolderId"></param>
        /// <param name="toPath"></param>
        /// <param name="action"></param>
        /// <param name="mode"></param>
        /// <param name="fullFilePath"></param>
        /// <param name="fullFromPath"></param>
        /// <param name="fullToPath"></param>
        public static void TransferFile(string filePath, int fileId, int toFolderId, string toPath, int action, int mode, string fullFilePath, string fullFromPath, string fullToPath)
        {
            switch (mode)
            {
            case 1:
                switch (action)
                {
                case 1:
                    FileInfo fileCopy     = new FileInfo(fullFilePath);
                    string   fileNameCopy = fileCopy.Name;
                    if (!File.Exists(Path.Combine(fullToPath, fileNameCopy)))
                    {
                        try
                        {
                            fileCopy.CopyTo(Path.Combine(fullToPath, fileNameCopy));
                            FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove     = new FileInfo(fullFilePath);
                    string   fileNameMove = fileMove.Name;
                    if (fileMove.Exists)
                    {
                        try
                        {
                            fileMove.MoveTo(fullToPath + fileNameMove);
                            FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 2:
                switch (action)
                {
                case 1:
                    FileInfo fileCopy     = new FileInfo(fullFilePath);
                    string   fileNameCopy = fileCopy.Name;
                    /// Checking if file exists
                    if (!File.Exists(fullToPath + fileNameCopy + ".resources"))
                    {
                        try
                        {
                            fileCopy.CopyTo(fullToPath + fileNameCopy + ".resources");
                            FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove = new FileInfo(fullFilePath);
                    string   fileName = fileMove.Name;
                    if (fileMove.Exists)
                    {
                        try
                        {
                            fileMove.MoveTo(fullToPath + fileName + ".resources");
                            FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 3:
                switch (action)
                {
                case 1:
                    FileInfo fileCopy = new FileInfo(fullFilePath);
                    ATTFile  objCopy  = new ATTFile();
                    objCopy.FileName        = fileCopy.Name;
                    objCopy.Folder          = toPath;
                    objCopy.FolderId        = toFolderId;
                    objCopy.AddedBy         = "superuser";
                    objCopy.Extension       = fileCopy.Extension;
                    objCopy.PortalId        = 1;
                    objCopy.UniqueId        = Guid.NewGuid();
                    objCopy.VersionGuid     = Guid.NewGuid();
                    objCopy.Size            = int.Parse(fileCopy.Length.ToString());
                    objCopy.ContentType     = FileManagerHelper.ReturnExtension(fileCopy.Extension);
                    objCopy.IsActive        = 1;
                    objCopy.StorageLocation = 2;
                    if (fileCopy.Exists)
                    {
                        byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                        objCopy.Content = _fileContent;
                        try
                        {
                            FileManagerController.AddFile(objCopy);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove = new FileInfo(fullFilePath);
                    ATTFile  objMove  = new ATTFile();
                    objMove.FileName        = fileMove.Name;
                    objMove.Folder          = toPath;
                    objMove.FolderId        = toFolderId;
                    objMove.AddedBy         = "superuser";
                    objMove.Extension       = fileMove.Extension;
                    objMove.PortalId        = 1;
                    objMove.UniqueId        = Guid.NewGuid();
                    objMove.VersionGuid     = Guid.NewGuid();
                    objMove.Size            = int.Parse(fileMove.Length.ToString());
                    objMove.ContentType     = FileManagerHelper.ReturnExtension(fileMove.Extension);
                    objMove.IsActive        = 1;
                    objMove.StorageLocation = 2;
                    if (fileMove.Exists)
                    {
                        byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                        objMove.Content = _fileContent;
                        try
                        {
                            FileManagerController.AddFile(objMove);
                            fileMove.Delete();
                            FileManagerController.DeleteFileFolder(0, fileId);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 4:
                switch (action)
                {
                case 1:
                    FileInfo fileCopy = new FileInfo(fullFilePath + ".resources");
                    /// Checking if file exists
                    string fileNameCopy = "";
                    fileNameCopy = fileCopy.Name;
                    if (!File.Exists(Path.Combine(fullToPath, fileNameCopy.Replace(".resources", ""))))
                    {
                        try
                        {
                            fileCopy.CopyTo(Path.Combine(fullToPath, fileNameCopy.Replace(".resources", "")));
                            FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove     = new FileInfo(fullFilePath + ".resources");
                    string   fileNameMove = fileMove.Name;
                    if (fileMove.Exists)
                    {
                        try
                        {
                            fileMove.MoveTo(Path.Combine(fullToPath, fileNameMove.Replace(".resources", "")));
                            FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 5:
                switch (action)
                {
                case 1:
                    FileInfo file11 = new FileInfo(fullFilePath + ".resources");
                    /// Checking if file exists
                    string fileName11 = "";
                    fileName11 = filePath.Substring(filePath.LastIndexOf('/') + 1, filePath.Length - 1 - filePath.LastIndexOf('/'));
                    if (!File.Exists(fullToPath + fileName11 + ".resources"))
                    {
                        try
                        {
                            file11.CopyTo(fullToPath + fileName11 + ".resources");
                            FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove = new FileInfo(fullFilePath + ".resources");
                    /// Checking if file exists
                    string fileNameMove = fileMove.Name;
                    if (fileMove.Exists)
                    {
                        try
                        {
                            fileMove.MoveTo(Path.Combine(fullFilePath, fileNameMove + ".resources"));
                            FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 6:
                switch (action)
                {
                case 1:
                    FileInfo file12 = new FileInfo(fullFilePath + ".resources");
                    ATTFile  obj12  = new ATTFile();
                    obj12.FileName        = RemoveResourceExtension(file12.Name);
                    obj12.Folder          = toPath;
                    obj12.FolderId        = toFolderId;
                    obj12.AddedBy         = "superuser";
                    obj12.Extension       = file12.Extension;
                    obj12.PortalId        = 1;
                    obj12.UniqueId        = Guid.NewGuid();
                    obj12.VersionGuid     = Guid.NewGuid();
                    obj12.Size            = int.Parse(file12.Length.ToString());
                    obj12.ContentType     = FileManagerHelper.ReturnExtension(file12.Extension);
                    obj12.IsActive        = 1;
                    obj12.StorageLocation = 2;
                    if (new FileInfo(fullFilePath + ".resources").Exists)
                    {
                        File.Move(fullFilePath + ".resources", fullFilePath);
                        byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                        obj12.Content = _fileContent;
                        try
                        {
                            FileManagerController.AddFile(obj12);
                            File.Move(fullFilePath, fullFilePath + ".resources");
                        }
                        catch (Exception)
                        {
                            if (File.Exists(fullFilePath))
                            {
                                File.Move(fullFilePath, fullFilePath + ".resources");
                            }

                            throw;
                        }
                    }
                    break;

                case 2:
                    FileInfo fileMove = new FileInfo(fullFilePath + ".resources");
                    ATTFile  objMove  = new ATTFile();
                    objMove.FileName        = RemoveResourceExtension(fileMove.Name);
                    objMove.Folder          = toPath;
                    objMove.FolderId        = toFolderId;
                    objMove.AddedBy         = "superuser";
                    objMove.Extension       = fileMove.Extension;
                    objMove.PortalId        = 1;
                    objMove.UniqueId        = Guid.NewGuid();
                    objMove.VersionGuid     = Guid.NewGuid();
                    objMove.Size            = int.Parse(new FileInfo(fullFilePath + ".resources").Length.ToString());
                    objMove.ContentType     = FileManagerHelper.ReturnExtension(fileMove.Extension);
                    objMove.IsActive        = 1;
                    objMove.StorageLocation = 2;
                    if (new FileInfo(fullFilePath + ".resources").Exists)
                    {
                        byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath + ".resources");
                        objMove.Content = _fileContent;
                        try
                        {
                            FileManagerController.AddFile(objMove);
                            File.Delete(fullFilePath + ".resources");
                            FileManagerController.DeleteFileFolder(0, fileId);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    break;
                }
                break;

            case 7:
                switch (action)
                {
                case 1:
                    ATTFile obj20 = new ATTFile();
                    obj20 = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string newFilePath = Path.Combine(fullToPath, obj20.FileName);
                        if (!File.Exists(newFilePath))
                        {
                            FileManagerHelper.WriteBinaryFile(newFilePath, obj20.Content);
                            FileInfo file20   = new FileInfo(newFilePath);
                            ATTFile  obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser",
                                                            file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(),
                                                            int.Parse(file20.Length.ToString()),
                                                            FileManagerHelper.ReturnExtension(file20.Extension), 1, 0);
                            FileManagerController.AddFile(obj20New);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;

                case 2:
                    ATTFile objMove = new ATTFile();
                    objMove = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string newFilePath = Path.Combine(fullToPath, objMove.FileName);
                        FileManagerHelper.WriteBinaryFile(newFilePath, objMove.Content);
                        FileInfo file20   = new FileInfo(newFilePath);
                        ATTFile  obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser", file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file20.Length.ToString()), FileManagerHelper.ReturnExtension(file20.Extension), 1, 0);
                        FileManagerController.AddFile(obj20New);
                        FileManagerController.DeleteFileFolder(0, fileId);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;
                }
                break;

            case 8:
                switch (action)
                {
                case 1:
                    ATTFile obj21 = new ATTFile();
                    obj21 = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string newFilePath = Path.Combine(fullToPath, obj21.FileName);
                        if (!File.Exists(newFilePath + ".resources"))
                        {
                            FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", obj21.Content);
                            FileInfo file21   = new FileInfo(newFilePath + ".resources");
                            ATTFile  obj21New = new ATTFile(file21.Name, toPath, toFolderId, "superuser",
                                                            file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(),
                                                            int.Parse(file21.Length.ToString()),
                                                            FileManagerHelper.ReturnExtension(file21.Extension), 1, 1);
                            FileManagerController.AddFile(obj21New);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;

                case 2:
                    ATTFile objMove = new ATTFile();
                    objMove = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string newFilePath = Path.Combine(fullToPath, objMove.FileName);
                        FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", objMove.Content);
                        FileInfo file21   = new FileInfo(newFilePath + ".resources");
                        ATTFile  obj21New = new ATTFile(file21.Name.Replace(".resources", ""), toPath, toFolderId, "superuser", file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file21.Length.ToString()), FileManagerHelper.ReturnExtension(file21.Extension), 1, 1);
                        FileManagerController.AddFile(obj21New);
                        FileManagerController.DeleteFileFolder(0, fileId);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;
                }
                break;

            case 9:
                switch (action)
                {
                case 1:
                    ATTFile obj22 = new ATTFile();
                    obj22 = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string   newFilePath = Path.Combine(fullToPath, obj22.FileName);
                        FileInfo file22      = new FileInfo(newFilePath);
                        obj22.Folder   = toPath;
                        obj22.FolderId = toFolderId;
                        obj22.AddedBy  = "superuser";
                        FileManagerController.AddFile(obj22);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;

                case 2:
                    ATTFile objMove = new ATTFile();
                    objMove = FileManagerController.GetFileDetails(fileId);
                    try
                    {
                        string   newFilePath = Path.Combine(fullToPath, objMove.FileName);
                        FileInfo fileMove    = new FileInfo(newFilePath);
                        objMove.Folder   = toPath;
                        objMove.FolderId = toFolderId;
                        objMove.AddedBy  = "superuser";
                        FileManagerController.AddFile(objMove);
                        FileManagerController.DeleteFileFolder(0, fileId);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    break;
                }
                break;
            }
        }
Example #21
0
        /// <summary>
        /// Copy or Move the file to the fullToPath location
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileId"></param>
        /// <param name="toFolderId"></param>
        /// <param name="toPath"></param>
        /// <param name="action"></param>
        /// <param name="mode"></param>
        /// <param name="fullFilePath"></param>
        /// <param name="fullFromPath"></param>
        /// <param name="fullToPath"></param>
         public static void TransferFile(string filePath, int fileId, int toFolderId, string toPath, int action, int mode,string fullFilePath,string fullFromPath,string fullToPath)
    {
        switch (mode)
        {
            case 1:
                switch (action)
                {
                    case 1:
                        FileInfo fileCopy = new FileInfo(fullFilePath);
                        string fileNameCopy = fileCopy.Name;
                        if (!File.Exists(Path.Combine(fullToPath, fileNameCopy)))
                        {
                            try
                            {
                                fileCopy.CopyTo(Path.Combine(fullToPath, fileNameCopy));
                                FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath);
                        string fileNameMove = fileMove.Name;
                        if (fileMove.Exists)
                        {
                            try
                            {
                                fileMove.MoveTo(fullToPath + fileNameMove);
                                FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                }
                break;
            case 2:
                switch (action)
                {
                    case 1:
                        FileInfo fileCopy = new FileInfo(fullFilePath);
                        string fileNameCopy = fileCopy.Name;
                        /// Checking if file exists
                        if (!File.Exists(fullToPath + fileNameCopy + ".resources"))
                        {
                            try
                            {
                                fileCopy.CopyTo(fullToPath + fileNameCopy+".resources");
                                FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath);
                        string fileName = fileMove.Name;
                        if (fileMove.Exists)
                        {
                            try
                            {
                                fileMove.MoveTo(fullToPath + fileName+".resources");
                                FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                }
                break;
            case 3:
                switch (action)
                {
                    case 1:
                        FileInfo fileCopy = new FileInfo(fullFilePath);
                        ATTFile objCopy = new ATTFile();
                        objCopy.FileName = fileCopy.Name;
                        objCopy.Folder = toPath;
                        objCopy.FolderId = toFolderId;
                        objCopy.AddedBy = "superuser";
                        objCopy.Extension = fileCopy.Extension;
                        objCopy.PortalId = 1;
                        objCopy.UniqueId = Guid.NewGuid();
                        objCopy.VersionGuid = Guid.NewGuid();
                        objCopy.Size = int.Parse(fileCopy.Length.ToString());
                        objCopy.ContentType = FileManagerHelper.ReturnExtension(fileCopy.Extension);
                        objCopy.IsActive = 1;
                        objCopy.StorageLocation = 2;
                        if (fileCopy.Exists)
                        {
                            byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                            objCopy.Content = _fileContent;
                            try
                            {
                                FileManagerController.AddFile(objCopy);
                            }
                            catch (Exception)
                            {

                                throw;
                            }
                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath);
                        ATTFile objMove = new ATTFile();
                        objMove.FileName = fileMove.Name;
                        objMove.Folder = toPath;
                        objMove.FolderId = toFolderId;
                        objMove.AddedBy = "superuser";
                        objMove.Extension = fileMove.Extension;
                        objMove.PortalId = 1;
                        objMove.UniqueId = Guid.NewGuid();
                        objMove.VersionGuid = Guid.NewGuid();
                        objMove.Size = int.Parse(fileMove.Length.ToString());
                        objMove.ContentType = FileManagerHelper.ReturnExtension(fileMove.Extension);
                        objMove.IsActive = 1;
                        objMove.StorageLocation = 2;
                        if (fileMove.Exists)
                        {
                            byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                            objMove.Content = _fileContent;
                            try
                            {
                                FileManagerController.AddFile(objMove);
                                fileMove.Delete();
                                FileManagerController.DeleteFileFolder(0, fileId);
                            }
                            catch (Exception)
                            {

                                throw;
                            }
                        }
                        break;
                }
                break;
            case 4:
                switch (action)
                {
                    case 1:
                        FileInfo fileCopy = new FileInfo(fullFilePath + ".resources");
                        /// Checking if file exists
                        string fileNameCopy = "";
                        fileNameCopy = fileCopy.Name;
                        if (!File.Exists(Path.Combine(fullToPath, fileNameCopy.Replace(".resources", ""))))
                        {
                            try
                            {
                                fileCopy.CopyTo(Path.Combine(fullToPath,fileNameCopy.Replace(".resources","")));
                                FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath + ".resources");                       
                        string fileNameMove = fileMove.Name;                       
                        if (fileMove.Exists)
                        {
                            try
                            {
                                fileMove.MoveTo(Path.Combine(fullToPath,fileNameMove.Replace(".resources","")));
                                FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                }
                break;
            case 5:
                switch (action)
                {
                    case 1:
                        FileInfo file11 = new FileInfo(fullFilePath + ".resources");
                        /// Checking if file exists
                        string fileName11 = "";
                        fileName11 = filePath.Substring(filePath.LastIndexOf('/') + 1, filePath.Length - 1 - filePath.LastIndexOf('/'));
                        if (!File.Exists(fullToPath + fileName11 + ".resources"))
                        {
                            try
                            {
                                file11.CopyTo(fullToPath + fileName11 + ".resources");
                                FileManagerController.CopyFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath + ".resources");
                        /// Checking if file exists
                        string fileNameMove = fileMove.Name;
                        if (fileMove.Exists)
                        {
                            try
                            {
                                fileMove.MoveTo(Path.Combine(fullFilePath ,fileNameMove + ".resources"));
                                FileManagerController.MoveFile(fileId, toFolderId, toPath, Guid.NewGuid(), Guid.NewGuid());
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }
                        break;
                }
                break;
            case 6:
                switch (action)
                {
                    case 1:
                        FileInfo file12 = new FileInfo(fullFilePath+".resources");
                        ATTFile obj12 = new ATTFile();
                        obj12.FileName = RemoveResourceExtension(file12.Name);
                        obj12.Folder = toPath;
                        obj12.FolderId = toFolderId;
                        obj12.AddedBy = "superuser";
                        obj12.Extension = file12.Extension;
                        obj12.PortalId = 1;
                        obj12.UniqueId = Guid.NewGuid();
                        obj12.VersionGuid = Guid.NewGuid();
                        obj12.Size = int.Parse(file12.Length.ToString());
                        obj12.ContentType = FileManagerHelper.ReturnExtension(file12.Extension);
                        obj12.IsActive = 1;
                        obj12.StorageLocation = 2;
                        if (new FileInfo(fullFilePath + ".resources").Exists)
                        {
                            File.Move(fullFilePath + ".resources", fullFilePath);
                            byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath);
                            obj12.Content = _fileContent;
                            try
                            {
                                FileManagerController.AddFile(obj12);
                                File.Move(fullFilePath, fullFilePath + ".resources");
                            }
                            catch (Exception)
                            {
                                if (File.Exists(fullFilePath))
                                {
                                    File.Move(fullFilePath, fullFilePath + ".resources");
                                }

                                throw;
                            }
                        }
                        break;
                    case 2:
                        FileInfo fileMove = new FileInfo(fullFilePath+".resources");
                        ATTFile objMove = new ATTFile();
                        objMove.FileName = RemoveResourceExtension(fileMove.Name);
                        objMove.Folder = toPath;
                        objMove.FolderId = toFolderId;
                        objMove.AddedBy = "superuser";
                        objMove.Extension = fileMove.Extension;
                        objMove.PortalId = 1;
                        objMove.UniqueId = Guid.NewGuid();
                        objMove.VersionGuid = Guid.NewGuid();
                        objMove.Size = int.Parse(new FileInfo(fullFilePath + ".resources").Length.ToString());
                        objMove.ContentType = FileManagerHelper.ReturnExtension(fileMove.Extension);
                        objMove.IsActive = 1;
                        objMove.StorageLocation = 2;
                        if (new FileInfo(fullFilePath + ".resources").Exists)
                        {                           
                            byte[] _fileContent = FileManagerHelper.FileToByteArray(fullFilePath+".resources");
                            objMove.Content = _fileContent;
                            try
                            {
                                FileManagerController.AddFile(objMove);
                                File.Delete(fullFilePath + ".resources");
                                FileManagerController.DeleteFileFolder(0, fileId);
                            }
                            catch (Exception)
                            {                             

                                throw;
                            }
                        }
                        break;
                }
                break;
            case 7:
                switch (action)
                {
                    case 1:
                        ATTFile obj20 = new ATTFile();
                        obj20 = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, obj20.FileName);
                            if (!File.Exists(newFilePath))
                            {
                            FileManagerHelper.WriteBinaryFile(newFilePath, obj20.Content);
                            FileInfo file20 = new FileInfo(newFilePath);
                            ATTFile obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser",
                                                           file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(),
                                                           int.Parse(file20.Length.ToString()),
                                                           FileManagerHelper.ReturnExtension(file20.Extension), 1, 0);
                            FileManagerController.AddFile(obj20New);
                        }
                        }
                        catch (Exception)
                        {

                            throw;
                        }       
                        break;
                    case 2:
                        ATTFile objMove = new ATTFile();
                        objMove = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, objMove.FileName);
                            FileManagerHelper.WriteBinaryFile(newFilePath, objMove.Content);
                            FileInfo file20 = new FileInfo(newFilePath);
                            ATTFile obj20New = new ATTFile(file20.Name, toPath, toFolderId, "superuser", file20.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file20.Length.ToString()), FileManagerHelper.ReturnExtension(file20.Extension), 1, 0);
                            FileManagerController.AddFile(obj20New);
                            FileManagerController.DeleteFileFolder(0, fileId);
                        }
                        catch (Exception)
                        {

                            throw;
                        }       
                        break;
                }
                break;
            case 8:
                switch (action)
                {
                    case 1:
                        ATTFile obj21 = new ATTFile();
                        obj21 = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, obj21.FileName);
                            if (!File.Exists(newFilePath + ".resources"))
                            {
                            FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", obj21.Content);
                            FileInfo file21 = new FileInfo(newFilePath + ".resources");
                                ATTFile obj21New = new ATTFile(file21.Name, toPath, toFolderId, "superuser",
                                                               file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(),
                                                               int.Parse(file21.Length.ToString()),
                                                               FileManagerHelper.ReturnExtension(file21.Extension), 1, 1);
                            FileManagerController.AddFile(obj21New);
                            }
                        }
                        catch (Exception)
                        {

                            throw;
                        }
                        break;
                    case 2:
                        ATTFile objMove = new ATTFile();
                        objMove = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, objMove.FileName);
                            FileManagerHelper.WriteBinaryFile(newFilePath + ".resources", objMove.Content);
                            FileInfo file21 = new FileInfo(newFilePath + ".resources");
                            ATTFile obj21New = new ATTFile(file21.Name.Replace(".resources",""), toPath, toFolderId, "superuser", file21.Extension, 1, Guid.NewGuid(), Guid.NewGuid(), int.Parse(file21.Length.ToString()), FileManagerHelper.ReturnExtension(file21.Extension), 1, 1);
                            FileManagerController.AddFile(obj21New);
                            FileManagerController.DeleteFileFolder(0, fileId);
                        }
                        catch (Exception)
                        {

                            throw;
                        }
                        break;
                }
                break;
            case 9:
                switch (action)
                {
                    case 1:
                        ATTFile obj22 = new ATTFile();
                        obj22 = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, obj22.FileName);
                            FileInfo file22 = new FileInfo(newFilePath);
                            obj22.Folder = toPath;
                            obj22.FolderId = toFolderId;
                            obj22.AddedBy = "superuser";
                            FileManagerController.AddFile(obj22);
                        }
                        catch (Exception)
                        {

                            throw;
                        }
                        break;
                    case 2:
                        ATTFile objMove = new ATTFile();
                        objMove = FileManagerController.GetFileDetails(fileId);
                        try
                        {
                            string newFilePath = Path.Combine(fullToPath, objMove.FileName);
                            FileInfo fileMove = new FileInfo(newFilePath);
                            objMove.Folder = toPath;
                            objMove.FolderId = toFolderId;
                            objMove.AddedBy = "superuser";
                            FileManagerController.AddFile(objMove);
                            FileManagerController.DeleteFileFolder(0, fileId);
                        }
                        catch (Exception)
                        {

                            throw;
                        }
                        break;
                }
                break;
           
        }
    }
        public static List<ATTFile> SearchFiles(string SearchQuery)
        {
            List<ATTFile> lstFiles = new List<ATTFile>();
            string StoredProcedureName = "usp_FileManagerSearchFiles";
            SQLHandler sagesql = new SQLHandler();
            List<KeyValuePair<string, object>> ParaMeterCollection = new List<KeyValuePair<string, object>>();
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@SearchQuery", SearchQuery));
            SqlDataReader SQLReader;
            try
            {
                SQLReader = sagesql.ExecuteAsDataReader(StoredProcedureName, ParaMeterCollection);
                while (SQLReader.Read())
                {
                    ATTFile obj = new ATTFile();
                    obj.FileId = int.Parse(SQLReader["FileId"].ToString());
                    obj.FileName = SQLReader["FileName"].ToString();
                    obj.Folder = SQLReader["Folder"].ToString();
                    obj.Extension = SQLReader["Extension"].ToString();
                    obj.Size = int.Parse(SQLReader["Size"].ToString());
                    obj.AddedOn = SQLReader["AddedOn"].ToString();
                    obj.Content = SQLReader["Content"] == DBNull.Value ? null : (byte[])SQLReader["Content"];
                    obj.StorageLocation = int.Parse(SQLReader["StorageLocation"].ToString());

                    lstFiles.Add(obj);
                }
                SQLReader.Dispose();
            }
            catch (Exception e)
            {
                throw e;
            }
            return lstFiles;
        }
        /// <summary>
        /// Creates a html string to be rendered based upon the dynamic conditions
        /// </summary>
        /// <param name="IsZip">IsZip</param>
        /// <param name="IsImg">IsImg</param>
        /// <param name="StorageLocation">StorageLocation</param>
        /// <param name="ext">ext</param>
        /// <param name="urlPath">urlPath</param>
        /// <param name="absolutePath">absolutePath</param>
        /// <param name="downloadPath">downloadPath</param>
        /// <param name="checkId">checkId</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="sb">sb</param>
        /// <param name="permission">permission</param>
        /// <param name="dictImages">dictImages</param>
        public static void ConstructHTMLString(bool IsZip, bool IsImg, int StorageLocation, string ext, string urlPath, string absolutePath, string downloadPath, string checkId, int folderId, ATTFile file, ref StringBuilder sb, string permission, Dictionary<string, string> dictImages, int index)
        {
            switch (StorageLocation)
            {
                case 0:
                    string attStr = FileManagerHelper.GetAttributeString(absolutePath);
                    if (IsZip)
                    {
                        sb.Append(AddExtension(ext, index));
                        sb.Append(AddCheckBox(checkId));
                        sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                        sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                        sb.Append(AddExtractButton(Path.Combine(file.Folder, file.FileName), dictImages["Extract"].ToString(), permission));
                        sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                        sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));


                        sb.Append("</tr>");
                    }
                    else
                    {
                        if (IsImg)
                        {
                            string imgpath = urlPath + file.Folder;
                            imgpath = Path.Combine(imgpath, file.FileName);
                            sb.Append(AddExtension(ext, index));
                            sb.Append(AddCheckBox(checkId));
                            //sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                            sb.Append(AddPopupLink(downloadPath, folderId, file, permission, ext));
                            sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                            sb.Append(AddPreviewButton(urlPath, dictImages["Preview"].ToString()));
                            sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                            sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));
                            sb.Append("</tr>");
                        }
                        else
                        {
                            sb.Append(AddExtension(ext, index));
                            sb.Append(AddCheckBox(checkId));
                            //sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                            sb.Append(AddPopupLink(downloadPath, folderId, file, permission, ext));
                            sb.Append(AddInfoSpan(file, attStr, StorageLocation));
                            sb.Append(AddBlankSpan());
                            sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));

                            sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                            sb.Append("</tr>");
                        }
                    }
                    break;
                case 1:
                    string attStr1 = FileManagerHelper.GetAttributeString(absolutePath + ".resources");
                    sb.Append(AddExtension(ext, index));
                    sb.Append(AddCheckBox(checkId));
                    sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                    sb.Append(AddInfoSpan(file, attStr1, StorageLocation));
                    sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                    sb.Append(AddBlankSpan());
                    sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                    sb.Append("</tr>");
                    break;
                case 2:
                    sb.Append(AddExtension(ext, index));
                    sb.Append(AddCheckBox(checkId));
                    sb.Append(AddDownloadLink(downloadPath, folderId, file, permission, ext));
                    sb.Append(AddInfoSpan(file, "", StorageLocation));
                    sb.Append(AddBlankSpan());
                    sb.Append(AddDeleteButton(Path.Combine(file.Folder, file.FileName), dictImages["Delete"].ToString(), permission));

                    sb.Append(AddEditButton(Path.Combine(file.Folder, file.FileName), dictImages["Edit"].ToString(), permission));
                    sb.Append("</li>");
                    break;
            }
        }
 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;
 }
        public static ATTFile GetFileDetails(int FileID)
        {
            List<KeyValuePair<string, object>> ParaMeterCollection = new List<KeyValuePair<string, object>>();
            ParaMeterCollection.Add(new KeyValuePair<string, object>("@FileID", FileID));

            SQLHandler sagesql = new SQLHandler();
            ATTFile obj = new ATTFile();
            obj = sagesql.ExecuteAsObject<ATTFile>("usp_FileManagerGetFileDetails", ParaMeterCollection);
            return obj;
        }
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="filePath">filePath</param>
        /// <param name="folderId">folderId</param>
        /// <param name="file">file</param>
        /// <param name="permission">permission</param>
        /// <param name="extension">extension</param>
        /// <returns>Return table column for desire class.</returns>
        public static string AddPopupLink(string filePath, int folderId, ATTFile file, string permission, string extension)
        {
            extension = string.Format("icon-{0}", extension);
            string name = file.FileName;
            if (file.FileName.Length > 40)
            {
                name = file.FileName.Substring(0, 40) + "...";
            }
            //if (permission == "edit" || permission == "view")
            //    return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");
            //else
            //    return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"#\" rel=" + file.FileName + ">" + file.FileName + "</a></td>");
            // return ("<td class='" + extension + "' width='30%'><a class=\"download_link\" href=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\" rel=" + file.FileName + ">" + name + "</a></td>");

            return ("<td class='" + extension + "' width='30%'><a href=# class=\"download_link\"><span   value=\"" + filePath + "FileName=" + file.FileName + "&FolderName=" + file.Folder + "\"  id=\"spnEditImage\">" + name + "</a></span></td>");


        }
Example #27
0
        public static void RecurseThroughDirectory(DirectoryInfo di,int folderId,int folderType)
        {
            FileInfo[] files = di.GetFiles();
            foreach (FileInfo fi in files)
            {
                List<ATTFile> lstFile = FileManagerController.GetFiles(folderId);
                bool exists = false;
                int size = int.Parse(fi.Length.ToString());
                if(Path.GetExtension(fi.Name)==".resources")
                {
                     exists= lstFile.Exists(
                        delegate(ATTFile obj)
                        {
                            return (obj.FileName == Path.GetFileNameWithoutExtension(fi.Name) && obj.FolderId == folderId);
                        }
                        );
                    
                }
                else
                {
                    exists = lstFile.Exists(
                    delegate(ATTFile obj)
                    {
                        return (obj.FileName == fi.Name && obj.FolderId == folderId);
                    }
                    );
                
                }
                if(!exists)
                {
                    //Add file to database
                    if (folderType == 1)
                    {
                        File.Move(fi.FullName,fi.FullName+".resources");
                        ATTFile fileObj = new ATTFile(fi.Name, FileManagerHelper.ReplaceBackSlash(GetFolderPath(di.FullName.Replace(absolutePath, ""))), folderId, UserName, Path.GetExtension(fi.Name.Replace(".resources", "")), PortalID, Guid.NewGuid(), Guid.NewGuid(),size, FileManagerHelper.ReturnExtension(Path.GetExtension(fi.Name.Replace(".resources", ""))), 1,folderType);
                        FileManagerController.AddFile(fileObj);
                    }
                    else
                    {   if(IsExtensionValid(Path.GetExtension(fi.Name)))
                        {
                        ATTFile fileObj = new ATTFile(fi.Name, FileManagerHelper.ReplaceBackSlash(GetFolderPath(di.FullName.Replace(absolutePath, ""))), folderId, UserName, Path.GetExtension(fi.Name), PortalID, Guid.NewGuid(), Guid.NewGuid(), int.Parse(fi.Length.ToString()), FileManagerHelper.ReturnExtension(Path.GetExtension(fi.Name)), 1, 0);
                        FileManagerController.AddFile(fileObj);
                        }
                    }

                   
                    
                }
            }
            foreach (DirectoryInfo di_child in di.GetDirectories())
            {
                int newFolderId = 0;
                int storageLocation = 0;
                int index = lstFolders.FindIndex(
                    delegate (Folder obj)
                        {
                            return (obj.FolderPath == GetFolderPath(di_child.FullName));
                        }
                    );
                if(index==-1)
                {
                    //Add folder to the database and get the folderId into newFolderId
                    Folder folder = new Folder();
                    folder.PortalId = PortalID;
                    folder.FolderPath = FileManagerHelper.ReplaceBackSlash(GetFolderPath(di_child.FullName));
                    folder.StorageLocation = storageLocation;
                    folder.UniqueId = Guid.NewGuid();
                    folder.VersionGuid = Guid.NewGuid();
                    folder.IsActive = 1;
                    folder.AddedBy = UserName;
                    folder.IsRoot = false;
                    newFolderId = FileManagerController.AddFolderReturnFolderID(folder);
                }
                else if(index>-1)
                {
                    newFolderId = lstFolders[index].FolderId;
                    storageLocation = lstFolders[index].StorageLocation;
                }
                RecurseThroughDirectory(di_child,newFolderId,storageLocation);
            }
            
        }
        /// <summary>
        /// Return table column for desire class.
        /// </summary>
        /// <param name="file">file</param>
        /// <param name="attributeString">attributeString</param>
        /// <param name="mode">mode</param>
        /// <returns>Return table column for desire class.</returns>

        public static string AddInfoSpan(ATTFile file, string attributeString, int mode)
        {
            string html = "";

            switch (mode)
            {
                case 2:
                    html = "<td><span class=\"info\">" + file.AddedOn + "||" + file.Size + "bytes" + "</span></span></td>";
                    break;
                default:
                    html = "<td><span class=\"info\">" + file.AddedOn + "||" + file.Size + "bytes" + "||<span class=\"attr\">" + attributeString + "</span></span></td>";
                    break;
            }
            return html;
        }