public static string GetXMLString(string filePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();
        string xml = null;

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            StreamReader sr = null;
            try
            {
                sr  = new StreamReader(filePath);
                xml = sr.ReadToEnd();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                    sr = null;
                }
            }
        }
        return(xml);
    }
    public static void UpdateFile(string fileName, string filePath, string attrString, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            filePath = GetAbsolutePath(filePath);
            try
            {
                FileInfo file = new FileInfo(filePath);
                /// Checking if file exists
                if (file.Exists)
                {
                    ///get the folder path
                    filePath = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
                    filePath = filePath + fileName;
                    file.MoveTo(filePath);
                    //FileManagerController.UpdateFile(fileId, fileName);
                    FileManagerHelper.SetFileAttributes(filePath, attrString);
                    //CacheHelper.Clear("FileManagerFileList");
                }
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
    }
    public static void Synchronize(int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            try
            {
                SynchronizeFiles.UserName     = fb.GetUsername;
                SynchronizeFiles.PortalID     = fb.GetPortalID;
                SynchronizeFiles.extensions   = "jpg,zip,txt,doc,docx,tif,css,js,jpeg,png";
                SynchronizeFiles.absolutePath = HttpContext.Current.Request.PhysicalApplicationPath.ToString();
                //SynchronizeFiles.lstFolders = FileManagerController.GetAllFolders();
                SynchronizeFiles.F2DSync();
                SynchronizeFiles.D2FSync();
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
            finally
            {
                CacheHelper.Clear("FileManagerFolders");
                CacheHelper.Clear("FileManagerFileList");
            }
        }
    }
    public static void CreateFolder(int FolderID, string filePath, string folderName, int fileType, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (!dir.Exists)
            {
                dir.Create();
                Folder folder = new Folder();
                folder.PortalId        = fb.GetPortalID;
                folder.ParentID        = FolderID;
                folder.FolderPath      = filePath;
                folder.StorageLocation = fileType;
                folder.UniqueId        = Guid.NewGuid();
                folder.VersionGuid     = Guid.NewGuid();
                folder.IsActive        = 1;
                folder.AddedBy         = fb.GetUsername;
                try
                {
                    FileManagerController.AddFolder(folder);
                    CacheHelper.Clear("FileManagerFolders");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
    }
    public static int GetSearchCount(string SearchQuery, string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        List <ATTFile>      lstFiles   = new List <ATTFile>();
        AuthenticateService objService = new AuthenticateService();

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

            if (Directory.Exists(FilePath))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
                foreach (FileInfo file in dirInfo.GetFiles(SearchQuery + "*"))
                {
                    ATTFile obj = new ATTFile();
                    obj.FileName = file.Name;
                    lstFiles.Add(obj);
                }
            }
        }
        return(lstFiles.Count);
    }
    public static List <Roles> GetAllRoles(int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService  = new AuthenticateService();
        List <Roles>        lstNewRoles = new List <Roles>();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            List <Roles> lstRoles = PermissionHelper.GetAllRoles(1, true, "superuser");
            foreach (Roles r in lstRoles)
            {
                if (Regex.Replace(r.RoleName.ToLower(), @"\s", "") == "superuser")
                {
                    lstNewRoles.Insert(0, r);
                }
                else if (Regex.Replace(r.RoleName.ToLower(), @"\s", "") == "siteadmin")
                {
                    lstNewRoles.Insert(1, r);
                }
                else
                {
                    lstNewRoles.Add(r);
                }
            }
        }
        return(lstNewRoles);
    }
    public static void DeleteRootFolder(int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            FileManagerController.DeleteRootFolder(FolderID);
        }
    }
    public static void SetFilePath(string filePath, int folderId, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            HttpContext.Current.Session["Path"]     = filePath;
            HttpContext.Current.Session["FolderID"] = folderId;
        }
    }
    public static int ValidateUser(int portalID, string userName, int userModuleID, string secureToken)
    {
        int UserID = 0;
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            UserID = FileManagerController.GetUserID(userName);
        }
        return(UserID);
    }
    public static List <Folder> GetRootFolders(int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService        = new AuthenticateService();
        List <Folder>       objRootFolderList = new List <Folder>();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            objRootFolderList = FileManagerController.GetRootFolders();
        }
        return(objRootFolderList);
    }
    public static List <FolderPermission> GetUserListForFolder(int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        List <FolderPermission> objFolderPErmission = new List <FolderPermission>();
        AuthenticateService     objService          = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            objFolderPErmission = FileManagerController.GetUserListForFolder(FolderID);
        }
        return(objFolderPErmission);
    }
    public static string EditFile(string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();
        string ImgPath = string.Empty;

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            ImgPath = HttpContext.Current.Request.ApplicationPath.ToString() + FilePath;
        }
        return(ImgPath);
    }
    public static void MoveFile(string filePath, string fromPath, string toPath, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string fullFilePath = GetAbsolutePath(filePath);
            string fullFromPath = GetAbsolutePath(fromPath);
            string fullToPath   = GetAbsolutePath(toPath);
            FileManagerHelper.TransferFile(filePath, toPath, (int)Action.MOVE, (int)TransferMode.NORMALTONORMAL, fullFilePath, fullFromPath, fullToPath);
        }
    }
    public static string GetPermissionKeys(int FolderID, int UserID, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();
        string keyString = string.Empty;

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            List <string> lstPermission = FileManagerController.GetPermissionKeys(FolderID, UserID, userModuleID, userName);
            keyString = string.Join("-", lstPermission.ToArray());
        }
        return(keyString);
    }
    public static string GetExtensions(int portalID, string userName, int userModuleID, string secureToken)
    {
        string extension = "";
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            SageFrameConfig config = new SageFrameConfig();
            extension = config.GetSettingValueByIndividualKey(SageFrameSettingKeys.FileExtensions);
        }
        return(extension);
    }
    public static string DeleteFile(string filePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        string message = "";
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            filePath = GetAbsolutePath(filePath);

            if (filePath.EndsWith("/"))
            {
                DirectoryInfo di = new DirectoryInfo(filePath);
                if (di.Exists)
                {
                    try
                    {
                        di.Delete();
                        message = "Folder deleted successfully";
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                        message = "Folder contaning files cannot be deleted";
                    }
                }
            }
            else
            {
                FileInfo file = new FileInfo(filePath);
                // Checking if file exists
                if (file.Exists)
                {
                    ///Reset the file attribute before deleting
                    try
                    {
                        File.SetAttributes(filePath, FileAttributes.Normal);
                        file.Delete();

                        message = "File deleted successfully";
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                        message = "File could be deleted";
                    }
                }
            }
            //CacheHelper.Clear("FileManagerFileList");
            //CacheHelper.Clear("FileManagerFolders");
        }
        return(message);
    }
    public static void UpdateFileContain(string FullPath, string UpdateValue, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            int index = 0;
            index = HttpContext.Current.Request.ApplicationPath == "/" ? 0 : 1;
            string originalFile = string.Concat(HttpContext.Current.Server.MapPath("~/"), FullPath.Substring(FullPath.IndexOf('/', index)).Replace("/", "\\"));
            System.IO.StreamWriter objStreamWriter = new System.IO.StreamWriter(originalFile);
            objStreamWriter.Write(UpdateValue);
            objStreamWriter.Close();
        }
    }
Exemple #18
0
    public static void AddRootFolder(string FolderName, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), FolderName));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (dir.Exists)
            {
                dir.Create();
                CacheHelper.Clear("FileManagerFolders");
            }
        }
    }
    public static int GetCount(string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();
        int numFiles = 0;

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

            files    = Directory.GetFiles(FilePath);
            numFiles = files.Length;
        }
        return(numFiles);
    }
    public static void CopyFile(string filePath, string fromPath, string toPath, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string fullFilePath = GetAbsolutePath(filePath);
            string fullFromPath = GetAbsolutePath(fromPath);
            string fullToPath   = GetAbsolutePath(toPath);
            try
            {
                //public static void TransferFile(string filePath, string toPath, int action, int mode, string fullFilePath, string fullFromPath, string fullToPath)
                FileManagerHelper.TransferFile(filePath, toPath, (int)Action.COPY, (int)TransferMode.NORMALTONORMAL, fullFilePath, fullFromPath, fullToPath);
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
    }
    public static string UnzipFiles(string FilePath, int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

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

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            try
            {
                int index = 0;
                index = HttpContext.Current.Request.ApplicationPath == "/" ? 0 : 1;
                string originalFile = string.Concat(HttpContext.Current.Server.MapPath("~/"), FullPath.Substring(FullPath.IndexOf("/", index)).Replace("/", "\\"));
                html = GetXMLString(originalFile, portalID, userName, userModuleID, secureToken);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        return(html);
    }
Exemple #23
0
    public static void CreateFolder(int FolderID, string filePath, string folderName, int fileType, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));
            DirectoryInfo dir          = new DirectoryInfo(absolutePath);
            if (!dir.Exists)
            {
                dir.Create();
                try
                {
                    CacheHelper.Clear("FileManagerFolders");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
    }
Exemple #24
0
    public static string UnzipFiles(string FilePath, int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath  = GetAbsolutePath(FilePath);
            FileInfo      file          = new FileInfo(absolutePath);
            string        folderName    = file.Name;
            string        newFolderPath = FileManagerHelper.GetFilePathWithoutExtension(absolutePath);
            DirectoryInfo dir           = new DirectoryInfo(newFolderPath);
            if (!dir.Exists)
            {
                string path = string.Empty;
                FileManagerHelper.UnZipFiles(absolutePath, newFolderPath, ref path, SageFrame.Common.RegisterModule.Common.Password, false, userModuleID, fb.GetPortalID);
                Folder folder = new Folder();
            }
            CacheHelper.Clear("FileManagerFileList");
            CacheHelper.Clear("FileManagerFolders");
        }
        return(sb.ToString());
    }
    public static void SetFolderPermission(int FolderID, int UserID, int IsActive, string AddedBy, List <Permission> lstPermission, int portalID, string userName, int userModuleID, string secureToken)
    {
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            FileManagerController.DeleteExistingPermissions(FolderID);
            foreach (Permission objPer in lstPermission)
            {
                try
                {
                    if (objPer.UserID != 0)
                    {
                        objPer.RoleID = Guid.Empty;
                    }
                    FileManagerController.SetFolderPermission(FolderID, objPer.PermissionKey, objPer.UserID, objPer.RoleID, IsActive, AddedBy);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }
    }
    public static string SearchFiles(string SearchQuery, int CurrentPage, int PageSize, string FilePath, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

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

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

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

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



            if (UserPermissionKey == 1)
            {
                int index = 0;
                foreach (ATTFile fi in lstFiles)
                {
                    string ext = "";
                    //bool IsZip = false;
                    bool IsImg = false;
                    if (fi.Extension.Length > 1)
                    {
                        ext = fi.Extension.Substring(1).ToLower();
                    }
                    // if (ext == "zip")
                    //     IsZip = true;
                    if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                    {
                        IsImg = true;
                    }
                    string checkId = "chk_" + fi.FileId;
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "edit", dictImages, index, secureToken);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                    index++;
                }
            }
            else
            {
                int index = 0;
                foreach (ATTFile fi in lstFiles)
                {
                    string ext = "";
                    //  bool IsZip = false;
                    bool IsImg = false;
                    if (fi.Extension.Length > 1)
                    {
                        ext = fi.Extension.Substring(1).ToLower();
                    }
                    //if (ext == "zip")
                    //   IsZip = true;
                    if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                    {
                        IsImg = true;
                    }
                    string checkId = "chk_" + fi.FileId;
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(GetUrlPath(fi.Folder), fi.FileName), Path.Combine(GetAbsolutePath(fi.Folder), fi.FileName), downloadPath, checkId, 0, fi, ref sb, "view", dictImages, index, secureToken);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                    index++;
                }
            }
            sb.Append("</table>");
            sb.Append("<div id='divPagerNav'></div>");
            sb.Append("</div>");
        }
        return(sb.ToString());
    }
    public static string CropImage(string ImagePath, int X1, int Y1, int X2, int Y2, int w, int h, int portalID, string userName, int userModuleID, string secureToken)
    {
        string CroppedImag             = "";
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string dir       = "";
            string imagename = ImagePath.Substring(ImagePath.LastIndexOf('/') + 1).ToString();
            dir = ImagePath.Replace(imagename, "");
            string imagenamewithoutext = imagename.Substring(imagename.LastIndexOf('.') + 1).ToString();

            int X     = System.Math.Min(X1, X2);
            int Y     = System.Math.Min(Y1, Y2);
            int index = 0;
            index = HttpContext.Current.Request.ApplicationPath == "/" ? 0 : 1;
            string originalFile = string.Concat(HttpContext.Current.Server.MapPath("~/"), ImagePath.Substring(ImagePath.IndexOf('/', index)).Replace("/", "\\"));
            string savePath     = Path.GetDirectoryName(originalFile) + "\\";
            if (File.Exists(originalFile))
            {
                using (System.Drawing.Image img = System.Drawing.Image.FromFile(originalFile))
                {
                    using (System.Drawing.Bitmap _bitmap = new System.Drawing.Bitmap(w, h))
                    {
                        _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                        using (Graphics _graphic = Graphics.FromImage(_bitmap))
                        {
                            _graphic.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            _graphic.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            _graphic.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                            _graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                            _graphic.DrawImage(img, 0, 0, w, h);
                            _graphic.DrawImage(img, new Rectangle(0, 0, w, h), X, Y, w, h, GraphicsUnit.Pixel);

                            Random rand = new Random((int)DateTime.Now.Ticks);
                            int    RandomNumber;
                            RandomNumber = rand.Next(1, 200);
                            int    CharCode   = rand.Next(Convert.ToInt32('a'), Convert.ToInt32('z'));
                            char   RandomChar = Convert.ToChar(CharCode);
                            string extension  = Path.GetExtension(originalFile);
                            //string croppedFileName = Guid.NewGuid().ToString();
                            string croppedFileName = imagenamewithoutext + "_" + RandomNumber.ToString() + RandomChar.ToString();
                            string path            = savePath;

                            // If the image is a gif file, change it into png
                            if (extension.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
                            {
                                extension = ".png";
                            }

                            string newFullPathName = string.Concat(path, croppedFileName, extension);

                            using (EncoderParameters encoderParameters = new EncoderParameters(1))
                            {
                                encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                                _bitmap.Save(newFullPathName, GetImageCodec(extension), encoderParameters);
                            }

                            //lblCroppedImage.Text = string.Format("<img src='{0}' alt='Cropped image'>", path + extension);

                            CroppedImag = string.Format("<img src='{0}' alt='Cropped image'>", string.Concat(dir, croppedFileName, extension));
                        }
                    }
                }
            }
        }
        return(CroppedImag);
    }
    public static string GetFileList(string filePath, int folderId, int UserID, int IsSort, int CurrentPage, int PageSize, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

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

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

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