Exemplo n.º 1
0
        public int AddFolder(FolderInfo folder)
        {
            var tmpFolder = FolderManager.Instance.GetFolder(folder.PortalID, folder.FolderPath);

            if (tmpFolder != null && folder.FolderID == Null.NullInteger)
            {
                folder.FolderID = tmpFolder.FolderID;
            }

            if (folder.FolderID == Null.NullInteger)
            {
                folder = (FolderInfo)FolderManager.Instance.AddFolder(FolderMappingController.Instance.GetFolderMapping(folder.PortalID, folder.FolderMappingID), folder.FolderPath);
            }
            else
            {
                FolderManager.Instance.UpdateFolder(folder);
            }

            return folder.FolderID;
        }
        public void CollectData(FolderInfo folderInfo, int startIndex, int portalId)
        {
            ArrayList filesWorking = FileSystemUtils.GetFilesByFolder(portalId, folderInfo.FolderID);

            if (filesWorking != null)
            {
                foreach (DotNetNuke.Services.FileSystem.FileInfo fileInfo in filesWorking)
                {
                    ParseCSV(fileInfo, startIndex);
                }
            }
            ImportData(this.portalId);
        }
Exemplo n.º 3
0
        public int AddFolder(int PortalID, string FolderPath, int StorageLocation, bool IsProtected, bool IsCached)
        {
            var objFolder = new FolderInfo();

            objFolder.UniqueId = Guid.NewGuid();
            objFolder.VersionGuid = Guid.NewGuid();
            objFolder.PortalID = PortalID;
            objFolder.FolderPath = FolderPath;
            objFolder.StorageLocation = StorageLocation;
            objFolder.IsProtected = IsProtected;
            objFolder.IsCached = IsCached;

            return AddFolder(objFolder);
        }
Exemplo n.º 4
0
 public void UpdateFolder(FolderInfo objFolderInfo)
 {
     FolderManager.Instance.UpdateFolder(objFolderInfo);
 }
Exemplo n.º 5
0
 public static void AddAllUserReadPermission(FolderInfo folder, PermissionInfo permission)
 {
     FolderManager.Instance.AddAllUserReadPermission(folder, permission);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Render all Directories and sub directories recursive
        /// </summary>
        /// <param name="folderInfo">The folder Info.</param>
        /// <returns>
        /// TreeNode List
        /// </returns>
        private RadTreeNode RenderFolder(FolderInfo folderInfo)
        {
            if (!FolderPermissionController.CanViewFolder(folderInfo))
            {
                return null;
            }

            RadTreeNode tnFolder = new RadTreeNode
            {
                Text = folderInfo.FolderName,
                Value = folderInfo.PhysicalPath,
                ImageUrl = "Images/folder.gif",
                ExpandedImageUrl = "Images/folderOpen.gif",
                ToolTip = folderInfo.FolderID.ToString()
            };

            if (folderInfo.StorageLocation.Equals((int)FolderController.StorageLocationTypes.SecureFileSystem))
            {
                tnFolder.ImageUrl = "Images/folderLocked.gif";
                tnFolder.ExpandedImageUrl = "Images/folderOpenLocked.gif";
            }
            else if (folderInfo.StorageLocation.Equals((int)FolderController.StorageLocationTypes.DatabaseSecure))
            {
                tnFolder.ImageUrl = "Images/folderdb.gif";
                tnFolder.ExpandedImageUrl = "Images/folderdb.gif";
            }

            /*ArrayList folders = FileSystemUtils.GetFoldersByParentFolder(
                this._portalSettings.PortalId, folderInfo.FolderPath);*/

            var folders = FolderManager.Instance.GetFolders(folderInfo).ToList();

            if (folders.Any())
            {
                foreach (RadTreeNode node in
                    folders.Cast<FolderInfo>().Select(this.RenderFolder).Where(node => node != null))
                {
                    switch (this.GetStorageLocationType(Convert.ToInt32(node.ToolTip)))
                    {
                        case FolderController.StorageLocationTypes.SecureFileSystem:
                            {
                                node.ImageUrl = "Images/folderLocked.gif";
                                node.ExpandedImageUrl = "Images/folderOpenLocked.gif";
                            }

                            break;
                        case FolderController.StorageLocationTypes.DatabaseSecure:
                            {
                                node.ImageUrl = "Images/folderdb.gif";
                                node.ExpandedImageUrl = "Images/folderdb.gif";
                            }

                            break;
                    }

                    tnFolder.Nodes.Add(node);
                }
            }

            return tnFolder;
        }
 /// <summary>
 /// SaveFolderPermissions updates a Folder's permissions
 /// </summary>
 /// <param name="folder">The Folder to update</param>
 public virtual void SaveFolderPermissions(FolderInfo folder)
 {
     SaveFolderPermissions((IFolderInfo)folder);
 }
 /// <summary>
 /// Returns a flag indicating whether the current user can manage a folder's settings
 /// </summary>
 /// <param name="folder">The page</param>
 /// <returns>A flag indicating whether the user has permission</returns>
 public virtual bool CanManageFolder(FolderInfo folder)
 {
     return HasFolderPermission(folder, ManageFolderPermissionKey);
 }
        public void OverwriteFolder_Deletes_Source_Folder_In_Database()
        {
            var fileManager = new Mock<IFileManager>();
            FileManager.RegisterInstance(fileManager.Object);

            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            var files = new List<IFileInfo>();
            _mockFolderManager.Setup(mfm => mfm.GetFiles(_folderInfo.Object, It.IsAny<bool>(), It.IsAny<bool>())).Returns(files);

            var destinationFolder = new FolderInfo();

            _mockFolderManager.Setup(mfm => mfm.DeleteFolder(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath)).Verifiable();

            var folderMapping = new FolderMappingInfo();

            _mockFolderManager.Setup(mfm => mfm.GetFolderMapping(It.IsAny<Dictionary<int, FolderMappingInfo>>(), Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);
            _mockFolderManager.Setup(mfm => mfm.IsFolderMappingEditable(folderMapping)).Returns(false);

            _mockFolderManager.Object.OverwriteFolder(_folderInfo.Object, destinationFolder, new Dictionary<int, FolderMappingInfo>(), new SortedList<string, IFolderInfo>());

            _mockFolderManager.Verify();
        }
        public void OverwriteFolder_Calls_MoveFile_For_Each_File_In_Source_Folder()
        {
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            var destinationFolder = new FolderInfo();

            var file1 = new FileInfo();
            var file2 = new FileInfo();
            var file3 = new FileInfo();

            var files = new List<IFileInfo> { file1, file2, file3 };
            _mockFolderManager.Setup(mfm => mfm.GetFiles(_folderInfo.Object, It.IsAny<bool>(), It.IsAny<bool>())).Returns(files);

            var fileManager = new Mock<IFileManager>();
            FileManager.RegisterInstance(fileManager.Object);

            fileManager.Setup(fm => fm.MoveFile(It.IsAny<IFileInfo>(), destinationFolder));

            _mockFolderManager.Setup(mfm => mfm.DeleteFolder(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath));

            var folderMapping = new FolderMappingInfo();

            _mockFolderManager.Setup(mfm => mfm.GetFolderMapping(It.IsAny<Dictionary<int, FolderMappingInfo>>(), Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);
            _mockFolderManager.Setup(mfm => mfm.IsFolderMappingEditable(folderMapping)).Returns(false);

            _mockFolderManager.Object.OverwriteFolder(_folderInfo.Object, destinationFolder, new Dictionary<int, FolderMappingInfo>(), new SortedList<string, IFolderInfo>());

            fileManager.Verify(fm => fm.MoveFile(It.IsAny<IFileInfo>(), destinationFolder), Times.Exactly(3));
        }
        public void MoveFolder_Throws_When_Move_Operation_Is_Not_Valid()
        {
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            
            IFolderInfo destinationFolder = new FolderInfo();
            destinationFolder.FolderPath = Constants.FOLDER_OtherValidFolderRelativePath;
            destinationFolder.FolderMappingID = Constants.FOLDER_ValidFolderMappingID;

            _pathUtils.Setup(pu => pu.FormatFolderPath(Constants.FOLDER_OtherValidFolderRelativePath)).Returns(Constants.FOLDER_OtherValidFolderRelativePath);

            _mockFolderManager.Setup(mfm => mfm.FolderExists(It.IsAny<int>(), It.IsAny<string>())).Returns(false);
            _mockFolderManager.Setup(mfm => mfm.CanMoveBetweenFolderMappings(It.IsAny<FolderMappingInfo>(), It.IsAny<FolderMappingInfo>())).Returns(true);
            _mockFolderManager.Setup(mfm => mfm.IsMoveOperationValid(_folderInfo.Object, destinationFolder, It.IsAny<string>())).Returns(false);

            _mockFolderManager.Object.MoveFolder(_folderInfo.Object, destinationFolder);
        }
        public void MoveFolder_Returns_The_Same_Folder_If_The_Paths_Are_The_Same()
        {
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_ValidFolderRelativePath);

            IFolderInfo destinationFolder = new FolderInfo();
            destinationFolder.FolderPath = Constants.FOLDER_ValidFolderRelativePath;

            _pathUtils.Setup(pu => pu.FormatFolderPath(Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderRelativePath);

            var movedFolder = _folderManager.MoveFolder(_folderInfo.Object, destinationFolder);

            Assert.AreEqual(_folderInfo.Object, movedFolder);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Processes all Files from the template
        /// </summary>
        /// <param name="nodeFiles">Template file node for the Files</param>
        /// <param name="PortalId">PortalId of the new portal</param>
        /// <history>
        /// 	[cnurse]	11/09/2004	Created
        /// </history>
        private void ParseFiles( XmlNodeList nodeFiles, int PortalId, FolderInfo objFolder )
        {
            int FileId = 0;
            FileController objController = new FileController();
            FileInfo objInfo = null;
            string fileName = null;

            foreach( XmlNode node in nodeFiles )
            {
                fileName = XmlUtils.GetNodeValue( node, "filename", "" );

                //First check if the file exists
                objInfo = objController.GetFile( fileName, PortalId, objFolder.FolderID );

                if( objInfo == null )
                {
                    objInfo = new FileInfo();
                    objInfo.PortalId = PortalId;
                    objInfo.FileName = fileName;
                    objInfo.Extension = XmlUtils.GetNodeValue( node, "extension", "" );
                    objInfo.Size = XmlUtils.GetNodeValueInt( node, "size", 0 );
                    objInfo.Width = XmlUtils.GetNodeValueInt( node, "width", 0 );
                    objInfo.Height = XmlUtils.GetNodeValueInt( node, "height", 0 );
                    objInfo.ContentType = XmlUtils.GetNodeValue( node, "contenttype", "" );
                    objInfo.FolderId = objFolder.FolderID;
                    objInfo.Folder = objFolder.FolderPath;

                    //Save new File 
                    FileId = objController.AddFile( objInfo );
                }
                else
                {
                    //Get Id from File
                    FileId = objInfo.FileId;
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get all Files and Put them in a DataTable for the GridView
        /// </summary>
        /// <param name="currentFolderInfo">The current folder info.</param>
        /// <returns>
        /// The File Table
        /// </returns>
        public DataTable GetFiles(FolderInfo currentFolderInfo)
        {
            DataTable filesTable = new DataTable();

            filesTable.Columns.Add(new DataColumn("FileName", typeof(string)));
            filesTable.Columns.Add(new DataColumn("PictureURL", typeof(string)));
            filesTable.Columns.Add(new DataColumn("Info", typeof(string)));
            filesTable.Columns.Add(new DataColumn("FileId", typeof(int)));

            HttpRequest httpRequest = HttpContext.Current.Request;

            var type = "Link";

            if (!string.IsNullOrEmpty(httpRequest.QueryString["Type"]))
            {
                type = httpRequest.QueryString["Type"];
            }

            // Get Folder Info Secure?
            var isSecure =
                this.GetStorageLocationType(currentFolderInfo.FolderID).Equals(
                    FolderController.StorageLocationTypes.SecureFileSystem);

            var isDatabaseSecure =
                this.GetStorageLocationType(currentFolderInfo.FolderID).Equals(
                    FolderController.StorageLocationTypes.DatabaseSecure);

            var filesArrayList = FileSystemUtils.GetFilesByFolder(
                this._portalSettings.PortalId, currentFolderInfo.FolderID);

            var files = filesArrayList.OfType<DotNetNuke.Services.FileSystem.FileInfo>().ToList();

            if (this.SortFilesDescending)
            {
                Utility.SortDescending(files, item => item.FileName);
            }

            foreach (DotNetNuke.Services.FileSystem.FileInfo fileItem in files)
            {
                // Check if File Exists
                /*if (!File.Exists(string.Format("{0}{1}", fileItem.PhysicalPath, isSecure ? ".resources" : string.Empty)))
                {
                    continue;
                }*/

                var item = fileItem;

                var name = fileItem.FileName;
                var extension = fileItem.Extension;

                if (isSecure)
                {
                    name = GetFileNameCleaned(name);
                    extension = Path.GetExtension(name);
                }

                switch (type)
                {
                    case "Image":
                        {
                            // Show Images only
                            foreach (DataRow dr in
                                from sAllowExt in this.allowedImageExt
                                where name.ToLower().EndsWith(sAllowExt)
                                select filesTable.NewRow())
                            {
                                if (isSecure || isDatabaseSecure)
                                {
                                    var link = string.Format("fileID={0}", fileItem.FileId);

                                    dr["PictureURL"] = Globals.LinkClick(link, int.Parse(this.request.QueryString["tabid"]), Null.NullInteger);
                                }
                                else
                                {
                                    dr["PictureURL"] = MapUrl(fileItem.PhysicalPath);
                                }

                                dr["FileName"] = name;
                                dr["FileId"] = item.FileId;

                                dr["Info"] =
                                    string.Format(
                                        "<span class=\"FileName\">{0}</span><br /><span class=\"FileInfo\">Size: {1}</span>",
                                        name,
                                        fileItem.Size);

                                filesTable.Rows.Add(dr);
                            }
                        }

                        break;
                    case "Flash":
                        {
                            // Show Flash Files only
                            foreach (DataRow dr in
                                from sAllowExt in this.allowedFlashExt
                                where name.ToLower().EndsWith(sAllowExt)
                                select filesTable.NewRow())
                            {
                                dr["PictureURL"] = "images/types/swf.png";

                                dr["FileName"] = name;
                                dr["FileId"] = item.FileId;

                                dr["Info"] =
                                    string.Format(
                                        "<span class=\"FileName\">{0}</span><br /><span class=\"FileInfo\">Size: {1}</span>",
                                        name,
                                        fileItem.Size);

                                filesTable.Rows.Add(dr);
                            }
                        }

                        break;
                    default:
                        {
                            // Show all allowed File types
                            if (extension.StartsWith("."))
                            {
                                extension = extension.Replace(".", string.Empty);
                            }

                            if (extension.Count() <= 1 || !this.extensionWhiteList.Contains(extension.ToLower()))
                            {
                                continue;
                            }

                            DataRow dr = filesTable.NewRow();

                            var imageExtension = string.Format("images/types/{0}.png", extension);

                            if (File.Exists(this.MapPath(imageExtension)))
                            {
                                dr["PictureURL"] = imageExtension;
                            }
                            else
                            {
                                dr["PictureURL"] = "images/types/unknown.png";
                            }

                            if (this.allowedImageExt.Any(sAllowImgExt => name.ToLower().EndsWith(sAllowImgExt)))
                            {
                                if (isSecure || isDatabaseSecure)
                                {
                                    var link = string.Format("fileID={0}", fileItem.FileId);

                                    dr["PictureURL"] = Globals.LinkClick(link, int.Parse(this.request.QueryString["tabid"]), Null.NullInteger);
                                }
                                else
                                {
                                    dr["PictureURL"] = MapUrl(fileItem.PhysicalPath);
                                }
                            }

                            dr["FileName"] = name;
                            dr["FileId"] = fileItem.FileId;

                            dr["Info"] =
                                string.Format(
                                    "<span class=\"FileName\">{0}</span><br /><span class=\"FileInfo\">Size: {1}</span>",
                                    name,
                                    fileItem.Size);

                            filesTable.Rows.Add(dr);
                        }

                        break;
                }
            }

            return filesTable;
        }
Exemplo n.º 15
0
        private static void RemoveOrphanedFiles( FolderInfo folder, int PortalId )
        {
            FileController objFileController = new FileController();

            if( folder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure )
            {
                foreach( Services.FileSystem.FileInfo objFile in GetFilesByFolder( PortalId, folder.FolderID ) )
                {
                    RemoveOrphanedFile( objFile, PortalId );
                }
            }
        }
		private bool CheckAllChildrenVisible(ref FolderInfo folder)
		{
			string virtualPath = FileSystemValidation.ToVirtualPath(folder.FolderPath);

			//check files are visible
			var files = GetDNNFiles(folder.FolderID);
			var visibleFileCount = 0;
			foreach (Services.FileSystem.FileInfo fileItem in files.Values)
			{
                if (CheckSearchPatterns(fileItem.FileName, SearchPatterns))
				{
					visibleFileCount = visibleFileCount + 1;
				}
			}

			if (visibleFileCount != Directory.GetFiles(HttpContext.Current.Request.MapPath(virtualPath)).Length)
			{
				return false;
			}

			//check folders
			if (folder != null)
			{
				IDictionary<string, FolderInfo> childUserFolders = DNNValidator.GetChildUserFolders(virtualPath);

				if (childUserFolders.Count != Directory.GetDirectories(HttpContext.Current.Request.MapPath(virtualPath)).Length)
				{
					return false;
				}

				//check children
				foreach (FolderInfo childFolder in childUserFolders.Values)
				{
					//do recursive check
					FolderInfo tempVar2 = childFolder;
					if (! (CheckAllChildrenVisible(ref tempVar2)))
					{
						return false;
					}
				}
			}

			return true;
		}
Exemplo n.º 17
0
 /// <summary>
 /// Returns a flag indicating whether the current user can delete a folder or file
 /// </summary>
 /// <param name="folder">The page</param>
 /// <returns>A flag indicating whether the user has permission</returns>
 public virtual bool CanDeleteFolder(FolderInfo folder)
 {
     return HasFolderPermission(folder, DeleteFolderPermissionKey);
 }
        public void OverwriteFolder_Adds_Folder_To_FoldersToDelete_If_FolderMapping_Is_Editable()
        {
            var fileManager = new Mock<IFileManager>();
            FileManager.RegisterInstance(fileManager.Object);

            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            var files = new List<IFileInfo>();
            _mockFolderManager.Setup(mfm => mfm.GetFiles(_folderInfo.Object, It.IsAny<bool>(), It.IsAny<bool>())).Returns(files);

            var destinationFolder = new FolderInfo();

            _mockFolderManager.Setup(mfm => mfm.DeleteFolder(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath));

            var folderMapping = new FolderMappingInfo();

            _mockFolderManager.Setup(mfm => mfm.GetFolderMapping(It.IsAny<Dictionary<int, FolderMappingInfo>>(), Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);
            _mockFolderManager.Setup(mfm => mfm.IsFolderMappingEditable(folderMapping)).Returns(true);

            var foldersToDelete = new SortedList<string, IFolderInfo>();
            _mockFolderManager.Object.OverwriteFolder(_folderInfo.Object, destinationFolder, new Dictionary<int, FolderMappingInfo>(), foldersToDelete);

            Assert.AreEqual(1, foldersToDelete.Count);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Returns a flag indicating whether the current user can view a folder or file
 /// </summary>
 /// <param name="folder">The page</param>
 /// <returns>A flag indicating whether the user has permission</returns>
 public virtual bool CanViewFolder(FolderInfo folder)
 {
     return HasFolderPermission(folder, ViewFolderPermissionKey);
 }
        public void GetFolder_Returns_Valid_Folder_When_Folder_Exists_Overload()
        {
            _pathUtils.Setup(pu => pu.FormatFolderPath(Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _pathUtils.Setup(pu => pu.RemoveTrailingSlash(Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderName);

            var folderDataTable = new DataTable();
            folderDataTable.Columns.Add("FolderName");
            folderDataTable.Rows.Add(Constants.FOLDER_ValidFolderName);

            var dr = folderDataTable.CreateDataReader();

            _mockData.Setup(md => md.GetFolder(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath)).Returns(dr);

            var folderInfo = new FolderInfo { FolderPath = Constants.FOLDER_ValidFolderRelativePath };

            _cbo.Setup(cbo => cbo.FillObject<FolderInfo>(dr)).Returns(folderInfo);

            _mockFolderManager.Setup(mfm => mfm.GetFolders(Constants.CONTENT_ValidPortalId)).Returns(new List<IFolderInfo>());

            var result = _mockFolderManager.Object.GetFolder(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath);

            Assert.AreEqual(Constants.FOLDER_ValidFolderName, result.FolderName);
        }
Exemplo n.º 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["Folder"] != null)
            {
                //DNN upload when provided with a GUID of the folder ID being used
                DotNetNuke.Services.FileSystem.FolderInfo FI = new DotNetNuke.Services.FileSystem.FolderInfo();

                string folder = Request.QueryString["Folder"].ToString();

                if (!String.IsNullOrEmpty(folder))
                {
                    FI = (DotNetNuke.Services.FileSystem.FolderInfo)FolderManager.Instance.GetFolder(Guid.Parse(folder));
                    FileManager.Instance.AddFile(FI, Request.Files[0].FileName, Request.Files[0].InputStream);
                    Response.Write("{\"success\":true}");
                }
                else
                {
                    Response.Write("{\"error\":\"" + "string fileName: cannot be empty or null" + "\"}");
                }
            }
            else if (Request.QueryString["FilePath"] != null)
            {
                //Uses standard asp file upload
                string filePath = null;
                byte[] rawFile  = null;

                using (BinaryReader binaryReader = new BinaryReader(Request.Files[0].InputStream))
                {
                    rawFile  = binaryReader.ReadBytes(Request.Files[0].ContentLength);
                    filePath = Request.Files[0].FileName.ToLower();
                }

                //Check if the folder exists, and if it doesn't create it
                string folder = Request.QueryString["FilePath"].ToString();
                if (Directory.Exists(Server.MapPath(folder)) == false)
                {
                    Directory.CreateDirectory(Server.MapPath(folder));
                }

                string msAddOn  = DateTime.Now.Millisecond.ToString();
                string fileName = Path.GetFileNameWithoutExtension(filePath) + "_" + msAddOn + Path.GetExtension(filePath);

                if (!String.IsNullOrEmpty(fileName))
                {
                    //Checks if it is an image or not
                    if (folder.ToLower().Contains("/photos/"))
                    {
                        //Get Format
                        ImageFormat MyFormat = ImageFormat.Jpeg;
                        if (fileName.EndsWith(".png"))
                        {
                            MyFormat = ImageFormat.Png;
                        }
                        else if (fileName.EndsWith(".bmp"))
                        {
                            MyFormat = ImageFormat.Bmp;
                        }

                        //Resize image and create a thumbnail for it
                        System.Drawing.Image rawFileImage      = ByteArrayToImage(rawFile);                                                      //Convert rawFile Byte array to Image to process Image Resize
                        System.Drawing.Image rawThumbFileImage = ByteArrayToImage(rawFile);
                        ResizeImage((Bitmap)rawFileImage, 900, 900, fileName).Save(Server.MapPath(folder + fileName), MyFormat);                 //regular
                        ResizeImage((Bitmap)rawThumbFileImage, 200, 200, fileName).Save(Server.MapPath(folder + "thumb_" + fileName), MyFormat); //thumbnail
                    }
                    else if (folder.ToLower().Contains("/videos/"))
                    {
                        //if it's the poster
                        if (fileName.EndsWith(".png") || fileName.EndsWith(".jpg"))
                        {
                            System.Drawing.Image rawFileImage = ByteArrayToImage(rawFile);
                            ResizeImage((Bitmap)rawFileImage, 900, 900, fileName).Save(Server.MapPath(folder + fileName), ImageFormat.Jpeg);
                        }
                        else
                        {
                            //if it's the video
                            File.WriteAllBytes(Server.MapPath(folder + fileName), rawFile);
                        }
                    }
                    else if (folder.ToLower().Contains("/slides/"))
                    {
                        System.Drawing.Image rawFileImage = ByteArrayToImage(rawFile);
                        ResizeImage((Bitmap)rawFileImage, 900, 900, fileName).Save(Server.MapPath(folder + fileName), ImageFormat.Jpeg);
                    }
                    else
                    {
                        File.WriteAllBytes(Server.MapPath(folder + fileName), rawFile);
                    }
                    Response.Write("{\"success\":true, \"msAddOn\":" + msAddOn + "}");
                    //syncs files right away so they can be viewed in the html editor.
                    int    PID      = DotNetNuke.Entities.Portals.PortalController.Instance.GetCurrentPortalSettings().PortalId;
                    string syncpath = Server.MapPath(folder);
                    //syncs the folder the file was added to.
                    DotNetNuke.Services.FileSystem.FolderManager.Instance.Synchronize(PID, syncpath, true, true);
                    //syncs the whole portal.
                    DotNetNuke.Services.FileSystem.FolderManager.Instance.Synchronize(PID);
                }
                else
                {
                    Response.Write("{\"errors\":\"" + "string fileName: cannot be empty or null" + "\"}");
                }
            }
        }
        catch (Exception ex)
        {
            Exceptions.LogException(ex);
            Response.Write("{\"error\":\"" + ex.Message + "\"}");
        }
    }
Exemplo n.º 22
0
        private static void AddFolderAndMoveFiles(string folderPath, string newFolderPath, FolderMappingInfo folderMapping)
        {
            var folderProvider = Instance(folderMapping.FolderProviderType);

            if (!folderProvider.FolderExists(newFolderPath, folderMapping))
            {
                folderProvider.AddFolder(newFolderPath, folderMapping);
            }

            var folder = new FolderInfo { FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };
            var newFolder = new FolderInfo { FolderPath = newFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };

            MoveFiles(folder, newFolder, folderMapping);
        }
Exemplo n.º 23
0
 private static void RemoveOrphanedFiles(FolderInfo folder, int PortalId)
 {
     if (folder.FolderMappingID != FolderMappingController.Instance.GetFolderMapping(PortalId, "Database").FolderMappingID)
     {
         foreach (FileInfo objFile in FolderManager.Instance.GetFiles(folder))
         {
             RemoveOrphanedFile(objFile, PortalId);
         }
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Copies the specified file to the destination folder.
        /// </summary>
        public virtual void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.NotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath) return;

            var sourceFolder = new FolderInfo { FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };
            var destinationFolder = new FolderInfo { FolderPath = newFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };

            using (var fileContent = GetFileStream(sourceFolder, fileName))
            {
                if (!fileContent.CanSeek)
                {
                    using (var seekableStream = FileManager.Instance.GetSeekableStream(fileContent))
                    {
                        AddFile(destinationFolder, fileName, seekableStream);
                    }
                }
                else
                {
                    AddFile(destinationFolder, fileName, fileContent);
                }
            }
        }
Exemplo n.º 25
0
        public static string AddFile(string strFile, int PortalId, bool ClearCache, FolderInfo folder)
        {
            var fileManager = FileManager.Instance;

            var fileName = GetFileName(strFile);

            var file = (FileInfo)fileManager.GetFile(folder, fileName);
            
            if (file == null)
            {
                file = new FileInfo { PortalId = PortalId, FolderId = folder.FolderID, FileName = fileName };
                using (var fileContent = fileManager.GetFileContent(file))
                {
                    fileManager.AddFile(folder, GetFileName(strFile), fileContent, false);
                }
            }
            else
            {
                using (var fileContent = fileManager.GetFileContent(file))
                {
                    fileManager.UpdateFile(file, fileContent);
                }
            }

            return "";
        }
Exemplo n.º 26
0
        /// -----------------------------------------------------------------------------
        /// <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;
        }
Exemplo n.º 27
0
        public int AddFolder(int PortalID, string FolderPath)
        {
            var objFolder = new FolderInfo();

            objFolder.UniqueId = Guid.NewGuid();
            objFolder.VersionGuid = Guid.NewGuid();
            objFolder.PortalID = PortalID;
            objFolder.FolderPath = FolderPath;
            objFolder.StorageLocation = (int) StorageLocationTypes.InsecureFileSystem;
            objFolder.IsProtected = false;
            objFolder.IsCached = false;

            return AddFolder(objFolder);
        }
Exemplo n.º 28
0
 private bool HasFolderPermission(FolderInfo folder, string permissionKey)
 {
     if (folder == null) return false;
     return (PortalSecurity.IsInRoles(folder.FolderPermissions.ToString(permissionKey))
             || PortalSecurity.IsInRoles(folder.FolderPermissions.ToString(AdminFolderPermissionKey)))
            && !PortalSecurity.IsDenied(folder.FolderPermissions.ToString(permissionKey));
     //Deny on Edit permission on folder shouldn't take away any other explicitly Allowed
     //&& !PortalSecurity.IsDenied(folder.FolderPermissions.ToString(AdminFolderPermissionKey));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Returns a flag indicating whether the current user can browse the folder
 /// </summary>
 /// <param name="folder">The page</param>
 /// <returns>A flag indicating whether the user has permission</returns>
 public virtual bool CanBrowseFolder(FolderInfo folder)
 {
     if (folder == null) return false;
     return (PortalSecurity.IsInRoles(folder.FolderPermissions.ToString(BrowseFolderPermissionKey))
         || PortalSecurity.IsInRoles(folder.FolderPermissions.ToString(ViewFolderPermissionKey)))
         && !PortalSecurity.IsDenied(folder.FolderPermissions.ToString(BrowseFolderPermissionKey));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Returns a flag indicating whether the current user can addmister a folder
 /// </summary>
 /// <param name="folder">The page</param>
 /// <returns>A flag indicating whether the user has permission</returns>
 public virtual bool CanAdminFolder(FolderInfo folder)
 {
     if (folder == null) return false;
     return PortalSecurity.IsInRoles(folder.FolderPermissions.ToString(AdminFolderPermissionKey));
 }
 public void StageData(ArrayList files, FolderInfo folderInfo)
 {
     FileController fc = new FileController();
     if (folderInfo != null && files != null)
     {
         foreach (DotNetNuke.Services.FileSystem.FileInfo fileInfo in files)
         {
             if (File.Exists(fileInfo.PhysicalPath))
             {
                 File.Move(fileInfo.PhysicalPath, folderInfo.PhysicalPath + fileInfo.FileName);
                 fc.UpdateFile(fileInfo.FileId, fileInfo.FileName, fileInfo.Extension.Substring(1), fileInfo.Size, Null.NullInteger, Null.NullInteger, fileInfo.ContentType, folderInfo.PhysicalPath, folderInfo.FolderID);
             }
         }
     }
 }
Exemplo n.º 32
0
 public void UpdateFolder(FolderInfo objFolderInfo)
 {
     FolderManager.Instance.UpdateFolder(objFolderInfo);
 }