/DesktopModules/Admin/FileManager/FileManager.ascx.cs
C# | 2499 lines | 1914 code | 132 blank | 453 comment | 99 complexity | dd438f47e13b1f24c0a6df29be52de39 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- #region Copyright
- //
- // DotNetNukeŽ - http://www.dotnetnuke.com
- // Copyright (c) 2002-2012
- // by DotNetNuke Corporation
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
- // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
- // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions
- // of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- // DEALINGS IN THE SOFTWARE.
- #endregion
- #region Usings
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using DotNetNuke.Common.Utilities;
- using DotNetNuke.Entities.Host;
- using DotNetNuke.Entities.Icons;
- using DotNetNuke.Entities.Modules;
- using DotNetNuke.Entities.Modules.Actions;
- using DotNetNuke.Entities.Portals;
- using DotNetNuke.Instrumentation;
- using DotNetNuke.Security;
- using DotNetNuke.Security.Permissions;
- using DotNetNuke.Services.Exceptions;
- using DotNetNuke.Services.FileSystem;
- using DotNetNuke.Services.Localization;
- using DotNetNuke.UI.Skins.Controls;
- using DotNetNuke.UI.Utilities;
- using DotNetNuke.UI.WebControls;
- using ICSharpCode.SharpZipLib.Zip;
- using Microsoft.VisualBasic;
- using DataCache = DotNetNuke.Common.Utilities.DataCache;
- using DNNTreeNode = DotNetNuke.UI.WebControls.TreeNode;
- using DNNTreeNodeCollection = DotNetNuke.UI.WebControls.TreeNodeCollection;
- using FileInfo = DotNetNuke.Services.FileSystem.FileInfo;
- using Globals = DotNetNuke.Common.Globals;
- #endregion
- namespace DotNetNuke.Modules.Admin.FileManager
- {
- /// -----------------------------------------------------------------------------
- /// Project : DotNetNuke
- /// Class : FileManager
- ///
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Supplies the functionality for uploading files to the Portal
- /// Synchronizing Files within the folder and the database
- /// and Provides status of available disk space for the portal
- /// as well as limiting uploads to the restricted allocated file space
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [DYNST] 2/1/2004 Created
- /// [Jon Henning] 11/1/2004 Updated to use ClientAPI/DNNTree
- /// [cnurse] 12/2/2004 Database Synchronization added
- /// </history>
- /// -----------------------------------------------------------------------------
- public partial class FileManager : PortalModuleBase, IActionable, IClientAPICallbackEventHandler
- {
- #region "Private Members"
- private string _ErrorMessage =
- "<TABLE><TR><TD height=100% class=NormalRed>{0}</TD></TR><TR valign=bottom><TD align=center><INPUT id=btnClearError onclick=clearErrorMessage(); type=button value=OK></TD></TR></TABLE>";
- private SortedList<int, string> _folderMappings;
- #endregion
- #region "Protected Properties"
- protected bool IsAdminRole
- {
- get
- {
- return PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName);
- }
- }
- #endregion
- #region "Public Properties"
- public int FolderPortalID
- {
- get
- {
- if (IsHostMenu)
- {
- return Null.NullInteger;
- }
- else
- {
- return PortalId;
- }
- }
- }
- public string RootFolderName
- {
- get
- {
- if (ViewState["RootFolderName"] != null)
- {
- return ViewState["RootFolderName"].ToString();
- }
- else
- {
- return "";
- }
- }
- set
- {
- ViewState["RootFolderName"] = value;
- }
- }
- public string RootFolderPath
- {
- get
- {
- string _CurRootFolder;
- if (IsHostMenu)
- {
- _CurRootFolder = Globals.HostMapPath;
- }
- else
- {
- _CurRootFolder = PortalSettings.HomeDirectoryMapPath;
- }
- return _CurRootFolder;
- }
- }
- public string Sort
- {
- get
- {
- return ViewState["strSort"].ToString();
- }
- set
- {
- ViewState.Add("strSort", value);
- }
- }
- public string LastSort
- {
- get
- {
- return ViewState["strLastSort"].ToString();
- }
- set
- {
- ViewState.Add("strLastSort", value);
- }
- }
- public string FilterFiles
- {
- get
- {
- return ViewState["strFilterFiles"].ToString();
- }
- set
- {
- ViewState.Add("strFilterFiles", value);
- }
- }
- public string LastPath
- {
- get
- {
- return UnMaskPath(ClientAPI.GetClientVariable(Page, "LastPath"));
- }
- set
- {
- value = MaskPath(value);
- ClientAPI.RegisterClientVariable(Page, "LastPath", value, true);
- }
- }
- public string DestPath
- {
- get
- {
- return ClientAPI.GetClientVariable(Page, "DestPath");
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "DestPath", value, true);
- }
- }
- public string SourcePath
- {
- get
- {
- return ClientAPI.GetClientVariable(Page, "SourcePath");
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "SourcePath", value, true);
- }
- }
- public string MoveFiles
- {
- get
- {
- return ClientAPI.GetClientVariable(Page, "MoveFiles");
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "MoveFiles", value, true);
- }
- }
- public bool IsRefresh
- {
- get
- {
- return Convert.ToBoolean(ClientAPI.GetClientVariable(Page, "IsRefresh"));
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "IsRefresh", Convert.ToString(Convert.ToInt32(value)), true);
- }
- }
- public bool DisabledButtons
- {
- get
- {
- return Convert.ToBoolean(ClientAPI.GetClientVariable(Page, "DisabledButtons"));
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "DisabledButtons", Convert.ToString(Convert.ToInt32(value)), true);
- }
- }
- public string MoveStatus
- {
- get
- {
- return ClientAPI.GetClientVariable(Page, "MoveStatus");
- }
- set
- {
- ClientAPI.RegisterClientVariable(Page, "MoveStatus", value, true);
- }
- }
- public string LastFolderPath
- {
- get
- {
- if (ViewState["LastFolderPath"] != null)
- {
- return ViewState["LastFolderPath"].ToString();
- }
- else
- {
- return "";
- }
- }
- set
- {
- ViewState["LastFolderPath"] = value;
- }
- }
- public int PageSize
- {
- get
- {
- return Convert.ToInt32(selPageSize.SelectedValue);
- }
- }
- public int PageIndex
- {
- get
- {
- if (ViewState["PageIndex"] != null)
- {
- return Convert.ToInt32(ViewState["PageIndex"]);
- }
- else
- {
- return 0;
- }
- }
- set
- {
- if (value >= 0 && value < dgFileList.PageCount)
- {
- ViewState["PageIndex"] = value;
- }
- }
- }
- private SortedList<int, string> FolderMappings
- {
- get
- {
- if (_folderMappings == null)
- {
- _folderMappings = new SortedList<int, string>();
- var folderMappingController = FolderMappingController.Instance;
- var folderMappings = folderMappingController.GetFolderMappings(FolderPortalID);
- folderMappings.ForEach(f => _folderMappings.Add(f.FolderMappingID, f.MappingName));
- }
- return _folderMappings;
- }
- }
- #endregion
- #region "Private Methods"
- protected bool HasPermission(string permissionKey)
- {
- var hasPermision = UserInfo.IsSuperUser;
- var strSourcePath = UnMaskPath(DestPath).Replace(RootFolderPath, "").Replace("\\", "/");
- var objFolder = FolderManager.Instance.GetFolder(FolderPortalID, strSourcePath);
- if (!hasPermision && objFolder != null)
- {
- hasPermision = IsEditable && FolderPermissionController.HasFolderPermission(objFolder.FolderPermissions, permissionKey);
- }
- return hasPermision;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Adds a File to the DataTable used for the File List grid
- /// </summary>
- /// <param name="tblFiles">The DataTable</param>
- /// <param name="objFile">The FileInfo object to add</param>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/3/2004 documented
- /// [cnurse] 04/24/2006 Updated to use new Secure Storage
- /// </history>
- /// -----------------------------------------------------------------------------
- private void AddFileToTable(DataTable tblFiles, FileInfo objFile)
- {
- DataRow dRow = tblFiles.NewRow();
- dRow["FileType"] = "File";
- dRow["FileId"] = objFile.FileId;
- dRow["FileName"] = objFile.FileName;
- dRow["FileSize"] = objFile.Size.ToString("##,##0");
- dRow["IntFileSize"] = objFile.Size;
-
- if (!String.IsNullOrEmpty(objFile.Extension) || objFile.Extension != null)
- {
- dRow["Extension"] = objFile.Extension;
- }
- else
- {
- dRow["Extension"] = "none";
- }
- if (objFile.SupportsFileAttributes)
- {
- dRow["SupportsFileAttributes"] = true;
- if (objFile.FileAttributes.HasValue)
- {
- dRow["DateModified"] = objFile.LastModificationTime;
- dRow["Archive"] = objFile.FileAttributes.Value & FileAttributes.Archive;
- dRow["ReadOnly"] = objFile.FileAttributes.Value & FileAttributes.ReadOnly;
- dRow["Hidden"] = objFile.FileAttributes.Value & FileAttributes.Hidden;
- dRow["System"] = objFile.FileAttributes.Value & FileAttributes.System;
- dRow["AttributeString"] = GetAttributeString(objFile.FileAttributes.Value);
- }
- }
- else
- {
- dRow["SupportsFileAttributes"] = false;
- dRow["Archive"] = false;
- dRow["ReadOnly"] = false;
- dRow["Hidden"] = false;
- dRow["System"] = false;
- dRow["AttributeString"] = "";
- }
- tblFiles.Rows.Add(dRow);
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Adds node to tree
- /// </summary>
- /// <param name="strName">Name of folder to display</param>
- /// <param name="strKey">Masked Key of folder location</param>
- /// <param name="eImage">Type of image</param>
- /// <param name="objNodes">Node collection to add to</param>
- /// <returns></returns>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 10/26/2004 Created
- /// [Jon Henning] 8/24/2005 Added Populate on Demand (POD) logic
- /// </history>
- /// -----------------------------------------------------------------------------
- private DNNTreeNode AddNode(string strName, string strKey, int imageIndex, DNNTreeNodeCollection objNodes)
- {
- DNNTreeNode objNode;
- objNode = new DNNTreeNode(HttpUtility.HtmlEncode(strName));
- objNode.Key = strKey;
- objNode.ToolTip = strName;
- objNode.ImageIndex = imageIndex;
- objNode.CssClass = "FileManagerTreeNode";
- objNodes.Add(objNode);
- if (objNode.Key == DestPath)
- {
- objNode.Selected = true;
- objNode.MakeNodeVisible();
- }
- return objNode;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Adds node to tree
- /// </summary>
- /// <param name="folder">The FolderInfo object to add</param>
- /// <param name="objNodes">Node collection to add to</param>
- /// <returns></returns>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 04/24/2006 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private DNNTreeNode AddNode(FolderInfo folder, DNNTreeNodeCollection objNodes)
- {
- DNNTreeNode objNode;
- string strName = folder.FolderName;
- string strKey = MaskPath(RootFolderPath + folder.FolderPath);
- var subFolders = FolderManager.Instance.GetFolders(folder).ToList();
- var imageIndex = FolderMappings.IndexOfKey(folder.FolderMappingID);
- objNode = AddNode(strName, strKey, imageIndex, objNodes);
- objNode.HasNodes = subFolders.Count > 0;
- return objNode;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// BindFileList
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void BindFileList()
- {
- string strCurPage;
- LastPath = PathUtils.Instance.RemoveTrailingSlash(UnMaskPath(DestPath));
- dgFileList.PageSize = PageSize;
- dgFileList.CurrentPageIndex = PageIndex;
- var folderPath = PathUtils.Instance.StripFolderPath(DestPath).Replace("\\", "/");
- if (Host.EnableFileAutoSync)
- {
- FolderManager.Instance.Synchronize(FolderPortalID, folderPath, false, true);
- }
- GetFilesByFolder(folderPath);
- if (dgFileList.PageCount > 1)
- {
- tblMessagePager.Visible = true;
- strCurPage = Localization.GetString("Pages");
- lblCurPage.Text = string.Format(strCurPage, (dgFileList.CurrentPageIndex + 1), (dgFileList.PageCount));
- lnkMoveFirst.Text = "<img border=0 Alt='" + Localization.GetString("First") + "' src='" + IconController.IconURL("MoveFirst") + "'>";
- lnkMovePrevious.Text = "<img border=0 Alt='" + Localization.GetString("Previous") + "' src='" + IconController.IconURL("MovePrevious") + "'>";
- lnkMoveNext.Text = "<img border=0 Alt='" + Localization.GetString("Next") + "' src='" + IconController.IconURL("MoveNext") + "'>";
- lnkMoveLast.Text = "<img border=0 Alt='" + Localization.GetString("Last") + "' src='" + IconController.IconURL("Movelast") + "'>";
- }
- else
- {
- tblMessagePager.Visible = false;
- }
- lblCurFolder.Text = Regex.Replace(DestPath, "^0\\\\", RootFolderName + "\\");
- MoveFiles = "";
- UpdateSpaceUsed();
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cpaterra] 4/6/2006 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void BindStorageLocationTypes()
- {
- ddlStorageLocation.Items.Clear();
- foreach (var folderMapping in FolderMappingController.Instance.GetFolderMappings(FolderPortalID))
- {
- ddlStorageLocation.Items.Add(new ListItem(folderMapping.MappingName, folderMapping.FolderMappingID.ToString()));
- }
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// The BindFolderTree helper method is used to bind the list of
- /// files for this portal or for the hostfolder, to an asp:DATAGRID server control
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [DYNST] 2/1/2004 Created
- /// [Jon Henning] 11/1/2004 Updated to use ClientAPI/DNNTree
- /// [cnurse] 12/2/2004 Updated to use Localization for Root
- /// [Jon Henning] 8/24/2005 Added Populate on Demand (POD) logic
- /// [cnurse] 04/24/2006 Updated to use new Secure Storage
- /// </history>
- /// -----------------------------------------------------------------------------
- private void BindFolderTree()
- {
- DNNTreeNode objNode;
- //Clear the Tree Nodes Collection
- DNNTree.TreeNodes.Clear();
- objNode = AddNode(RootFolderName, MaskPath(RootFolderPath), FolderMappings.IndexOfValue("Standard"), DNNTree.TreeNodes);
- var folders = FolderManager.Instance.GetFolders(FolderPortalID).ToList();
- objNode.HasNodes = folders.Count > 1;
- if (DNNTree.PopulateNodesFromClient == false || DNNTree.IsDownLevel)
- {
- PopulateTree(objNode.TreeNodes, RootFolderPath);
- }
- if (DNNTree.SelectedTreeNodes.Count == 0)
- {
- objNode.Selected = true;
- }
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// GeneratePermissionsGrid generates the permissions grid for the folder
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/2/2004 documented
- /// </history>
- /// -----------------------------------------------------------------------------
- private void GeneratePermissionsGrid()
- {
- var folderPath = PathUtils.Instance.StripFolderPath(DestPath).Replace("\\", "/");
- dgPermissions.FolderPath = folderPath;
- var objFolderInfo = FolderManager.Instance.GetFolder(FolderPortalID, folderPath);
- if (objFolderInfo != null && ddlStorageLocation.Items.FindByValue(Convert.ToString(objFolderInfo.FolderMappingID)) != null)
- {
- ddlStorageLocation.SelectedValue = Convert.ToString(objFolderInfo.FolderMappingID);
- phSecureFolderWarning.Visible = !objFolderInfo.IsStorageSecure;
- }
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// GetAttributeString generates the attributes string from the FileAttributes
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/2/2004 documented
- /// </history>
- /// -----------------------------------------------------------------------------
- private string GetAttributeString(FileAttributes attributes)
- {
- string strResult = "";
- if ((attributes & FileAttributes.Archive) == FileAttributes.Archive)
- {
- strResult += "A";
- }
- if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
- {
- strResult += "R";
- }
- if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
- {
- strResult += "H";
- }
- if ((attributes & FileAttributes.System) == FileAttributes.System)
- {
- strResult += "S";
- }
- return strResult;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// GetFilesByFolder gets the Files/Folders to display
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/2/2004 documented and modified to display Folders in
- /// the grid
- /// [cnurse] 04/24/2006 Updated to use new Secure Storage
- /// </history>
- /// -----------------------------------------------------------------------------
- private void GetFilesByFolder(string strFolderName)
- {
- DataTable tblFiles = GetFileTable();
- var objFolder = FolderManager.Instance.GetFolder(FolderPortalID, strFolderName);
- if (objFolder != null)
- {
- var arrFiles = FolderManager.Instance.GetFiles(objFolder);
- foreach (FileInfo objFile in arrFiles)
- {
- AddFileToTable(tblFiles, objFile);
- }
- }
- var dv = new DataView();
- dv.Table = tblFiles;
- dv.Sort = Sort;
- if (!String.IsNullOrEmpty(FilterFiles))
- {
- dv.RowFilter = "FileName like '%" + FilterFiles + "%'";
- }
- dgFileList.DataSource = dv;
- dgFileList.DataBind();
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// GetFileTable creates the DataTable used to store the list of files and folders
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/3/2004 documented and modified to display Folders in
- /// the grid
- /// </history>
- /// -----------------------------------------------------------------------------
- private DataTable GetFileTable()
- {
- var tblFiles = new DataTable("Files");
- var myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.String");
- myColumns.ColumnName = "FileType";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Int32");
- myColumns.ColumnName = "FileId";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.String");
- myColumns.ColumnName = "FileName";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.String");
- myColumns.ColumnName = "FileSize";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Int32");
- myColumns.ColumnName = "IntFileSize";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.DateTime");
- myColumns.ColumnName = "DateModified";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Boolean");
- myColumns.ColumnName = "ReadOnly";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Boolean");
- myColumns.ColumnName = "Hidden";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Boolean");
- myColumns.ColumnName = "System";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Boolean");
- myColumns.ColumnName = "Archive";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.String");
- myColumns.ColumnName = "AttributeString";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.String");
- myColumns.ColumnName = "Extension";
- tblFiles.Columns.Add(myColumns);
- myColumns = new DataColumn();
- myColumns.DataType = Type.GetType("System.Boolean");
- myColumns.ColumnName = "SupportsFileAttributes";
- tblFiles.Columns.Add(myColumns);
- return tblFiles;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Gets the size of the all the files in the zip file
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/4/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private long GetZipFileExtractSize(string strFileName)
- {
- ZipEntry objZipEntry;
- ZipInputStream objZipInputStream;
- try
- {
- objZipInputStream = new ZipInputStream(File.OpenRead(strFileName));
- }
- catch (Exception ex)
- {
- DnnLog.Error(ex);
- ShowErrorMessage(MaskString(ex.Message));
- return -1;
- }
- objZipEntry = objZipInputStream.GetNextEntry();
- long iTemp = 0;
- while (objZipEntry != null)
- {
- iTemp = iTemp + objZipEntry.Size;
- objZipEntry = objZipInputStream.GetNextEntry();
- }
- objZipInputStream.Close();
- return iTemp;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Sets common properties on DNNTree control
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// [Jon Henning] 8/24/2005 Added Populate on Demand (POD) logic
- /// </history>
- /// -----------------------------------------------------------------------------
- private void InitializeTree()
- {
- DNNTree.SystemImagesPath = ResolveUrl("~/images/");
- PreloadFolderImages();
- DNNTree.ImageList.Add(IconController.IconURL("File"));
- DNNTree.IndentWidth = 10;
- DNNTree.CollapsedNodeImage = IconController.IconURL("Max","12X12");
- DNNTree.ExpandedNodeImage = IconController.IconURL("Min", "12X12");
- DNNTree.PopulateNodesFromClient = true;
- DNNTree.JSFunction = "nodeSelected();";
- }
- private void PreloadFolderImages()
- {
- IFolderMappingController folderMappingController = FolderMappingController.Instance;
- FolderMappingInfo folderMappingInfo = null;
- string imageUrl = String.Empty;
- foreach (var folderMapping in FolderMappings)
- {
- folderMappingInfo = folderMappingController.GetFolderMapping(folderMapping.Key);
- imageUrl = folderMappingInfo.ImageUrl;
- DNNTree.ImageList.Add(imageUrl);
- }
- }
- private void ManageToolbarButton(HtmlGenericControl wrapperControl, Image imageControl, string js, string imageRootName, bool enableButton)
- {
- if (enableButton)
- {
- wrapperControl.Attributes.Add("style", "cursor: pointer");
- wrapperControl.Attributes.Add("onclick", js);
- imageControl.ImageUrl = IconController.IconURL(imageRootName);
- }
- else
- {
- wrapperControl.Attributes.Remove("style");
- wrapperControl.Attributes.Remove("onclick");
- imageControl.ImageUrl = IconController.IconURL(imageRootName + "Disabled");
- }
- }
- private void ManageSecurity()
- {
- ManageToolbarButton(addFolder, lnkAddFolderIMG, "return canAddFolder();", "AddFolder", HasPermission("ADD"));
- ManageToolbarButton(deleteFolder, lnkDelFolderIMG, "return deleteFolder();", "DeleteFolder", HasPermission("DELETE"));
- ManageToolbarButton(syncFolder, lnkSyncFolderIMG, "__doPostBack(m_sUCPrefixName + 'lnkSyncFolder', '');", "Synchronize", HasPermission("MANAGE"));
- chkRecursive.Enabled = HasPermission("MANAGE");
- ManageToolbarButton(refresh, lnkRefreshIMG, "__doPostBack(m_sUCPrefixName + 'lnkRefresh', '');", "Refresh", true);
- ManageToolbarButton(copy, lnkCopy, "copyCheckedFiles();", "CopyFile", HasPermission("COPY"));
- ManageToolbarButton(move, lnkMove, "moveFiles();", "MoveFile", HasPermission("COPY"));
- ManageToolbarButton(upload, lnkUploadIMG, "__doPostBack(m_sUCPrefixName + 'lnkUpload', '');", "UploadFile", HasPermission("ADD"));
- ManageToolbarButton(delete, lnkDelete, "deleteCheckedFiles();", "Delete", HasPermission("DELETE"));
- ManageToolbarButton(filter, lnkFilterIMG, "__doPostBack(m_sUCPrefixName + 'lnkFilter', '');", "Search", true);
- lnkCopy.Enabled = IsEditable;
- lnkMove.Enabled = IsEditable;
- lnkUpload.Enabled = IsEditable;
- lnkDelete.Enabled = IsEditable;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Masks the path
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private string MaskPath(string strOrigPath)
- {
- return strOrigPath.Replace(PathUtils.Instance.RemoveTrailingSlash(RootFolderPath), "0").Replace("/", "\\");
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Masks a string
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private string MaskString(string strSource)
- {
- var search = PathUtils.Instance.RemoveTrailingSlash(RootFolderPath).ToUpper();
- var replace = Localization.GetString("PortalRoot", LocalResourceFile);
- var result = "";
- var temp = strSource.ToUpper();
- var position = temp.IndexOf(search);
- while (position >= 0)
- {
- result += strSource.Substring(0, position) + replace;
- strSource = strSource.Substring(position + search.Length);
- temp = temp.Substring(position + search.Length);
- position = temp.IndexOf(search);
- }
- return result + strSource;
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Populates DNNTree control with folder hiearachy
- /// </summary>
- /// <param name="objNodes">Node collection to add children to</param>
- /// <param name="strPath">Path of parent node</param>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 10/26/2004 Created
- /// [Jon Henning] 8/24/2005 Added Populate on Demand (POD) logic
- /// [cnurse] 04/24/2006 Updated to use new Secure Storage
- /// </history>
- /// -----------------------------------------------------------------------------
- private void PopulateTree(DNNTreeNodeCollection objNodes, string strPath)
- {
- var folderPath = strPath.Replace(RootFolderPath, "").Replace("\\", "/");
- var parentFolder = FolderManager.Instance.GetFolder(FolderPortalID, folderPath);
- var folders = FolderManager.Instance.GetFolders(parentFolder);
- DNNTreeNode objNode;
- //Iterate through the SubFolders
- foreach (var folder in folders)
- {
- if (FolderPermissionController.CanViewFolder((FolderInfo)folder))
- {
- objNode = AddNode((FolderInfo)folder, objNodes);
- if (DNNTree.PopulateNodesFromClient == false)
- {
- PopulateTree(objNode.TreeNodes, folder.FolderPath);
- }
- }
- }
- }
- private void SetFolder(DNNTreeNode node)
- {
- dgFileList.EditItemIndex = -1;
- if (DNNTree.IsDownLevel)
- {
- DestPath = node.Key;
- LastPath = node.Key;
- }
- ManageSecurity();
- BindFileList();
- GeneratePermissionsGrid();
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Sets up the file manager for Edit Mode
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void SetEditMode()
- {
- if (dgFileList.EditItemIndex > -1)
- {
- //In Edit Mode
- int intCount = dgFileList.Items.Count;
- CheckBox chkFile2;
- CheckBox chkFile;
- ImageButton lnkDeleteFile;
- ImageButton lnkEditFile;
- int i;
- for (i = 0; i <= intCount - 1; i++)
- {
- if (i != dgFileList.EditItemIndex)
- {
- chkFile2 = (CheckBox) dgFileList.Items[i].FindControl("chkFile2");
- chkFile = (CheckBox) dgFileList.Items[i].FindControl("chkFile");
- lnkDeleteFile = (ImageButton) dgFileList.Items[i].FindControl("lnkDeleteFile");
- lnkEditFile = (ImageButton) dgFileList.Items[i].FindControl("lnkEditFile");
- if ((chkFile2) != null)
- {
- chkFile2.Enabled = false;
- }
- if ((chkFile) != null)
- {
- chkFile.Enabled = false;
- }
- if ((lnkDeleteFile) != null)
- {
- lnkDeleteFile.Enabled = false;
- lnkDeleteFile.ImageUrl = IconController.IconURL("TrashDisabled");
- lnkDeleteFile.AlternateText = "";
- }
- if ((lnkEditFile) != null)
- {
- lnkEditFile.Enabled = false;
- lnkEditFile.ImageUrl = IconController.IconURL("EditDisabled");
- lnkEditFile.AlternateText = "";
- }
- chkFile2 = null;
- chkFile = null;
- lnkDeleteFile = null;
- lnkEditFile = null;
- }
- }
- DisabledButtons = true;
- }
- else
- {
- }
- dgFileList.Columns[0].HeaderStyle.Width = Unit.Percentage(5);
- dgFileList.Columns[1].HeaderStyle.Width = Unit.Percentage(25);
- dgFileList.Columns[2].HeaderStyle.Width = Unit.Percentage(25);
- dgFileList.Columns[3].HeaderStyle.Width = Unit.Percentage(7);
- dgFileList.Columns[4].HeaderStyle.Width = Unit.Percentage(15);
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Sets up the Error Message
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void ShowErrorMessage(string strMessage)
- {
- strMessage = strMessage.Replace("\\", "\\\\");
- strMessage = strMessage.Replace("'", "\\'");
- strMessage = strMessage.Replace(Environment.NewLine, "\\n");
- strMessage = string.Format(_ErrorMessage, strMessage);
- ClientAPI.RegisterClientVariable(Page, "ErrorMessage", strMessage, true);
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Synchronizes the complete File System
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void Synchronize()
- {
- if (IsHostMenu)
- {
- FolderManager.Instance.Synchronize(Null.NullInteger);
- }
- else
- {
- FolderManager.Instance.Synchronize(PortalId);
- }
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Unmasks the path
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private string UnMaskPath(string strOrigPath)
- {
- strOrigPath = PathUtils.Instance.AddTrailingSlash(RootFolderPath) + PathUtils.Instance.StripFolderPath(strOrigPath);
- return strOrigPath.Replace("/", "\\");
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Updates the space Used label
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- private void UpdateSpaceUsed()
- {
- string strDestFolder = PathUtils.Instance.AddTrailingSlash(UnMaskPath(DestPath));
- var objPortalController = new PortalController();
- string strUsed;
- string strQuota;
- if (PortalSettings.HostSpace == 0)
- {
- strQuota = Localization.GetString("UnlimitedSpace", LocalResourceFile);
- }
- else
- {
- strQuota = PortalSettings.HostSpace + "MB";
- }
- if (IsHostMenu)
- {
- lblFileSpace.Text = " ";
- }
- else
- {
- long spaceUsed = objPortalController.GetPortalSpaceUsedBytes(FolderPortalID);
- if (spaceUsed < 1024)
- {
- strUsed = spaceUsed.ToString("0.00") + "B";
- }
- else if (spaceUsed < (1024*1024))
- {
- strUsed = (spaceUsed/1024).ToString("0.00") + "KB";
- }
- else
- {
- strUsed = (spaceUsed/(1024*1024)).ToString("0.00") + "MB";
- }
- lblFileSpace.Text = string.Format(Localization.GetString("SpaceUsed", LocalResourceFile), strUsed, strQuota);
- }
- }
- #endregion
- #region "Protected Methods"
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// The DeleteFiles helper method is used to delete the files in the list
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <param name="strFiles">The list of files to delete</param>
- /// <history>
- /// [DYNST] 2/1/2004 Created
- /// [Jon Henning] 11/1/2004 Updated to use ClientAPI/DNNTree
- /// </history>
- /// -----------------------------------------------------------------------------
- protected void DeleteFiles(string strFiles)
- {
- var arFiles = strFiles.Split(';');
- if (arFiles.Length == 0)
- {
- return;
- }
-
- var strErrorMessage = "";
-
- var strSourcePath = Globals.GetSubFolderPath(PathUtils.Instance.AddTrailingSlash(LastPath) + arFiles[0], FolderPortalID);
- var folder = FolderManager.Instance.GetFolder(FolderPortalID, strSourcePath);
- for (var i = 0; i <= arFiles.Length - 1; i++)
- {
- if (!String.IsNullOrEmpty(arFiles[i]))
- {
- var file = Services.FileSystem.FileManager.Instance.GetFile(folder, arFiles[i]);
- try
- {
- Services.FileSystem.FileManager.Instance.DeleteFile(file);
- }
- catch (Exception ex)
- {
- DnnLog.Error(ex);
- strErrorMessage += Localization.GetString("ErrorDeletingFile", LocalResourceFile) +
- PathUtils.Instance.AddTrailingSlash(UnMaskPath(DestPath)) +
- arFiles[i] +
- "<br/> " + ex.Message + "<br/>";
- }
- }
- }
-
- if (!String.IsNullOrEmpty(strErrorMessage))
- {
- strErrorMessage = MaskString(strErrorMessage);
- ShowErrorMessage(strErrorMessage);
- }
-
- BindFileList();
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Renders the page output
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [Jon Henning] 11/1/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- protected override void Render(HtmlTextWriter output)
- {
- //mark various controls as valid for event validation
- Page.ClientScript.RegisterForEventValidation(lnkAddFolder.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkDeleteFolder.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkDeleteAllCheckedFiles.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkRefresh.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkSelectFolder.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkSyncFolder.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkFilter.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkCopy.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkUpload.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMove.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMoveFirst.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMoveLast.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMoveNext.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMovePrevious.UniqueID);
- Page.ClientScript.RegisterForEventValidation(lnkMoveFiles.UniqueID);
- if (dgFileList.Items.Count <= 10 && dgFileList.PageCount == 1)
- {
- dgFileList.PagerStyle.Visible = false;
- }
- base.Render(output);
- }
- #endregion
- #region "Public Methods"
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// The CheckDestFolderAccess helper method Checks to make sure file copy/move
- /// operation will not exceed portal available space
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [DYNST] 2/1/2004 Created
- /// [Jon Henning] 11/1/2004 Updated to use ClientAPI/DNNTree
- /// [cnurse] 12/2/2004 Updated to use Localization
- /// </history>
- /// -----------------------------------------------------------------------------
- public string CheckDestFolderAccess(long intSize)
- {
- if (Request.IsAuthenticated)
- {
- string strDestFolder = PathUtils.Instance.AddTrailingSlash(UnMaskPath(DestPath));
- var objPortalController = new PortalController();
- if (objPortalController.HasSpaceAvailable(FolderPortalID, intSize) || Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
- {
- return "";
- }
- else
- {
- return Localization.GetString("NotEnoughSpace", LocalResourceFile);
- }
- }
- else
- {
- return Localization.GetString("PleaseLogin", LocalResourceFile);
- }
- }
- /// -----------------------------------------------------------------------------
- /// <summary>
- /// Gets the Image associated with the File/Folder
- /// </summary>
- /// <remarks>
- /// </remarks>
- /// <history>
- /// [cnurse] 12/4/2004 Created
- /// </history>
- /// -----------------------------------------------------------------------------
- public string GetImageUrl(string type)
- {
- string url = "";
- try
- {
- if (type == "folder")
- {
- url = IconController.IconURL("ExtClosedFolder");
- }
- else
- {
- if (!String.IsNullOrEmpty(type) && File.Exists(Server.MapPath(IconController.IconURL("Ext" + type))))
- {
- url = IconController.IconURL("Ext" + type);
- }
- else
- {
- url = IconController.IconURL("ExtFile");
- }
- }
- }
- catch (Exception exc) //Module failed to load
- {
- Exceptions.ProcessModuleLoadException(this, exc);
- }
- return url;
- }
- #endregion
- #region "Event Handlers"
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- cmdUpdate.Click += cmdUpdate_Click;
- dgFileList.ItemDataBound += dgFileList_ItemDataBound;
- dgFileList.SortCommand += dgFileList_SortCommand;
- DNNTree.NodeClick += DNNTree_NodeClick;
- DNNTree.PopulateOnDemand += DNNTree_PopulateOnDemand;
- lnkAddFolder.Command += lnkAddFolder_Command;
- lnkDeleteFolder.Command += lnkDelet…
Large files files are truncated, but you can click here to view the full file