public int ConvertFilePathToFileId(string FilePath, int PortalID) { string FileName = ""; string FolderName = ""; int FileId = -1; if (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); if (objFolder != null) { FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID); if (objFile != null) { FileId = objFile.FileId; } } return(FileId); }
public void DeleteFile(int PortalId, string FileName, string FolderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); DeleteFile(PortalId, FileName, objFolder.FolderID, true); }
public void DeleteFile(int PortalId, string FileName, string FolderPath, bool ClearCache) { FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath); DeleteFile(PortalId, FileName, objFolder.FolderID, ClearCache); }
public int AddFile(int PortalId, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string FolderPath, bool ClearCache) { FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath); return(AddFile(PortalId, FileName, Extension, Size, Width, Height, ContentType, FolderPath, objFolder.FolderID, ClearCache)); }
public int ConvertFilePathToFileId(string FilePath, int PortalID) { string FileName = ""; string FolderName = ""; int FileId = -1; if (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); if (objFolder != null) { FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID); if (objFile != null) { FileId = objFile.FileId; } } return FileId; }
public int AddFile(FileInfo file, string folderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(file.PortalId, folderPath, false); file.FolderId = objFolder.FolderID; file.Folder = folderPath; return(AddFile(file)); }
public IDataReader GetFiles(int PortalId, string FolderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); if (objFolder == null) { return(null); } return(GetFiles(PortalId, objFolder.FolderID)); }
public void UpdateFile(int PortalId, string OriginalFileName, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string SourceFolder, string DestinationFolder, bool ClearCache) { FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, DestinationFolder); FileInfo objFile = GetFile(OriginalFileName, PortalId, objFolder.FolderID); if (objFile != null) { UpdateFile(objFile.FileId, FileName, Extension, Size, Width, Height, ContentType, DestinationFolder, objFolder.FolderID); } }
public ArrayList GetFilesByFolder(int portalId, string folderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, folderPath, false); if (objFolder == null) { return(null); } return(CBO.FillCollection(GetFiles(portalId, objFolder.FolderID), typeof(FileInfo))); }
public FileInfo GetFile(string FileName, int PortalId, string FolderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); if (objFolder == null) { return(null); } else { return(GetFile(FileName, PortalId, objFolder.FolderID)); } }
public FileInfo GetFile(string FilePath, int PortalId) { var objFolders = new FolderController(); string FileName = Path.GetFileName(FilePath); FolderInfo objFolder = objFolders.GetFolder(PortalId, FilePath.Replace(FileName, ""), false); if (objFolder == null) { return(null); } else { return(GetFile(FileName, PortalId, objFolder.FolderID)); } }
public void UpdateFile(int PortalId, string OriginalFileName, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string SourceFolder, string DestinationFolder, bool ClearCache) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, DestinationFolder, false); FileInfo objFile = GetFile(OriginalFileName, PortalId, objFolder.FolderID); objFile.FileName = FileName; objFile.Extension = Extension; objFile.Size = Convert.ToInt32(Size); objFile.Width = Width; objFile.Height = Height; objFile.ContentType = ContentType; objFile.Folder = DestinationFolder; if ((objFile != null)) { UpdateFile(objFile); } }
public int AddFile(int portalId, string fileName, string extension, long size, int width, int height, string ContentType, string FolderPath, bool ClearCache) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, FolderPath, false); var objFile = new FileInfo(); objFile.UniqueId = Guid.NewGuid(); objFile.VersionGuid = Guid.NewGuid(); objFile.PortalId = portalId; objFile.FileName = fileName; objFile.Extension = extension; objFile.Size = Convert.ToInt32(size); objFile.Width = width; objFile.Height = height; objFile.ContentType = ContentType; objFile.Folder = FileSystemUtils.FormatFolderPath(FolderPath); objFile.FolderId = objFolder.FolderID; objFile.IsCached = ClearCache; return(AddFile(objFile)); }
public static void AddFile(string strFileName, string strExtension, string FolderPath, string strContentType, int Length, int imageWidth, int imageHeight) { #pragma warning disable 612,618 // Obtain PortalSettings from Current Context PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings(); int PortalId = FileSystemUtils.GetFolderPortalId(_portalSettings); var objFiles = new FileController(); var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); if ((objFolder != null)) { var objFile = new FileInfo(PortalId, strFileName, strExtension, Length, imageWidth, imageHeight, strContentType, FolderPath, objFolder.FolderID, objFolder.StorageLocation, true); objFiles.AddFile(objFile); } #pragma warning restore 612,618 }
/// <summary> /// Updates a File /// </summary> /// <param name="strSourceFile">The original File Name</param> /// <param name="strDestFile">The new File Name</param> /// <param name="PortalId"></param> /// <param name="isCopy">Flag determines whether file is to be be moved or copied</param> /// <param name="ClearCache"></param> 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 = ""; try { FolderController objFolderController = new FolderController(); FileController objFileController = new FileController(); string sourceFolderName = Globals.GetSubFolderPath( strSourceFile ); string sourceFileName = GetFileName( strSourceFile ); FolderInfo sourceFolder = objFolderController.GetFolder( PortalId, sourceFolderName ); string destFileName = GetFileName( strDestFile ); string destFolderName = Globals.GetSubFolderPath( strDestFile ); if( sourceFolder != null ) { Services.FileSystem.FileInfo file = objFileController.GetFile( sourceFileName, PortalId, sourceFolder.FolderID ); if( file != null ) { //Get the source Content from wherever it is Stream sourceStream = GetFileStream( file ); if( isCopy ) { //Add the new File AddFile( PortalId, sourceStream, strDestFile, "", file.Size, destFolderName, true, ClearCache ); } else { //Move/Update existing file FolderInfo destinationFolder = objFolderController.GetFolder( PortalId, destFolderName ); //Now move the file if( destinationFolder != null ) { objFileController.UpdateFile( file.FileId, destFileName, file.Extension, file.Size, file.Width, file.Height, file.ContentType, destFolderName, destinationFolder.FolderID ); //Write the content to the Destination WriteStream( file.FileId, sourceStream, strDestFile, destinationFolder.StorageLocation, true ); //Now we need to clean up the original files if( sourceFolder.StorageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { //try and delete the Insecure file AttemptFileDeletion( strSourceFile ); } if( sourceFolder.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem ) { //try and delete the Secure file AttemptFileDeletion( strSourceFile + Globals.glbProtectedExtension ); } } } } } } catch( Exception ex ) { retValue = ex.Message; } return retValue; }
public static void AddFile(string strFileName, string strExtension, string FolderPath, string strContentType, int Length, int imageWidth, int imageHeight) { // Obtain PortalSettings from Current Context PortalSettings portalSettings = PortalController.GetCurrentPortalSettings(); int portalId = IsHostTab(portalSettings.ActiveTab.TabID) ? Null.NullInteger : portalSettings.PortalId; var objFiles = new FileController(); var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, FolderPath, false); if ((objFolder != null)) { var objFile = new FileInfo(portalId, strFileName, strExtension, Length, imageWidth, imageHeight, strContentType, FolderPath, objFolder.FolderID, objFolder.StorageLocation, true); objFiles.AddFile(objFile); } }
/// <summary> /// Processes all Folders from the template /// </summary> /// <param name="nodeFolders">Template file node for the Folders</param> /// <param name="PortalId">PortalId of the new portal</param> /// <history> /// [cnurse] 11/09/2004 Created /// </history> private void ParseFolders( XmlNode nodeFolders, int PortalId ) { int FolderId = 0; FolderController objController = new FolderController(); FolderInfo objInfo = null; string folderPath = null; int storageLocation = 0; bool isProtected = false; foreach( XmlNode node in nodeFolders.SelectNodes( "//folder" ) ) { folderPath = XmlUtils.GetNodeValue( node, "folderpath", "" ); //First check if the folder exists objInfo = objController.GetFolder( PortalId, folderPath ); if( objInfo == null ) { isProtected = FileSystemUtils.DefaultProtectedFolders( folderPath ); if( isProtected == true ) { // protected folders must use insecure storage storageLocation = (int)FolderController.StorageLocationTypes.InsecureFileSystem; } else { storageLocation = Convert.ToInt32( XmlUtils.GetNodeValue( node, "storagelocation", "0" ) ); isProtected = Convert.ToBoolean( XmlUtils.GetNodeValue( node, "isprotected", "0" ) ); } //Save new folder FolderId = objController.AddFolder( PortalId, folderPath, storageLocation, isProtected, false ); objInfo = objController.GetFolder( PortalId, folderPath ); } else { //Get Id from Folder FolderId = objInfo.FolderID; } XmlNodeList nodeFolderPermissions = node.SelectNodes( "folderpermissions/permission" ); ParseFolderPermissions( nodeFolderPermissions, PortalId, FolderId, folderPath ); XmlNodeList nodeFiles = node.SelectNodes( "files/file" ); if( folderPath != "" ) { folderPath += "/"; } ParseFiles( nodeFiles, PortalId, objInfo ); } }
public int AddFile(int PortalId, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string FolderPath, bool ClearCache) { FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath); return AddFile(PortalId, FileName, Extension, Size, Width, Height, ContentType, FolderPath, objFolder.FolderID, ClearCache); }
public IDataReader GetFiles(int PortalId, string FolderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); if (objFolder == null) { return null; } return GetFiles(PortalId, objFolder.FolderID); }
public FileInfo GetFile(string FileName, int PortalId, string FolderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false); if (objFolder == null) { return null; } else { return GetFile(FileName, PortalId, objFolder.FolderID); } }
public FileInfo GetFile(string FilePath, int PortalId) { var objFolders = new FolderController(); string FileName = Path.GetFileName(FilePath); FolderInfo objFolder = objFolders.GetFolder(PortalId, FilePath.Replace(FileName, ""), false); if (objFolder == null) { return null; } else { return GetFile(FileName, PortalId, objFolder.FolderID); } }
public int AddFile(int portalId, string fileName, string extension, long size, int width, int height, string ContentType, string FolderPath, bool ClearCache) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, FolderPath, false); var objFile = new FileInfo(); objFile.UniqueId = Guid.NewGuid(); objFile.VersionGuid = Guid.NewGuid(); objFile.PortalId = portalId; objFile.FileName = fileName; objFile.Extension = extension; objFile.Size = Convert.ToInt32(size); objFile.Width = width; objFile.Height = height; objFile.ContentType = ContentType; objFile.Folder = FileSystemUtils.FormatFolderPath(FolderPath); objFile.FolderId = objFolder.FolderID; objFile.IsCached = ClearCache; return AddFile(objFile); }
public int AddFile(FileInfo file, string folderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(file.PortalId, folderPath, false); file.FolderId = objFolder.FolderID; file.Folder = folderPath; return AddFile(file); }
private void CheckUserFolderExist_Local() { FolderController ctlFolder = new FolderController(); //Create root folder if (!Directory.Exists(PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix )) { // 创建根目录,注意此处用filesystemutils来创建,这样可以设置缺省的文件夹权限 FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath, Local_FolderRootPrefix, 0); // Directory.CreateDirectory(PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix); } if (ctlFolder.GetFolder(PortalSettings.PortalId, Local_FolderRootPrefix + "/", true)==null)//检查该folder是否存在数据库中, { ctlFolder.AddFolder(PortalSettings.PortalId, Local_FolderRootPrefix + "/");//不存在则添加 } //Check user root folder if (!Directory.Exists(Local_UserFolderPath_Physical)) { // 创建用户根目录,注意此处用filesystemutils来创建,这样可以设置缺省的文件夹权限 FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix, CurrentUserId.ToString(), 0); // Directory.CreateDirectory(Local_UserFolderPath_Physical); } if (ctlFolder.GetFolder(PortalSettings.PortalId, Local_UserFolderPath_Relative, true) == null) { ctlFolder.AddFolder(PortalSettings.PortalId, Local_UserFolderPath_Relative);//不存在则添加 } }
/// <summary> /// Processess a template file for the new portal. This method will be called twice: for the portal template and for the admin template /// </summary> /// <param name="PortalId">PortalId of the new portal</param> /// <param name="TemplatePath">Path for the folder where templates are stored</param> /// <param name="TemplateFile">Template file to process</param> /// <param name="AdministratorId">UserId for the portal administrator. This is used to assign roles to this user</param> /// <param name="mergeTabs">Flag to determine whether Module content is merged.</param> /// <param name="IsNewPortal">Flag to determine is the template is applied to an existing portal or a new one.</param> /// <remarks> /// The roles and settings nodes will only be processed on the portal template file. /// </remarks> /// <history> /// [VMasanas] 27/08/2004 Created /// </history> public void ParseTemplate( int PortalId, string TemplatePath, string TemplateFile, int AdministratorId, PortalTemplateModuleAction mergeTabs, bool IsNewPortal ) { XmlDocument xmlDoc = new XmlDocument(); XmlNode node = null; int AdministratorRoleId = -1; int RegisteredRoleId = -1; int SubscriberRoleId = -1; RoleController objrole = new RoleController(); bool isAdminTemplate = false; isAdminTemplate = ( TemplateFile == "admin.template" ); // open the XML file try { xmlDoc.Load( TemplatePath + TemplateFile ); } catch // error { // } // settings, roles, folders and files can only be specified in portal templates, will be ignored on the admin template if( !isAdminTemplate ) { // parse roles if available node = xmlDoc.SelectSingleNode( "//portal/roles" ); if( node != null ) { ParseRoles( node, PortalId, AdministratorId, ref AdministratorRoleId, ref RegisteredRoleId, ref SubscriberRoleId ); } // create required roles if not already created if( AdministratorRoleId == -1 ) { AdministratorRoleId = CreateRole( PortalId, "Administrators", "Portal Administrators", 0F, 0, "M", 0F, 0, "N", false, false ); } if( RegisteredRoleId == -1 ) { RegisteredRoleId = CreateRole( PortalId, "Registered Users", "Registered Users", 0F, 0, "M", 0F, 0, "N", false, true ); } if( SubscriberRoleId == -1 ) { SubscriberRoleId = CreateRole( PortalId, "Subscribers", "A public role for portal subscriptions", 0F, 0, "M", 0F, 0, "N", true, true ); } objrole.AddUserRole( PortalId, AdministratorId, AdministratorRoleId, Null.NullDate, Null.NullDate ); objrole.AddUserRole( PortalId, AdministratorId, RegisteredRoleId, Null.NullDate, Null.NullDate ); objrole.AddUserRole( PortalId, AdministratorId, SubscriberRoleId, Null.NullDate, Null.NullDate ); // parse portal folders node = xmlDoc.SelectSingleNode( "//portal/folders" ); if( node != null ) { ParseFolders( node, PortalId ); } // force creation of root folder if not present on template FolderController objController = new FolderController(); if( objController.GetFolder( PortalId, "" ) == null ) { int folderid = objController.AddFolder( PortalId, "", (int)FolderController.StorageLocationTypes.InsecureFileSystem, true, false ); PermissionController objPermissionController = new PermissionController(); ArrayList arr = objPermissionController.GetPermissionByCodeAndKey( "SYSTEM_FOLDER", "" ); foreach( PermissionInfo objpermission in arr ) { FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, AdministratorRoleId, "" ); if( objpermission.PermissionKey == "READ" ) { // add READ permissions to the All Users Role FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, int.Parse( Globals.glbRoleAllUsers ), "" ); } } } // parse portal settings if available only for new portals node = xmlDoc.SelectSingleNode( "//portal/settings" ); if( node != null & IsNewPortal ) { ParsePortalSettings( node, PortalId ); } // update portal setup PortalInfo objportal = null; objportal = GetPortal( PortalId ); UpdatePortalSetup( PortalId, AdministratorId, AdministratorRoleId, RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId ); //Remove Exising Tabs if doing a "Replace" if( mergeTabs == PortalTemplateModuleAction.Replace ) { TabController objTabs = new TabController(); TabInfo objTab = null; foreach( KeyValuePair<int, TabInfo> tabPair in objTabs.GetTabsByPortal( PortalId ) ) { objTab = tabPair.Value; if( !objTab.IsAdminTab ) { //soft delete Tab objTab.TabName = objTab.TabName + "_old"; objTab.IsDeleted = true; objTabs.UpdateTab( objTab ); //Delete all Modules ModuleController objModules = new ModuleController(); ModuleInfo objModule = null; foreach( KeyValuePair<int, ModuleInfo> modulePair in objModules.GetTabModules( objTab.TabID ) ) { objModule = modulePair.Value; objModules.DeleteTabModule( objModule.TabID, objModule.ModuleID ); } } } } } // parse portal tabs node = xmlDoc.SelectSingleNode( "//portal/tabs" ); if( node != null ) { ParseTabs( node, PortalId, isAdminTemplate, mergeTabs, IsNewPortal ); } }
/// <summary> /// Serializes all Files /// </summary> /// <param name="xmlTemplate">Reference to XmlDocument context</param> /// <param name="nodeFiles">Node to add the serialized objects</param> /// <param name="objportal">Portal to serialize</param> /// <param name="folderPath">The folder containing the files</param> /// <param name="zipFile"></param> /// <remarks> /// The serialization uses the xml attributes defined in FileInfo class. /// </remarks> /// <history> /// [cnurse] 11/08/2004 Created /// [cnurse] 05/20/2004 Extracted adding of file to zip to new FileSystemUtils method /// </history> public void SerializeFiles(XmlDocument xmlTemplate, XmlNode nodeFiles, PortalInfo objportal, string folderPath, ref ZipOutputStream zipFile) { FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder( objportal.PortalID, folderPath ); ArrayList arrFiles = FileSystemUtils.GetFilesByFolder(objportal.PortalID, objFolder.FolderID); XmlSerializer xser = new XmlSerializer(typeof(FileInfo)); foreach (FileInfo objFile in arrFiles) { // verify that the file exists on the file system string filePath = objportal.HomeDirectoryMapPath + folderPath + objFile.FileName; if (File.Exists(filePath)) { StringWriter sw = new StringWriter(); xser.Serialize(sw, objFile); //Add node to template XmlDocument xmlFile = new XmlDocument(); xmlFile.LoadXml(sw.GetStringBuilder().ToString()); XmlNode nodeFile = xmlFile.SelectSingleNode("file"); nodeFile.Attributes.Remove(nodeFile.Attributes["xmlns:xsd"]); nodeFile.Attributes.Remove(nodeFile.Attributes["xmlns:xsi"]); nodeFiles.AppendChild(xmlTemplate.ImportNode(nodeFile, true)); FileSystemUtils.AddToZip(ref zipFile, filePath, objFile.FileName, folderPath); } } }
private string ExportModule( int ModuleID, string FileName ) { string strMessage = ""; ModuleController objModules = new ModuleController(); ModuleInfo objModule = objModules.GetModule( ModuleID, TabId, false ); if (objModule != null) { if (objModule.BusinessControllerClass != "" & objModule.IsPortable) { try { object objObject = Reflection.CreateObject(objModule.BusinessControllerClass, objModule.BusinessControllerClass); //Double-check if (objObject is IPortable) { string Content = Convert.ToString(((IPortable)objObject).ExportModule(ModuleID)); if (Content != "") { // add attributes to XML document Content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(objModule.FriendlyName) + "\" version=\"" + objModule.Version + "\">" + Content + "</content>"; //First check the Portal limits will not be exceeded (this is approximate) PortalController objPortalController = new PortalController(); string strFile = PortalSettings.HomeDirectoryMapPath + FileName; if (objPortalController.HasSpaceAvailable(PortalId, Content.Length)) { // save the file StreamWriter objStream = File.CreateText(strFile); objStream.WriteLine(Content); objStream.Close(); // add file to Files table FileController objFiles = new FileController(); FileInfo finfo = new FileInfo(strFile); FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, ""); Services.FileSystem.FileInfo objFile = objFiles.GetFile(lblFile.Text, PortalId, objFolder.FolderID); if (objFile == null) { objFiles.AddFile(PortalId, lblFile.Text, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID, true); } else { objFiles.UpdateFile(objFile.FileId, objFile.FileName, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID); } } else { strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile); } } else { strMessage = Localization.GetString("NoContent", this.LocalResourceFile); } } else { strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile); } } catch { strMessage = Localization.GetString("Error", this.LocalResourceFile); } } else { strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile); } } return strMessage; }
/// <summary>process import of multi-instance records.</summary> /// <param name="xml">The xml.</param> /// <param name="prefix">The prefix (image, or link)</param> /// <param name="slide">The slide.</param> private static void ProcessImport(XmlNode xml, string prefix, Slide slide) { var ps = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings(); var contentTypeXml = xml.SelectSingleNode(prefix + "contenttype"); var contentFileNameXml = xml.SelectSingleNode(prefix + "filename"); var contentFileExtensionXml = xml.SelectSingleNode(prefix + "fileextension"); var contentFolderPathXml = xml.SelectSingleNode(prefix + "folderpath"); var contentBase64Xml = xml.SelectSingleNode(prefix + "filedata"); var contentTabPathXml = xml.SelectSingleNode(prefix + "tabpath"); // this item appears to be an encoded tabpath.... lets continue if (contentTabPathXml != null) { // todo, when upgrading DNN reference, switch this to GetTabByTabPath on the TabController var tabInfo = ps.DesktopTabs.Cast<TabInfo>().SingleOrDefault(desktopTab => desktopTab.TabPath == contentTabPathXml.InnerText); if (tabInfo != null) { switch (prefix) { case "image": slide.ImageLink = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture); break; default: slide.Link = "TabID=" + tabInfo.TabID.ToString(CultureInfo.InvariantCulture); break; } } } // this item appears to be an encoded image... lets continue if (contentTypeXml != null && contentBase64Xml != null && contentFolderPathXml != null && contentFileNameXml != null && contentFileExtensionXml != null) { var folderController = new FolderController(); var fileController = new FileController(); // for now, just put imported images into the root folder... var folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true); if (folder == null) { folderController.AddFolder(ps.PortalId, contentFolderPathXml.InnerText); folder = folderController.GetFolder(ps.PortalId, contentFolderPathXml.InnerText, true); } var file = fileController.GetFile(contentFileNameXml.InnerText, ps.PortalId, folder.FolderID); if (file == null) { var content = Convert.FromBase64String(contentBase64Xml.InnerText); file = new DotNetNuke.Services.FileSystem.FileInfo { PortalId = ps.PortalId, ContentType = contentTypeXml.InnerText, FileName = contentFileNameXml.InnerText, Extension = contentFileExtensionXml.InnerText, FolderId = folder.FolderID, Size = content.Length, }; // save the file the dnn filesystem File.WriteAllBytes(ps.HomeDirectoryMapPath + file.FileName, content); // add the file to the dnn database file.FileId = fileController.AddFile(file); } // update the files content.... just incase, it never hurts.... right? ////fileController.UpdateFileContent(file.FileId, content); switch (prefix) { case "image": slide.ImageLink = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture); break; default: slide.Link = "FileID=" + file.FileId.ToString(CultureInfo.InvariantCulture); break; } } }
/// <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> private static void ParseFiles(XmlNode node, int portalId) { FileController objController = new FileController(); //Parse the File nodes foreach (XmlNode tempLoopVar_fileNode in node.SelectNodes("file")) { XmlNode fileNode = tempLoopVar_fileNode; string strFileName = XmlUtils.GetNodeValue(fileNode, "filename", ""); string strExtenstion = XmlUtils.GetNodeValue(fileNode, "extension", ""); long fileSize = long.Parse(XmlUtils.GetNodeValue(fileNode, "size", "")); int iWidth = XmlUtils.GetNodeValueInt(fileNode, "width", 0); int iHeight = XmlUtils.GetNodeValueInt(fileNode, "height", 0); string strType = XmlUtils.GetNodeValue(fileNode, "contentType", ""); string strFolder = XmlUtils.GetNodeValue(fileNode, "folder", ""); FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, strFolder); objController.AddFile(portalId, strFileName, strExtenstion, fileSize, iWidth, iHeight, strType, strFolder, objFolder.FolderID, true); } }
public static FolderInfo GetFolder( int PortalID, string FolderPath ) { FolderController objFolderController = new FolderController(); FolderInfo objFolder = objFolderController.GetFolder( PortalID, FolderPath ); if( HostSettings.GetHostSetting( "EnableFileAutoSync" ) != "N" ) { // synchronize files in folder if( objFolder != null ) { SynchronizeFolder( objFolder.PortalID, objFolder.PhysicalPath, objFolder.FolderPath, false, true, false ); } } return objFolder; }
private void SetStorageLocationType() { FolderController objFolder = new FolderController(); string FolderName = cboFolders.SelectedValue; // Check to see if this is the 'Root' folder, if so we cannot rely on its text value because it is something and not an empty string that we need to lookup the 'root' folder if( cboFolders.SelectedValue == string.Empty ) { FolderName = ""; } FolderInfo objFolderInfo = objFolder.GetFolder( PortalSettings.PortalId, FolderName ); if( objFolderInfo != null ) { switch( objFolderInfo.StorageLocation ) { case (int)FolderController.StorageLocationTypes.InsecureFileSystem: imgStorageLocationType.Visible = false; break; case (int)FolderController.StorageLocationTypes.SecureFileSystem: imgStorageLocationType.ImageUrl = ResolveUrl( "~/images/icon_securityroles_16px.gif" ); imgStorageLocationType.Visible = true; break; case (int)FolderController.StorageLocationTypes.DatabaseSecure: imgStorageLocationType.ImageUrl = ResolveUrl( "~/images/icon_sql_16px.gif" ); imgStorageLocationType.Visible = true; break; } } }
/// <summary> /// Unzips a File /// </summary> /// <param name="fileName">The zip File Name</param> /// <param name="DestFolder">The folder where the file is extracted to</param> /// <param name="settings">The Portal Settings for the Portal/Host Account</param> /// <remarks> /// </remarks> public static string UnzipFile( string fileName, string DestFolder, PortalSettings settings ) { int FolderPortalId = GetFolderPortalId( settings ); bool isHost = Convert.ToBoolean( ( ( settings.ActiveTab.ParentId == settings.SuperTabId ) ? true : false ) ); PortalController objPortalController = new PortalController(); FolderController objFolderController = new FolderController(); FileController objFileController = new FileController(); string sourceFolderName = Globals.GetSubFolderPath( fileName ); string sourceFileName = GetFileName( fileName ); FolderInfo folder = objFolderController.GetFolder( FolderPortalId, sourceFolderName ); Services.FileSystem.FileInfo file = objFileController.GetFile( sourceFileName, FolderPortalId, folder.FolderID ); int storageLocation = folder.StorageLocation; ZipInputStream objZipInputStream; ZipEntry objZipEntry; string strMessage = ""; string strFileName = ""; //Get the source Content from wherever it is //Create a Zip Input Stream try { objZipInputStream = new ZipInputStream( GetFileStream( file ) ); } catch( Exception ex ) { return ex.Message; } ArrayList sortedFolders = new ArrayList(); objZipEntry = objZipInputStream.GetNextEntry(); //add initial entry if required if( objZipEntry.IsDirectory ) { sortedFolders.Add( objZipEntry.Name.ToString() ); } //iterate other folders 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; } } objZipEntry = objZipInputStream.GetNextEntry(); while( objZipEntry != null ) { if( objZipEntry.IsDirectory ) { try { AddFolder( settings, DestFolder, objZipEntry.Name, storageLocation ); } catch( Exception ex ) { objZipInputStream.Close(); return ex.Message; } } objZipEntry = objZipInputStream.GetNextEntry(); } //Recreate the Zip Input Stream and parse it for the files 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 ) ) { string strExtension = Path.GetExtension( strFileName ).Replace( ".", "" ); string a = "," + settings.HostSettings["FileExtensions"].ToString().ToLower(); if( ( a.IndexOf( "," + strExtension.ToLower(), 0 ) + 1 ) != 0 || isHost ) { try { string folderPath = 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 ), false, false ); } catch( Exception ex ) { objZipInputStream.Close(); return ex.Message; } } else { // restricted file type strMessage += "<br>" + string.Format( Localization.GetString( "RestrictedFileType" ), strFileName, settings.HostSettings["FileExtensions"].ToString().Replace( ",", ", *." ) ); } } } else // file too large { strMessage += "<br>" + string.Format( Localization.GetString( "DiskSpaceExceeded" ), strFileName ); } } objZipEntry = objZipInputStream.GetNextEntry(); } objZipInputStream.Close(); return strMessage; }
public ArrayList GetFilesByFolder(int portalId, string folderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(portalId, folderPath, false); if (objFolder == null) { return null; } return CBO.FillCollection(GetFiles(portalId, objFolder.FolderID), typeof (FileInfo)); }
/// <summary> /// Adds a File /// </summary> /// <param name="portalId">The Id of the Portal</param> /// <param name="inStream">The stream to add</param> /// <param name="fileName"></param> /// <param name="contentType">The type of the content</param> /// <param name="length">The length of the content</param> /// <param name="folderName">The name of the folder</param> /// <param name="closeInputStream">A flag that dermines if the Input Stream should be closed.</param> /// <param name="clearCache">A flag that indicates whether the file cache should be cleared</param> /// <remarks>This method adds a new file /// </remarks> private static string AddFile( int portalId, Stream inStream, string fileName, string contentType, long length, string folderName, bool closeInputStream, bool clearCache, bool synchronize ) { FolderController objFolderController = new FolderController(); FileController objFileController = new FileController(); string sourceFolderName = Globals.GetSubFolderPath( fileName ); FolderInfo folder = objFolderController.GetFolder( portalId, sourceFolderName ); string sourceFileName = GetFileName( fileName ); string retValue = ""; retValue += CheckValidFileName( fileName ); // HACK : Modified to not error if object is null. //if( retValue.Length > 0 ) if(!String.IsNullOrEmpty(retValue)) { return retValue; } string extension = Path.GetExtension( fileName ).Replace( ".", "" ); if( String.IsNullOrEmpty( contentType ) ) { contentType = GetContentType( extension ); } //Add file to Database int intFileID = objFileController.AddFile( portalId, sourceFileName, extension, length, Null.NullInteger, Null.NullInteger, contentType, folderName, folder.FolderID, clearCache ); //Save file to File Storage if( folder.StorageLocation != (int)FolderController.StorageLocationTypes.InsecureFileSystem || synchronize == false ) { WriteStream( intFileID, inStream, fileName, folder.StorageLocation, closeInputStream ); } //Update the FileData retValue += UpdateFileData( intFileID, folder.FolderID, portalId, sourceFileName, extension, contentType, length, folderName ); if( folder.StorageLocation != (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { //try and delete the Insecure file AttemptFileDeletion( fileName ); } if( folder.StorageLocation != (int)FolderController.StorageLocationTypes.SecureFileSystem ) { //try and delete the Secure file AttemptFileDeletion( fileName + Globals.glbProtectedExtension ); } return retValue; }
protected void Save_OnClick(object sender, EventArgs e) { try { if (FolderList.Items.Count == 0) { return; } DotNetNuke.Entities.Portals.PortalSettings portalSettings = DotNetNuke.Entities.Portals.PortalSettings.Current; string fileContents = htmlText2.Text.Trim(); string newFileName = FileName.Text; if (! (newFileName.EndsWith(".html"))) { newFileName = newFileName + ".html"; } string rootFolder = portalSettings.HomeDirectoryMapPath; string dbFolderPath = FolderList.SelectedValue; string virtualFolder = (string)(string)FileSystemValidation.ToVirtualPath(dbFolderPath); rootFolder = rootFolder + FolderList.SelectedValue; rootFolder = rootFolder.Replace("/", "\\"); string errorMessage = string.Empty; FolderController folderCtrl = new FolderController(); FolderInfo folder = folderCtrl.GetFolder(portalSettings.PortalId, dbFolderPath, false); if ((folder == null)) { ShowSaveTemplateMessage(GetString("msgFolderDoesNotExist.Text")); return; } // Check file name is valid FileSystemValidation dnnValidator = new FileSystemValidation(); errorMessage = dnnValidator.OnCreateFile(virtualFolder + newFileName, fileContents.Length); if (! (string.IsNullOrEmpty(errorMessage))) { ShowSaveTemplateMessage(errorMessage); return; } FileController fileCtrl = new FileController(); DotNetNuke.Services.FileSystem.FileInfo existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID); // error if file exists if (! Overwrite.Checked && existingFile != null) { ShowSaveTemplateMessage(GetString("msgFileExists.Text")); return; } FileInfo newFile = existingFile; if ((newFile == null)) { newFile = new FileInfo(); } newFile.FileName = newFileName; newFile.ContentType = "text/plain"; newFile.Extension = "html"; newFile.Size = fileContents.Length; newFile.FolderId = folder.FolderID; errorMessage = FileSystemUtils.CreateFileFromString(rootFolder, newFile.FileName, fileContents, newFile.ContentType, string.Empty, false); if (! (string.IsNullOrEmpty(errorMessage))) { ShowSaveTemplateMessage(errorMessage); return; } existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID); if (newFile.FileId != existingFile.FileId) { newFile.FileId = existingFile.FileId; } if (newFile.FileId != Null.NullInteger) { fileCtrl.UpdateFile(newFile.FileId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID); } else { fileCtrl.AddFile(portalSettings.PortalId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID, true); } ShowSaveTemplateMessage(string.Empty); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); throw ex; } }
/// <summary> /// Deletes a file /// </summary> /// <param name="strSourceFile">The File to delete</param> /// <param name="settings">The Portal Settings for the Portal/Host Account</param> /// <param name="ClearCache"></param> public static string DeleteFile( string strSourceFile, PortalSettings settings, bool ClearCache ) { string retValue = ""; try { //try and delete the Insecure file AttemptFileDeletion( strSourceFile ); //try and delete the Secure file AttemptFileDeletion( strSourceFile + Globals.glbProtectedExtension ); string folderName = Globals.GetSubFolderPath( strSourceFile ); string fileName = GetFileName( strSourceFile ); int PortalId = GetFolderPortalId( settings ); //Remove file from DataBase FileController objFileController = new FileController(); FolderController objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder( PortalId, folderName ); objFileController.DeleteFile( PortalId, fileName, objFolder.FolderID, ClearCache ); } catch( Exception ex ) { retValue = ex.Message; } return retValue; }
public static ArrayList GetFilesByFolder(int PortalId, string folderPath) { var objFolders = new FolderController(); FolderInfo objFolder = objFolders.GetFolder(PortalId, folderPath, false); if (objFolder == null) { return null; } return GetFilesByFolder(PortalId, objFolder.FolderID); }
/// <summary> /// GeneratePermissionsGrid generates the permissions grid for the folder /// </summary> /// <history> /// [cnurse] 12/2/2004 documented /// </history> private void GeneratePermissionsGrid() { string folderPath = FileSystemUtils.StripFolderPath( DestPath ).Replace( "\\", "/" ); dgPermissions.FolderPath = folderPath; if( ! IsHostMenu ) { dgPermissions.DataBind(); } FolderController objFolderController = new FolderController(); FolderInfo objFolderInfo = objFolderController.GetFolder( FolderPortalID, folderPath ); if( objFolderInfo != null ) { ddlStorageLocation.SelectedValue = Convert.ToString( objFolderInfo.StorageLocation ); } }