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; } }
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; }
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); } }
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> /// 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; } } }
/// <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 UploadFile() { System.Web.HttpPostedFile postedFile = fileImport.PostedFile; FolderInfo fi = FileSystemUtils.GetFolder(PortalId, "Location Import"); //ArrayList al = FileSystemUtils.GetFilesByFolder(PortalId, fi.FolderID); string[] files = Directory.GetFiles(fi.PhysicalPath); FileController fc = new FileController(); string fileName = Path.GetFileName(postedFile.FileName); string newPath = fi.PhysicalPath + fileName; foreach (string s in files) { if (s == fileName) { lblMessage.Text = Localization.GetString("FileExists", LocalResourceFile); return; } } postedFile.SaveAs(newPath); string ext = Path.GetExtension(postedFile.FileName).Substring(1); int fileId = fc.AddFile(PortalId, fileName,ext , postedFile.ContentLength, Null.NullInteger, Null.NullInteger, postedFile.ContentType, fi.FolderPath, fi.FolderID, true); DataProvider provider = DataProvider.Instance(); provider.InsertFileInfo(fileId, UserId, TabModuleId, PortalId, DateTime.Now, false, false); lblMessage.Text = Localization.GetString("FileUploaded", LocalResourceFile); }
/// <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 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; FileController objFiles = new FileController(); if (portalSettings.ActiveTab.ParentId == portalSettings.SuperTabId) { portalId = Null.NullInteger; } else { portalId = portalSettings.PortalId; } objFiles.AddFile(portalId, strFileName, strExtension, Length, imageWidth, imageHeight, strContentType, FolderPath); }
/// <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; } } }