Пример #1
0
 public static string GetFolderPath(string folderPath)
 {
     return(FileManagerHelper.ReplaceBackSlash(folderPath.Replace(absolutePath, "")));
 }
Пример #2
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;
            }
        }
Пример #3
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);
     }
 }
Пример #4
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;
            }
        }