public int ConvertFilePathToFileId(string FilePath, int PortalID)
        {
            string FileName   = "";
            string FolderName = "";
            int    FileId     = -1;

            if (!String.IsNullOrEmpty(FilePath))
            {
                FileName   = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
                FolderName = FilePath.Replace(FileName, "");
            }
            FileController   objFiles   = new FileController();
            FolderController objFolders = new FolderController();
            FolderInfo       objFolder  = objFolders.GetFolder(PortalID, FolderName, false);

            if (objFolder != null)
            {
                FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID);
                if (objFile != null)
                {
                    FileId = objFile.FileId;
                }
            }
            return(FileId);
        }
 private static int AddFolder(int PortalId, string relativePath, int StorageLocation)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     bool isProtected = FileSystemUtils.DefaultProtectedFolders(relativePath);
     int FolderID = objFolderController.AddFolder(PortalId, relativePath, StorageLocation, isProtected, false);
     if (PortalId != Null.NullInteger)
     {
         SetFolderPermissions(PortalId, FolderID, relativePath);
     }
     return FolderID;
 }
 private static string AddFile(int PortalId, Stream inStream, string fileName, string contentType, long length, string folderName, bool closeInputStream, bool clearCache, bool synchronize)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     string sourceFolderName = Globals.GetSubFolderPath(fileName, PortalId);
     CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(PortalId, sourceFolderName, false);
     string sourceFileName = GetFileName(fileName);
     int intFileID;
     string retValue = "";
     retValue += CheckValidFileName(fileName);
     if (!String.IsNullOrEmpty(retValue))
     {
         return retValue;
     }
     string extension = Path.GetExtension(fileName).Replace(".", "");
     if (String.IsNullOrEmpty(contentType))
     {
         contentType = GetContentType(extension);
     }
     intFileID = objFileController.AddFile(PortalId, sourceFileName, extension, length, Null.NullInteger, Null.NullInteger, contentType, folderName, folder.FolderID, clearCache);
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem || synchronize == false)
     {
         WriteStream(intFileID, inStream, fileName, folder.StorageLocation, closeInputStream);
     }
     retValue += UpdateFileData(intFileID, folder.FolderID, PortalId, sourceFileName, extension, contentType, length, folderName);
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem)
     {
         DeleteFile(fileName);
     }
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem)
     {
         if (!fileName.EndsWith(".template"))
         {
             DeleteFile(fileName + Globals.glbProtectedExtension);
         }
     }
     return retValue;
 }
 public int ConvertFilePathToFileId(string FilePath, int PortalID)
 {
     string FileName = "";
     string FolderName = "";
     int FileId = -1;
     if (!String.IsNullOrEmpty(FilePath))
     {
         FileName = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
         FolderName = FilePath.Replace(FileName, "");
     }
     FileController objFiles = new FileController();
     FolderController objFolders = new FolderController();
     FolderInfo objFolder = objFolders.GetFolder(PortalID, FolderName, false);
     if (objFolder != null)
     {
         FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID);
         if (objFile != null)
         {
             FileId = objFile.FileId;
         }
     }
     return FileId;
 }
 public static string UnzipFile(string fileName, string DestFolder, PortalSettings settings)
 {
     ZipInputStream objZipInputStream = null;
     string strMessage = "";
     try
     {
         int FolderPortalId = GetFolderPortalId(settings);
         bool isHost = settings.ActiveTab.ParentId == settings.SuperTabId;
         PortalController objPortalController = new PortalController();
         CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         string sourceFolderName = Globals.GetSubFolderPath(fileName, FolderPortalId);
         string sourceFileName = GetFileName(fileName);
         CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(FolderPortalId, sourceFolderName, false);
         CommonLibrary.Services.FileSystem.FileInfo file = objFileController.GetFile(sourceFileName, FolderPortalId, folder.FolderID);
         int storageLocation = folder.StorageLocation;
         ZipEntry objZipEntry;
         string strFileName = "";
         string strExtension;
         try
         {
             objZipInputStream = new ZipInputStream(GetFileStream(file));
         }
         catch (Exception ex)
         {
             return ex.Message;
         }
         ArrayList sortedFolders = new ArrayList();
         objZipEntry = objZipInputStream.GetNextEntry();
         while (objZipEntry != null)
         {
             if (objZipEntry.IsDirectory)
             {
                 try
                 {
                     sortedFolders.Add(objZipEntry.Name.ToString());
                 }
                 catch (Exception ex)
                 {
                     objZipInputStream.Close();
                     return ex.Message;
                 }
             }
             objZipEntry = objZipInputStream.GetNextEntry();
         }
         sortedFolders.Sort();
         foreach (string s in sortedFolders)
         {
             try
             {
                 AddFolder(settings, DestFolder, s.ToString(), storageLocation);
             }
             catch (Exception ex)
             {
                 return ex.Message;
             }
         }
         objZipInputStream = new ZipInputStream(GetFileStream(file));
         objZipEntry = objZipInputStream.GetNextEntry();
         while (objZipEntry != null)
         {
             if (!objZipEntry.IsDirectory)
             {
                 if (objPortalController.HasSpaceAvailable(FolderPortalId, objZipEntry.Size))
                 {
                     strFileName = Path.GetFileName(objZipEntry.Name);
                     if (!String.IsNullOrEmpty(strFileName))
                     {
                         strExtension = Path.GetExtension(strFileName).Replace(".", "");
                         if (("," + Host.FileExtensions.ToLower()).IndexOf("," + strExtension.ToLower()) != 0 || isHost)
                         {
                             try
                             {
                                 string folderPath = System.IO.Path.GetDirectoryName(DestFolder + objZipEntry.Name.Replace("/", "\\"));
                                 DirectoryInfo Dinfo = new DirectoryInfo(folderPath);
                                 if (!Dinfo.Exists)
                                 {
                                     AddFolder(settings, DestFolder, objZipEntry.Name.Substring(0, objZipEntry.Name.Replace("/", "\\").LastIndexOf("\\")));
                                 }
                                 string zipEntryFileName = DestFolder + objZipEntry.Name.Replace("/", "\\");
                                 strMessage += AddFile(FolderPortalId, objZipInputStream, zipEntryFileName, "", objZipEntry.Size, Globals.GetSubFolderPath(zipEntryFileName, settings.PortalId), false, false);
                             }
                             catch (Exception ex)
                             {
                                 if (objZipInputStream != null)
                                 {
                                     objZipInputStream.Close();
                                 }
                                 return ex.Message;
                             }
                         }
                         else
                         {
                             strMessage += "<br>" + string.Format(Localization.GetString("RestrictedFileType"), strFileName, Host.FileExtensions.Replace(",", ", *."));
                         }
                     }
                 }
                 else
                 {
                     strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFileName);
                 }
             }
             objZipEntry = objZipInputStream.GetNextEntry();
         }
     }
     finally
     {
         if (objZipInputStream != null)
         {
             objZipInputStream.Close();
             objZipInputStream.Dispose();
         }
     }
     return strMessage;
 }
 public static void SynchronizeFolder(int PortalId, string physicalPath, string relativePath, bool isRecursive, bool syncFiles, bool forceFolderSync, bool hideSystemFolders)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     int FolderId;
     bool isInSync = true;
     if (forceFolderSync == true && String.IsNullOrEmpty(relativePath))
     {
         RemoveOrphanedFolders(PortalId);
     }
     CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(PortalId, relativePath, false);
     DirectoryInfo dirInfo = new DirectoryInfo(physicalPath);
     if (dirInfo.Exists)
     {
         if (folder == null)
         {
             if (ShouldSyncFolder(hideSystemFolders, dirInfo))
             {
                 FolderId = AddFolder(PortalId, relativePath, (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem);
                 folder = objFolderController.GetFolder(PortalId, relativePath, true);
                 isInSync = false;
             }
             else
             {
                 //Prevent further processing of this folder
                 return;
             }
         }
         else
         {
             isInSync = (dirInfo.LastWriteTime.ToString("yyyyMMddhhmmss") == folder.LastUpdated.ToString("yyyyMMddhhmmss"));
         }
         if (folder != null)
         {
             if (syncFiles == true && (isInSync == false || forceFolderSync == true))
             {
                 string[] strFiles = Directory.GetFiles(physicalPath);
                 foreach (string strFileName in strFiles)
                 {
                     AddFile(strFileName, PortalId, false, folder);
                 }
                 RemoveOrphanedFiles(folder, PortalId);
                 folder.LastUpdated = dirInfo.LastWriteTime;
                 objFolderController.UpdateFolder(folder);
             }
             if (isRecursive)
             {
                 string[] strFolders = Directory.GetDirectories(physicalPath);
                 foreach (string strFolder in strFolders)
                 {
                     DirectoryInfo dir = new DirectoryInfo(strFolder);
                     string relPath = Null.NullString;
                     if (String.IsNullOrEmpty(relativePath))
                     {
                         relPath = dir.Name + "/";
                     }
                     else
                     {
                         relPath = relativePath;
                         if (!relativePath.EndsWith("/"))
                         {
                             relPath = relPath + "/";
                         }
                         relPath = relPath + dir.Name + "/";
                     }
                     SynchronizeFolder(PortalId, strFolder, relPath, true, syncFiles, forceFolderSync, hideSystemFolders);
                 }
             }
         }
     }
     else
     {
         if (folder != null)
         {
             if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
             {
                 RemoveOrphanedFiles(folder, PortalId);
                 objFolderController.DeleteFolder(PortalId, relativePath.Replace("\\", "/"));
             }
         }
     }
 }
 public static void SetFolderPermission(int PortalId, int FolderId, int PermissionId, int RoleId, int UserId, string relativePath)
 {
     FolderPermissionInfo objFolderPermissionInfo;
     CommonLibrary.Services.FileSystem.FolderController objController = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo folder = objController.GetFolderInfo(PortalId, FolderId);
     foreach (FolderPermissionInfo fpi in folder.FolderPermissions)
     {
         if (fpi.FolderID == FolderId
             && fpi.PermissionID == PermissionId
             && fpi.RoleID == RoleId
             && fpi.UserID == UserId
             && fpi.AllowAccess == true)
         {
             return;
         }
     }
     objFolderPermissionInfo = new FolderPermissionInfo();
     objFolderPermissionInfo.FolderID = FolderId;
     objFolderPermissionInfo.PermissionID = PermissionId;
     objFolderPermissionInfo.RoleID = RoleId;
     objFolderPermissionInfo.UserID = UserId;
     objFolderPermissionInfo.AllowAccess = true;
     folder.FolderPermissions.Add(objFolderPermissionInfo, true);
     FolderPermissionController.SaveFolderPermissions(folder);
 }
 private void AddFolderPermissions(int PortalId, int folderId)
 {
     PortalInfo objPortal = GetPortal(PortalId);
     FolderController objController = new FolderController();
     FolderPermissionInfo objFolderPermission;
     FolderInfo folder = objController.GetFolderInfo(PortalId, folderId);
     PermissionController objPermissionController = new PermissionController();
     foreach (PermissionInfo objpermission in objPermissionController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", ""))
     {
         objFolderPermission = new FolderPermissionInfo(objpermission);
         objFolderPermission.FolderID = folder.FolderID;
         objFolderPermission.RoleID = objPortal.AdministratorRoleId;
         folder.FolderPermissions.Add(objFolderPermission);
         if (objpermission.PermissionKey == "READ")
         {
             objFolderPermission = new FolderPermissionInfo(objpermission);
             objFolderPermission.FolderID = folder.FolderID;
             objFolderPermission.RoleID = int.Parse(Globals.glbRoleAllUsers);
             folder.FolderPermissions.Add(objFolderPermission);
         }
     }
     FolderPermissionController.SaveFolderPermissions(folder);
 }
 public static void DeleteFolder(int PortalId, System.IO.DirectoryInfo folder, string folderName)
 {
     folder.Delete(false);
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     objFolderController.DeleteFolder(PortalId, folderName.Replace("\\", "/"));
 }
 public static void AddFile(string FileName, int PortalId, string Folder, string HomeDirectoryMapPath, string contentType)
 {
     string strFile = HomeDirectoryMapPath + Folder + FileName;
     CommonLibrary.Services.FileSystem.FileController objFiles = new CommonLibrary.Services.FileSystem.FileController();
     System.IO.FileInfo finfo = new System.IO.FileInfo(strFile);
     CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, Folder, false);
     CommonLibrary.Services.FileSystem.FileInfo objFile;
     objFile = objFiles.GetFile(FileName, PortalId, objFolder.FolderID);
     if (objFile == null)
     {
         objFiles.AddFile(PortalId, FileName, finfo.Extension, finfo.Length, 0, 0, contentType, "", objFolder.FolderID, true);
     }
     else
     {
         objFiles.UpdateFile(objFile.FileId, objFile.FileName, finfo.Extension, finfo.Length, 0, 0, contentType, "", objFolder.FolderID);
     }
 }
 public static CommonLibrary.Services.FileSystem.FolderInfo GetFolder(int PortalID, string FolderPath)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolderController.GetFolder(PortalID, FolderPath, false);
     if (Host.EnableFileAutoSync)
     {
         if (objFolder != null)
         {
             SynchronizeFolder(objFolder.PortalID, objFolder.PhysicalPath, objFolder.FolderPath, false, true, false, false);
         }
     }
     return objFolder;
 }
 public static ArrayList GetFolders(int PortalID)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     ArrayList arrFolders = new ArrayList();
     foreach (KeyValuePair<string, CommonLibrary.Services.FileSystem.FolderInfo> folderPair in objFolderController.GetFoldersSorted(PortalID))
     {
         arrFolders.Add(folderPair.Value);
     }
     return arrFolders;
 }
        private static string CreateFile(string RootPath, string FileName, long ContentLength, string ContentType, Stream InputStream, string NewFileName, bool Unzip)
        {
            // Obtain PortalSettings from Current Context
            PortalSettings settings = PortalController.GetCurrentPortalSettings();
            int PortalId = GetFolderPortalId(settings);
            bool isHost = (bool)(settings.ActiveTab.ParentId == settings.SuperTabId ? true : false);

            PortalController objPortalController = new PortalController();
            string strMessage = "";
            string strFileName = FileName;
            if (NewFileName != Null.NullString) strFileName = NewFileName;
            strFileName = RootPath + Path.GetFileName(strFileName);
            string strExtension = Path.GetExtension(strFileName).Replace(".", "");
            string strFolderpath = Globals.GetSubFolderPath(strFileName, PortalId);

            CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
            CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, strFolderpath, false);

            if (FolderPermissionController.CanAdminFolder(objFolder))
            {
                if (objPortalController.HasSpaceAvailable(PortalId, ContentLength))
                {
                    if (("," + Host.FileExtensions.ToUpper()).IndexOf("," + strExtension.ToUpper()) != -1 || isHost)
                    {
                        //Save Uploaded file to server
                        try
                        {
                            strMessage += AddFile(PortalId, InputStream, strFileName, ContentType, ContentLength, strFolderpath, true, true);

                            //Optionally Unzip File?
                            if (Path.GetExtension(strFileName).ToLower() == ".zip" & Unzip == true)
                            {
                                strMessage += UnzipFile(strFileName, RootPath, settings);
                            }
                        }
                        catch (Exception exc)
                        {
                            // save error - can happen if the security settings are incorrect on the disk
                            strMessage += "<br>" + string.Format(Localization.GetString("SaveFileError"), strFileName);
                            exc.ToString();
                        }
                    }
                    else
                    {
                        // restricted file type
                        strMessage += "<br>" + string.Format(Localization.GetString("RestrictedFileType"), strFileName, Host.FileExtensions.Replace(",", ", *."));
                    }
                }
                else
                {
                    // file too large
                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFileName);
                }
            }
            else
            {
                // insufficient folder permission in the application
                strMessage += "<br>" + string.Format(Localization.GetString("InsufficientFolderPermission"), strFolderpath);
            }

            return strMessage;
        }
Beispiel #14
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ParseFiles parses the Host Template's Files node
        /// </summary>
        /// <remarks>
        /// </remarks>
        ///	<param name="node">The Files node</param>
        ///	<param name="portalId">The PortalId (-1 for Host Files)</param>
        /// <history>
        /// [cnurse]	11/08/2004	created
        /// </history>
        /// -----------------------------------------------------------------------------
        private static void ParseFiles(XmlNode node, int portalId)
        {

            FileSystem.FileController objController = new FileSystem.FileController();

            //Parse the File nodes
            foreach (XmlNode fileNode in node.SelectNodes("file"))
            {
                string strFileName = XmlUtils.GetNodeValue(fileNode.CreateNavigator(), "filename");
                string strExtenstion = XmlUtils.GetNodeValue(fileNode.CreateNavigator(), "extension");
                long fileSize = long.Parse(XmlUtils.GetNodeValue(fileNode.CreateNavigator(), "size"));
                int iWidth = XmlUtils.GetNodeValueInt(fileNode, "width");
                int iHeight = XmlUtils.GetNodeValueInt(fileNode, "height");
                string strType = XmlUtils.GetNodeValue(fileNode.CreateNavigator(), "contentType");
                string strFolder = XmlUtils.GetNodeValue(fileNode.CreateNavigator(), "folder");

                FolderController objFolders = new FolderController();
                FolderInfo objFolder = objFolders.GetFolder(portalId, strFolder, false);
                objController.AddFile(portalId, strFileName, strExtenstion, fileSize, iWidth, iHeight, strType, strFolder, objFolder.FolderID, true
                );

            }
        }
        private void ParseFolders(XmlNode nodeFolders, int PortalId)
        {

            int FolderId;
            FolderController objController = new FolderController();
            FolderInfo objInfo;
            string folderPath;
            int storageLocation;
            bool isProtected = false;
            foreach (XmlNode node in nodeFolders.SelectNodes("//folder"))
            {
                folderPath = XmlUtils.GetNodeValue(node.CreateNavigator(), "folderpath");
                objInfo = objController.GetFolder(PortalId, folderPath, false);
                if (objInfo == null)
                {
                    isProtected = FileSystemUtils.DefaultProtectedFolders(folderPath);
                    if (isProtected == true)
                    {
                        storageLocation = (int)FolderController.StorageLocationTypes.InsecureFileSystem;
                    }
                    else
                    {
                        storageLocation = Convert.ToInt32(XmlUtils.GetNodeValue(node, "storagelocation", "0"));
                        isProtected = XmlUtils.GetNodeValueBoolean(node, "isprotected");
                    }
                    FolderId = objController.AddFolder(PortalId, folderPath, storageLocation, isProtected, false);
                    objInfo = objController.GetFolder(PortalId, folderPath, false);
                }
                else
                {
                    FolderId = objInfo.FolderID;
                }
                XmlNodeList nodeFolderPermissions = node.SelectNodes("folderpermissions/permission");
                ParseFolderPermissions(nodeFolderPermissions, PortalId, objInfo);
                XmlNodeList nodeFiles = node.SelectNodes("files/file");
                if (!String.IsNullOrEmpty(folderPath))
                {
                    folderPath += "/";
                }
                ParseFiles(nodeFiles, PortalId, objInfo);
            }
        }
 private static string UpdateFile(string strSourceFile, string strDestFile, int PortalId, bool isCopy, bool isNew, bool ClearCache)
 {
     string retValue = "";
     retValue += CheckValidFileName(strSourceFile) + " ";
     retValue += CheckValidFileName(strDestFile);
     if (retValue.Length > 1)
     {
         return retValue;
     }
     retValue = "";
     Stream sourceStream = null;
     try
     {
         CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         string sourceFolderName = Globals.GetSubFolderPath(strSourceFile, PortalId);
         string sourceFileName = GetFileName(strSourceFile);
         CommonLibrary.Services.FileSystem.FolderInfo sourceFolder = objFolderController.GetFolder(PortalId, sourceFolderName, false);
         string destFileName = GetFileName(strDestFile);
         string destFolderName = Globals.GetSubFolderPath(strDestFile, PortalId);
         CommonLibrary.Services.FileSystem.FileInfo file;
         if (sourceFolder != null)
         {
             file = objFileController.GetFile(sourceFileName, PortalId, sourceFolder.FolderID);
             if (file != null)
             {
                 sourceStream = (Stream)GetFileStream(file);
                 if (isCopy)
                 {
                     AddFile(PortalId, sourceStream, strDestFile, "", file.Size, destFolderName, true, ClearCache);
                 }
                 else
                 {
                     CommonLibrary.Services.FileSystem.FolderInfo destinationFolder = objFolderController.GetFolder(PortalId, destFolderName, false);
                     if (destinationFolder != null)
                     {
                         objFileController.UpdateFile(file.FileId, destFileName, file.Extension, file.Size, file.Width, file.Height, file.ContentType, destFolderName, destinationFolder.FolderID);
                         WriteStream(file.FileId, sourceStream, strDestFile, destinationFolder.StorageLocation, true);
                         if (sourceFolder.StorageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem)
                         {
                             DeleteFile(strSourceFile);
                         }
                         if (sourceFolder.StorageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem)
                         {
                             DeleteFile(strSourceFile + Globals.glbProtectedExtension);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         retValue = ex.Message;
     }
     finally
     {
         if (sourceStream != null)
         {
             sourceStream.Close();
             sourceStream.Dispose();
         }
     }
     return retValue;
 }
 public static ArrayList GetFoldersByUser(int PortalID, bool IncludeSecure, bool IncludeDatabase, string Permissions)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     ArrayList arrFolders = new ArrayList();
     foreach (CommonLibrary.Services.FileSystem.FolderInfo folder in objFolderController.GetFoldersSorted(PortalID).Values)
     {
         bool canAdd = true;
         switch (folder.StorageLocation)
         {
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure:
                 canAdd = IncludeDatabase;
                 break;
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem:
                 canAdd = IncludeSecure;
                 break;
         }
         if (canAdd && PortalID > Null.NullInteger)
         {
             canAdd = FolderPermissionController.HasFolderPermission(folder.FolderPermissions, Permissions);
         }
         if (canAdd)
         {
             arrFolders.Add(folder);
         }
     }
     return arrFolders;
 }
 public static void RemoveOrphanedFolders(int PortalId)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     ArrayList arrFolders = GetFolders(PortalId);
     foreach (CommonLibrary.Services.FileSystem.FolderInfo objFolder in arrFolders)
     {
         if (objFolder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
         {
             if (Directory.Exists(objFolder.PhysicalPath) == false)
             {
                 RemoveOrphanedFiles(objFolder, PortalId);
                 objFolderController.DeleteFolder(PortalId, objFolder.FolderPath);
             }
         }
     }
 }
         //-----------------------------------------------------------------------------
         //<summary>
         //Creates a User Folder
         //</summary>
         //<param name="_PortalSettings">Portal Settings for the Portal</param>
         //<param name="parentFolder">The Parent Folder Name</param>
         //<param name="UserID">The UserID, in order to generate the path/foldername</param>
         //<param name="StorageLocation">The Storage Location</param>
         //<remarks>
         //</remarks>
         //<history>
         //   [jlucarino]	02/26/2010	Created
         //</history>
         //-----------------------------------------------------------------------------
        public static void AddUserFolder(PortalSettings _PortalSettings, string parentFolder, int StorageLocation, int UserID)
        {
            int PortalId = 0;
            string ParentFolderName = null;
            System.IO.DirectoryInfo dinfoNew = default(System.IO.DirectoryInfo);
            string RootFolder = "";
            string SubFolder = "";

            PortalId = _PortalSettings.PortalId;
            ParentFolderName = _PortalSettings.HomeDirectoryMapPath;

            RootFolder = GetUserFolderPathElement(UserID, EnumUserFolderElement.Root);
            SubFolder = GetUserFolderPathElement(UserID, EnumUserFolderElement.SubFolder);

            //create root folder
            string folderPath = "";
            folderPath = System.IO.Path.Combine(Path.Combine(ParentFolderName, "Users"), RootFolder);
            dinfoNew = new System.IO.DirectoryInfo(folderPath);
            if (!dinfoNew.Exists)
            {
                dinfoNew.Create();
                AddFolder(PortalId, folderPath.Substring(ParentFolderName.Length).Replace("\\", "/"), StorageLocation);
            }

            //create two-digit subfolder
            folderPath = System.IO.Path.Combine(folderPath, SubFolder);
            dinfoNew = new System.IO.DirectoryInfo(folderPath);
            if (!dinfoNew.Exists)
            {
                dinfoNew.Create();
                AddFolder(PortalId, folderPath.Substring(ParentFolderName.Length).Replace("\\", "/"), StorageLocation);
            }

            //create folder from UserID
            folderPath = System.IO.Path.Combine(folderPath, UserID.ToString());
            dinfoNew = new System.IO.DirectoryInfo(folderPath);
            if (!dinfoNew.Exists)
            {
                dinfoNew.Create();
                int folderID = AddFolder(PortalId, folderPath.Substring(ParentFolderName.Length).Replace("\\", "/"), StorageLocation);

                //Give user Read Access to this folder
                CommonLibrary.Services.FileSystem.FolderInfo folder = new CommonLibrary.Services.FileSystem.FolderController().GetFolderInfo(PortalId, folderID);
                foreach (PermissionInfo permission in PermissionController.GetPermissionsByFolder())
                {
                    if (permission.PermissionKey.ToUpper() == "READ" || permission.PermissionKey.ToUpper() == "WRITE")
                    {
                        FolderPermissionInfo folderPermission = new FolderPermissionInfo(permission);
                        folderPermission.FolderID = folder.FolderID;
                        folderPermission.UserID = UserID;
                        folderPermission.RoleID = Null.NullInteger;
                        folderPermission.AllowAccess = true;

                        folder.FolderPermissions.Add(folderPermission);
                    }
                }

                FolderPermissionController.SaveFolderPermissions(folder);

            }
        }
 public static void SetFolderPermissions(int PortalId, int FolderId, int AdministratorRoleId, string relativePath)
 {
     CommonLibrary.Services.FileSystem.FolderInfo folder = new CommonLibrary.Services.FileSystem.FolderController().GetFolderInfo(PortalId, FolderId);
     foreach (PermissionInfo objPermission in PermissionController.GetPermissionsByFolder())
     {
         FolderPermissionInfo folderPermission = new FolderPermissionInfo(objPermission);
         folderPermission.FolderID = FolderId;
         folderPermission.RoleID = AdministratorRoleId;
         folder.FolderPermissions.Add(folderPermission, true);
     }
     FolderPermissionController.SaveFolderPermissions(folder);
 }
 public static string DeleteFile(string strSourceFile, PortalSettings settings, bool ClearCache)
 {
     string retValue = "";
     int PortalId = GetFolderPortalId(settings);
     string folderName = Globals.GetSubFolderPath(strSourceFile, PortalId);
     string fileName = GetFileName(strSourceFile);
     CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, folderName, false);
     if (FolderPermissionController.CanAdminFolder(objFolder))
     {
         try
         {
             DeleteFile(strSourceFile);
             DeleteFile(strSourceFile + Globals.glbProtectedExtension);
             CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
             objFileController.DeleteFile(PortalId, fileName, objFolder.FolderID, ClearCache);
         }
         catch (IOException ioEx)
         {
             retValue += "<br>" + string.Format(Localization.GetString("FileInUse"), strSourceFile);
             ioEx.ToString();
         }
         catch (Exception ex)
         {
             retValue = ex.Message;
         }
     }
     else
     {
         retValue += "<br>" + string.Format(Localization.GetString("InsufficientFolderPermission"), folderName);
     }
     return retValue;
 }
 public static void SetFolderPermissions(int PortalId, int FolderId, string relativePath)
 {
     if (!String.IsNullOrEmpty(relativePath))
     {
         CommonLibrary.Services.FileSystem.FolderInfo folder = new CommonLibrary.Services.FileSystem.FolderController().GetFolderInfo(PortalId, FolderId);
         string parentFolderPath = relativePath.Substring(0, relativePath.Substring(0, relativePath.Length - 1).LastIndexOf("/") + 1);
         foreach (FolderPermissionInfo objPermission in FolderPermissionController.GetFolderPermissionsCollectionByFolder(PortalId, parentFolderPath))
         {
             FolderPermissionInfo folderPermission = new FolderPermissionInfo(objPermission);
             folderPermission.FolderID = FolderId;
             folderPermission.RoleID = objPermission.RoleID;
             folderPermission.UserID = objPermission.UserID;
             folderPermission.AllowAccess = objPermission.AllowAccess;
             folder.FolderPermissions.Add(folderPermission, true);
         }
         FolderPermissionController.SaveFolderPermissions(folder);
     }
 }
 public static bool DownloadFile(int PortalId, int FileId, bool ClientCache, bool ForceDownload)
 {
     bool blnDownload = false;
     CommonLibrary.Services.FileSystem.FileController objFiles = new CommonLibrary.Services.FileSystem.FileController();
     CommonLibrary.Services.FileSystem.FileInfo objFile = objFiles.GetFileById(FileId, PortalId);
     if (objFile != null)
     {
         string filename = objFile.FileName;
         if (HttpContext.Current.Request.UserAgent.IndexOf("; MSIE ") > 0)
         {
             filename = HttpUtility.UrlEncode(filename);
         }
         CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, objFile.Folder, false);
         if (FolderPermissionController.CanViewFolder(objFolder))
         {
             bool blnFileExists = true;
             if (Host.EnableFileAutoSync)
             {
                 string strFile = "";
                 switch (objFile.StorageLocation)
                 {
                     case (int)FolderController.StorageLocationTypes.InsecureFileSystem:
                         strFile = objFile.PhysicalPath;
                         break;
                     case (int)FolderController.StorageLocationTypes.SecureFileSystem:
                         strFile = objFile.PhysicalPath + Globals.glbProtectedExtension;
                         break;
                 }
                 if (!String.IsNullOrEmpty(strFile))
                 {
                     System.IO.FileInfo objFileInfo = new System.IO.FileInfo(strFile);
                     if (objFileInfo.Exists)
                     {
                         if (objFile.Size != objFileInfo.Length)
                         {
                             objFile.Size = Convert.ToInt32(objFileInfo.Length);
                             UpdateFileData(FileId, objFile.FolderId, PortalId, objFile.FileName, objFile.Extension, GetContentType(objFile.Extension), objFileInfo.Length, objFile.Folder);
                         }
                     }
                     else
                     {
                         RemoveOrphanedFile(objFile, PortalId);
                         blnFileExists = false;
                     }
                 }
             }
             if (blnFileExists)
             {
                 int scriptTimeOut = HttpContext.Current.Server.ScriptTimeout;
                 HttpContext.Current.Server.ScriptTimeout = int.MaxValue;
                 HttpResponse objResponse = HttpContext.Current.Response;
                 objResponse.ClearContent();
                 objResponse.ClearHeaders();
                 if (ForceDownload)
                 {
                     objResponse.AppendHeader("content-disposition", "attachment; filename=\"" + filename + "\"");
                 }
                 else
                 {
                     objResponse.AppendHeader("content-disposition", "inline; filename=\"" + filename + "\"");
                 }
                 objResponse.AppendHeader("Content-Length", objFile.Size.ToString());
                 objResponse.ContentType = GetContentType(objFile.Extension.Replace(".", ""));
                 System.IO.Stream objStream = null;
                 try
                 {
                     objStream = FileSystemUtils.GetFileStream(objFile);
                     WriteStream(objResponse, objStream);
                 }
                 catch (Exception ex)
                 {
                     objResponse.Write("Error : " + ex.Message);
                 }
                 finally
                 {
                     if (objStream != null)
                     {
                         objStream.Close();
                         objStream.Dispose();
                     }
                 }
                 objResponse.Flush();
                 objResponse.End();
                 HttpContext.Current.Server.ScriptTimeout = scriptTimeOut;
                 blnDownload = true;
             }
         }
     }
     return blnDownload;
 }
 public void ParseTemplate(int PortalId, string TemplatePath, string TemplateFile, int AdministratorId, PortalTemplateModuleAction mergeTabs, bool IsNewPortal)
 {
     XmlDocument xmlPortal = new XmlDocument();
     XmlNode node;
     try
     {
         xmlPortal.Load(TemplatePath + TemplateFile);
     }
     catch
     {
     }
     node = xmlPortal.SelectSingleNode("//portal/settings");
     if (node != null && IsNewPortal)
     {
         ParsePortalSettings(node, PortalId);
     }
     node = xmlPortal.SelectSingleNode("//portal/rolegroups");
     if (node != null)
     {
         ParseRoleGroups(node.CreateNavigator(), PortalId, AdministratorId);
     }
     node = xmlPortal.SelectSingleNode("//portal/roles");
     if (node != null)
     {
         ParseRoles(node.CreateNavigator(), PortalId, AdministratorId);
     }
     node = xmlPortal.SelectSingleNode("//portal/portalDesktopModules");
     if (node != null)
     {
         ParsePortalDesktopModules(node.CreateNavigator(), PortalId);
     }
     node = xmlPortal.SelectSingleNode("//portal/folders");
     if (node != null)
     {
         ParseFolders(node, PortalId);
     }
     var objController = new FolderController();
     if (objController.GetFolder(PortalId, "", false) == null)
     {
         int folderid = objController.AddFolder(PortalId, "", (int)Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem, true, false);
         AddFolderPermissions(PortalId, folderid);
     }
     if (objController.GetFolder(PortalId, "Templates/", false) == null)
     {
         int folderid = objController.AddFolder(PortalId, "Templates/", (int)Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem, true, false);
         AddFolderPermissions(PortalId, folderid);
     }
     // force creation of templates folder if not present on template
     if (objController.GetFolder(PortalId, "Users/", false) == null)
     {
         int folderid = objController.AddFolder(PortalId, "Users/", (int)Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem, true, false);
         AddFolderPermissions(PortalId, folderid);
     }
     if (mergeTabs == PortalTemplateModuleAction.Replace)
     {
         var objTabs = new TabController();
         TabInfo objTab;
         foreach (KeyValuePair<int, TabInfo> tabPair in objTabs.GetTabsByPortal(PortalId))
         {
             objTab = tabPair.Value;
             objTab.TabName = objTab.TabName + "_old";
             objTab.TabPath = Common.Globals.GenerateTabPath(objTab.ParentId, objTab.TabName);
             objTab.IsDeleted = true;
             objTabs.UpdateTab(objTab);
             var objModules = new ModuleController();
             ModuleInfo objModule;
             foreach (KeyValuePair<int, ModuleInfo> modulePair in objModules.GetTabModules(objTab.TabID))
             {
                 objModule = modulePair.Value;
                 objModules.DeleteTabModule(objModule.TabID, objModule.ModuleID, false);
             }
         }
     }
     node = xmlPortal.SelectSingleNode("//portal/tabs");
     if (node != null)
     {
         string version = xmlPortal.DocumentElement.GetAttribute("version");
         if (version != "5.0")
         {
             var xmlAdmin = new XmlDocument();
             try
             {
                 xmlAdmin.Load(TemplatePath + "admin.template");
             }
             catch
             {
             }
             XmlNode adminNode = xmlAdmin.SelectSingleNode("//portal/tabs");
             foreach (XmlNode adminTabNode in adminNode.ChildNodes)
             {
                 node.AppendChild(xmlPortal.ImportNode(adminTabNode, true));
             }
         }
         ParseTabs(node, PortalId, false, mergeTabs, IsNewPortal);
     }
 }