/// <summary> /// Adds a File /// </summary> /// <param name="strFile">The File Name</param> /// <param name="portalId">The Id of the Portal</param> /// <param name="clearCache">A flag that indicates whether the file cache should be cleared</param> /// <remarks>This method is called by the SynchonizeFolder method, when the file exists in the file system /// but not in the Database /// </remarks> /// <history> /// [cnurse] 12/2/2004 Created /// [cnurse] 04/26/2006 Updated to account for secure storage /// </history> /// <param name="folderId"></param> private static string AddFile( string strFile, int portalId, bool clearCache, int folderId ) { string retValue = ""; try { FileController objFileController = new FileController(); FileInfo fInfo = new FileInfo( strFile ); string sourceFolderName = Globals.GetSubFolderPath( strFile ); string sourceFileName = GetFileName( strFile ); Services.FileSystem.FileInfo file = objFileController.GetFile( sourceFileName, portalId, folderId ); if( file == null ) { //Add the new File AddFile( portalId, fInfo.OpenRead(), strFile, "", fInfo.Length, sourceFolderName, true, clearCache ); } else { if( file.Size != fInfo.Length ) { //optimistic assumption for speed: update only if filesize has changed string extension = Path.GetExtension( strFile ).Replace( ".", "" ); UpdateFileData( file.FileId, folderId, portalId, sourceFileName, extension, GetContentType( extension ), fInfo.Length, sourceFolderName ); } } } catch( Exception ex ) { retValue = ex.Message; } return retValue; }
public static XmlReader CreateXmlReader(string xmlsrc, int portalId, bool prohibitDtd) { if (xmlsrc == String.Empty) return null; var filecontroller = new FileController(); var xmlFileInfo = filecontroller.GetFileById(filecontroller.ConvertFilePathToFileId(xmlsrc, portalId), portalId); return XmlReader.Create(FileSystemUtils.GetFileStream(xmlFileInfo), new XmlReaderSettings {ProhibitDtd = prohibitDtd}); }
protected void Page_Load(object sender, System.EventArgs e) { try { string renderUrl = Request.QueryString["rurl"]; if (! (string.IsNullOrEmpty(renderUrl))) { string fileContents = string.Empty; FileController fileCtrl = new FileController(); FileInfo fileInfo = null; int portalID = PortalController.GetCurrentPortalSettings().PortalId; if (renderUrl.ToLower().Contains("linkclick.aspx") && renderUrl.ToLower().Contains("fileticket")) { //File Ticket int fileID = GetFileIDFromURL(renderUrl); if (fileID > -1) { fileInfo = fileCtrl.GetFileById(fileID, portalID); } } else { //File URL string dbPath = (string)(string)FileSystemValidation.ToDBPath(renderUrl); string fileName = System.IO.Path.GetFileName(renderUrl); if (! (string.IsNullOrEmpty(fileName))) { FolderInfo dnnFolder = GetDNNFolder(dbPath); if (dnnFolder != null) { fileInfo = fileCtrl.GetFile(fileName, portalID, dnnFolder.FolderID); } } } if (fileInfo != null) { if (CanViewFile(fileInfo.Folder) && fileInfo.Extension.ToLower() == "htmtemplate") { byte[] fileBytes = FileSystemUtils.GetFileContent(fileInfo); fileContents = System.Text.Encoding.ASCII.GetString(fileBytes); } } if (! (string.IsNullOrEmpty(fileContents))) { Content.Text = Server.HtmlEncode(fileContents); } } } catch (Exception ex) { Services.Exceptions.Exceptions.LogException(ex); Content.Text = string.Empty; } }
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 static FileInfo DeserializeFile(XmlNode nodeFile, int portalId, int folderId) { var node = nodeFile.SelectSingleNode("file"); var newFile = new FileInfo { UniqueId = new Guid(XmlUtils.GetNodeValue(node.CreateNavigator(), "uniqueid")), VersionGuid = new Guid(XmlUtils.GetNodeValue(node.CreateNavigator(), "versionguid")), PortalId = portalId, FileName = XmlUtils.GetNodeValue(node.CreateNavigator(), "filename"), Folder = XmlUtils.GetNodeValue(node.CreateNavigator(), "folder"), FolderId = folderId, ContentType = XmlUtils.GetNodeValue(node.CreateNavigator(), "contenttype"), Extension = XmlUtils.GetNodeValue(node.CreateNavigator(), "extension"), StorageLocation = XmlUtils.GetNodeValueInt(node, "storagelocation"), IsCached = XmlUtils.GetNodeValueBoolean(node, "iscached", false), Size = XmlUtils.GetNodeValueInt(node, "size", Null.NullInteger), Width = XmlUtils.GetNodeValueInt(node, "width", Null.NullInteger), Height = XmlUtils.GetNodeValueInt(node, "height", Null.NullInteger) }; // create/update file var fileCtrl = new FileController(); var originalFile = fileCtrl.GetFileByUniqueID(newFile.UniqueId); if (originalFile == null) { var folder = FolderManager.Instance.GetFolder(folderId); using (var fileContent = FileManager.Instance.GetFileContent(newFile)) { newFile.FileId = FileManager.Instance.AddFile(folder, newFile.FileName, fileContent, false).FileId; } } else { newFile.FileId = originalFile.FileId; } return((FileInfo)FileManager.Instance.UpdateFile(newFile)); }
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> /// This handler handles requests for LinkClick.aspx, but only those specifc /// to file serving /// </Summary> /// <Param name="context">System.Web.HttpContext)</Param> public virtual void ProcessRequest(HttpContext context) { PortalSettings portalSettings = PortalController.GetCurrentPortalSettings(); // get TabId int tabId = -1; if (context.Request.QueryString["tabid"] != null) { tabId = int.Parse(context.Request.QueryString["tabid"]); } // get ModuleId int moduleId = -1; if (context.Request.QueryString["mid"] != null) { moduleId = int.Parse(context.Request.QueryString["mid"]); } // get the URL string URL = ""; bool blnClientCache = true; bool blnForceDownload = false; if (context.Request.QueryString["fileticket"] != null) { URL = "FileID=" + UrlUtils.DecryptParameter(context.Request.QueryString["fileticket"]); } if (context.Request.QueryString["userticket"] != null) { URL = "UserId=" + UrlUtils.DecryptParameter(context.Request.QueryString["userticket"]); } if (context.Request.QueryString["link"] != null) { URL = context.Request.QueryString["link"]; if (URL.ToLower().StartsWith("fileid=")) { URL = ""; // restrict direct access by FileID } } if (!String.IsNullOrEmpty(URL)) { TabType UrlType = Globals.GetURLType(URL); if (UrlType != TabType.File) { URL = Globals.LinkClick(URL, tabId, moduleId, false); } if (UrlType == TabType.File && URL.ToLower().StartsWith("fileid=") == false) { // to handle legacy scenarios before the introduction of the FileServerHandler FileController objFiles = new FileController(); URL = "FileID=" + objFiles.ConvertFilePathToFileId(URL, portalSettings.PortalId); } // get optional parameters if (context.Request.QueryString["clientcache"] != null) { blnClientCache = bool.Parse(context.Request.QueryString["clientcache"]); } if ((context.Request.QueryString["forcedownload"] != null) || (context.Request.QueryString["contenttype"] != null)) { blnForceDownload = bool.Parse(context.Request.QueryString["forcedownload"]); } // update clicks UrlController objUrls = new UrlController(); objUrls.UpdateUrlTracking(portalSettings.PortalId, URL, moduleId, -1); // clear the current response context.Response.Clear(); if (UrlType == TabType.File) { // serve the file if (tabId == Null.NullInteger) { if (!(FileSystemUtils.DownloadFile(portalSettings.PortalId, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))) { context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error")); } } else { if (!(FileSystemUtils.DownloadFile(portalSettings, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))) { context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error")); } } } else { // redirect to URL context.Response.Redirect(URL, true); } } }
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; } }
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> /// Goes to selected file. /// </summary> /// <param name="fileName">Name of the file.</param> private void GoToSelectedFile(string fileName) { // Find the File inside the Repeater foreach (RepeaterItem item in this.FilesList.Items) { HtmlGenericControl listRow = (HtmlGenericControl)item.FindControl("ListRow"); switch (item.ItemType) { case ListItemType.Item: listRow.Attributes["class"] = "FilesListRow"; break; case ListItemType.AlternatingItem: listRow.Attributes["class"] = "FilesListRowAlt"; break; } if (listRow.Attributes["title"] != fileName) { continue; } listRow.Attributes["class"] += " Selected"; LinkButton fileListItem = (LinkButton)item.FindControl("FileListItem"); if (fileListItem == null) { return; } int fileId = Convert.ToInt32(fileListItem.CommandArgument); var fileInfo = new FileController().GetFileById(fileId, this._portalSettings.PortalId); this.ShowFileHelpUrl(fileInfo.FileName, fileInfo); this.ScrollToSelectedFile(fileListItem.ClientID); } }
private static Stream GetFileStream( Services.FileSystem.FileInfo objFile ) { FileController objFileController = new FileController(); Stream fileStream = null; if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { // read from file system fileStream = new FileStream( objFile.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read ); } else if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem ) { // read from file system fileStream = new FileStream( objFile.PhysicalPath + Globals.glbProtectedExtension, FileMode.Open, FileAccess.Read, FileShare.Read ); } else if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure ) { // read from database fileStream = new MemoryStream( objFileController.GetFileContent( objFile.FileId, objFile.PortalId ) ); } return fileStream; }
/// <summary> /// Streams a file to the output stream if the user has the proper permissions /// </summary> /// <param name="PortalId">The Id of the Portal to which the file belongs</param> /// <param name="FileId">FileId identifying file in database</param> /// <param name="ClientCache">Cache file in client browser - true/false</param> /// <param name="ForceDownload">Force Download File dialog box - true/false</param> public static bool DownloadFile( int PortalId, int FileId, bool ClientCache, bool ForceDownload ) { bool blnDownload = false; // get file FileController objFiles = new FileController(); Services.FileSystem.FileInfo objFile = objFiles.GetFileById( FileId, PortalId ); if( objFile != null ) { // check folder view permissions if( PortalSecurity.IsInRoles( GetRoles( objFile.Folder, PortalId, "READ" ) ) ) { // auto sync bool blnFileExists = true; if( HostSettings.GetHostSetting( "EnableFileAutoSync" ) != "N" ) { string strFile = ""; if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { strFile = objFile.PhysicalPath; } else if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem ) { strFile = objFile.PhysicalPath + Globals.glbProtectedExtension; } if( strFile != "" ) { // synchronize file FileInfo objFileInfo = new FileInfo( strFile ); if( objFileInfo.Exists ) { if( objFile.Size != objFileInfo.Length ) { objFile.Size = Convert.ToInt32( objFileInfo.Length ); UpdateFileData( FileId, objFile.FolderId, PortalId, objFile.FileName, objFile.Extension, GetContentType( objFile.Extension ), objFileInfo.Length, objFile.Folder ); } } else // file does not exist { RemoveOrphanedFile( objFile, PortalId ); blnFileExists = false; } } } // download file if( blnFileExists ) { // save script timeout int scriptTimeOut = HttpContext.Current.Server.ScriptTimeout; // temporarily set script timeout to large value ( this value is only applicable when application is not running in Debug mode ) HttpContext.Current.Server.ScriptTimeout = int.MaxValue; HttpResponse objResponse = HttpContext.Current.Response; objResponse.ClearContent(); objResponse.ClearHeaders(); // force download dialog if( ForceDownload || objFile.Extension.ToLower().Equals( "pdf" ) ) { objResponse.AppendHeader( "content-disposition", "attachment; filename=" + objFile.FileName ); } else { //use proper file name when browser forces download because of file type (save as name should match file name) objResponse.AppendHeader( "content-disposition", "inline; filename=" + objFile.FileName ); } objResponse.AppendHeader( "Content-Length", objFile.Size.ToString() ); objResponse.ContentType = GetContentType( objFile.Extension.Replace( ".", "" ) ); //Stream the file to the response Stream objStream = GetFileStream( objFile ); try { WriteStream( objResponse, objStream ); } catch( Exception ex ) { // Trap the error, if any. objResponse.Write( "Error : " + ex.Message ); } finally { if( objStream != null ) { // Close the file. objStream.Close(); } } objResponse.Flush(); objResponse.Close(); blnDownload = true; } } } return blnDownload; }
/// <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; }
/// <summary> /// Writes a Stream to the appropriate File Storage /// </summary> /// <param name="fileId">The Id of the File</param> /// <param name="inStream">The Input Stream</param> /// <param name="fileName">The name of the file</param> /// <param name="storageLocation">The type of storage location</param> /// <param name="closeInputStream">A flag that dermines if the Input Stream should be closed.</param> /// <remarks> /// </remarks> private static void WriteStream( int fileId, Stream inStream, string fileName, int storageLocation, bool closeInputStream ) { FileController objFileController = new FileController(); // Buffer to read 2K bytes in chunk: byte[] arrData = new byte[2049]; Stream outStream = null; if( storageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure ) { objFileController.ClearFileContent( fileId ); outStream = new MemoryStream(); } else if( storageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem ) { if( File.Exists( fileName + Globals.glbProtectedExtension ) == true ) { File.Delete( fileName + Globals.glbProtectedExtension ); } outStream = new FileStream( fileName + Globals.glbProtectedExtension, FileMode.Create ); } else if( storageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { if( File.Exists( fileName ) == true ) { File.Delete( fileName ); } outStream = new FileStream( fileName, FileMode.Create ); } try { // Total bytes to read: // Read the data in buffer int intLength = inStream.Read( arrData, 0, arrData.Length ); while( intLength > 0 ) { // Write the data to the current output stream. if( outStream != null ) { outStream.Write( arrData, 0, intLength ); } //Read the next chunk intLength = inStream.Read( arrData, 0, arrData.Length ); } if( storageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure ) { if( outStream != null ) { outStream.Seek( 0, SeekOrigin.Begin ); } objFileController.UpdateFileContent( fileId, outStream ); } } catch( Exception ) { } finally { if( inStream != null && closeInputStream ) { // Close the file. inStream.Close(); } if( outStream != null ) { // Close the file. outStream.Close(); } } }
private static string UpdateFileData( int fileID, int folderID, int PortalId, string fileName, string extension, string contentType, long length, string folderName ) { string retvalue = ""; try { FileController objFileController = new FileController(); Image imgImage = null; int imageWidth = 0; int imageHeight = 0; // HACK : VB version of this line used InStr() and converted the outputed // int to a boolean to check if the file extention was an image type, // which does not work in C# hence the line as it is now. if((Globals.glbImageFileTypes.IndexOf(extension.ToLower())+1) > 0) { try { Services.FileSystem.FileInfo objFile = objFileController.GetFileById( fileID, PortalId ); Stream imageStream = GetFileStream( objFile ); imgImage = Image.FromStream( imageStream ); imageHeight = imgImage.Height; imageWidth = imgImage.Width; imgImage.Dispose(); imageStream.Close(); } catch { // error loading image file contentType = "application/octet-stream"; } finally { //Update the File info objFileController.UpdateFile( fileID, fileName, extension, length, imageWidth, imageHeight, contentType, folderName, folderID ); } } } catch( Exception ex ) { retvalue = ex.Message; } return retvalue; }
/// <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; }
public static FileInfo DeserializeFile(XmlNode nodeFile, int portalId, int folderId) { var node = nodeFile.SelectSingleNode("file"); var newFile = new FileInfo { UniqueId = new Guid(XmlUtils.GetNodeValue(node.CreateNavigator(), "uniqueid")), VersionGuid = new Guid(XmlUtils.GetNodeValue(node.CreateNavigator(), "versionguid")), PortalId = portalId, FileName = XmlUtils.GetNodeValue(node.CreateNavigator(), "filename"), Folder = XmlUtils.GetNodeValue(node.CreateNavigator(), "folder"), FolderId = folderId, ContentType = XmlUtils.GetNodeValue(node.CreateNavigator(), "contenttype"), Extension = XmlUtils.GetNodeValue(node.CreateNavigator(), "extension"), StorageLocation = XmlUtils.GetNodeValueInt(node, "storagelocation"), IsCached = XmlUtils.GetNodeValueBoolean(node, "iscached", false), Size = XmlUtils.GetNodeValueInt(node, "size", Null.NullInteger), Width = XmlUtils.GetNodeValueInt(node, "width", Null.NullInteger), Height = XmlUtils.GetNodeValueInt(node, "height", Null.NullInteger) }; // create/update file var fileCtrl = new FileController(); var originalFile = fileCtrl.GetFileByUniqueID(newFile.UniqueId); if (originalFile == null) { var folder = FolderManager.Instance.GetFolder(folderId); using (var fileContent = FileManager.Instance.GetFileContent(newFile)) { newFile.FileId = FileManager.Instance.AddFile(folder, newFile.FileName, fileContent, false).FileId; } } else { newFile.FileId = originalFile.FileId; } return (FileInfo)FileManager.Instance.UpdateFile(newFile); }
private string ImportFile( int PortalId, string url ) { string strUrl = url; if( Globals.GetURLType( url ) == TabType.File ) { FileController objFileController = new FileController(); int fileId = objFileController.ConvertFilePathToFileId( url, PortalId ); if( fileId >= 0 ) { strUrl = "FileID=" + fileId.ToString(); } } return strUrl; }
/// <summary> /// Show Info for Selected File /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> private void FilesList_ItemCommand(object source, RepeaterCommandEventArgs e) { foreach (RepeaterItem item in this.FilesList.Items) { var listRowItem = (HtmlGenericControl)item.FindControl("ListRow"); switch (item.ItemType) { case ListItemType.Item: listRowItem.Attributes["class"] = "FilesListRow"; break; case ListItemType.AlternatingItem: listRowItem.Attributes["class"] = "FilesListRowAlt"; break; } } var listRow = (HtmlGenericControl)e.Item.FindControl("ListRow"); listRow.Attributes["class"] += " Selected"; var fileListItem = (LinkButton)e.Item.FindControl("FileListItem"); if (fileListItem == null) { return; } int fileId = Convert.ToInt32(fileListItem.CommandArgument); var currentFile = new FileController().GetFileById(fileId, this._portalSettings.PortalId); this.ShowFileHelpUrl(currentFile.FileName, currentFile); this.ScrollToSelectedFile(fileListItem.ClientID); }
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> /// Close Browser Window /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void CmdCloseClick(object sender, EventArgs e) { if (!this.panLinkMode.Visible && this.panPageMode.Visible) { if (this.dnntreeTabs.SelectedNode != null) { var tabController = new TabController(); var selectTab = tabController.GetTab( int.Parse(this.dnntreeTabs.SelectedValue), this._portalSettings.PortalId, true); string fileName = null; var domainName = string.Format("http://{0}", Globals.GetDomainName(this.Request, true)); // Add Language Parameter ?! var localeSelected = this.LanguageRow.Visible && this.LanguageList.SelectedIndex > 0; var friendlyUrl = localeSelected ? Globals.FriendlyUrl( selectTab, string.Format( "{0}&language={1}", Globals.ApplicationURL(selectTab.TabID), this.LanguageList.SelectedValue), this._portalSettings) : Globals.FriendlyUrl( selectTab, Globals.ApplicationURL(selectTab.TabID), this._portalSettings); var locale = localeSelected ? string.Format("language/{0}/", this.LanguageList.SelectedValue) : string.Empty; // Relative or Absolute Url switch (this.rblLinkType.SelectedValue) { case "relLnk": { if (this.chkHumanFriendy.Checked) { fileName = friendlyUrl; fileName = Globals.ResolveUrl( Regex.Replace(fileName, domainName, "~", RegexOptions.IgnoreCase)); } else { fileName = Globals.ResolveUrl( string.Format("~/tabid/{0}/{1}Default.aspx", selectTab.TabID, locale)); } break; } case "absLnk": { if (this.chkHumanFriendy.Checked) { fileName = friendlyUrl; fileName = Regex.Replace( fileName, domainName, string.Format("{0}", domainName), RegexOptions.IgnoreCase); } else { fileName = string.Format( "{2}/tabid/{0}/{1}Default.aspx", selectTab.TabID, locale, domainName); } } break; case "lnkClick": { fileName = Globals.LinkClick( selectTab.TabID.ToString(), this.TrackClicks.Checked ? int.Parse(this.request.QueryString["tabid"]) : Null.NullInteger, Null.NullInteger); if (fileName.Contains("&language")) { fileName = fileName.Remove(fileName.IndexOf("&language")); } break; } case "lnkAbsClick": { fileName = string.Format( "{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, Globals.LinkClick( selectTab.TabID.ToString(), this.TrackClicks.Checked ? int.Parse(this.request.QueryString["tabid"]) : Null.NullInteger, Null.NullInteger)); if (fileName.Contains("&language")) { fileName = fileName.Remove(fileName.IndexOf("&language")); } break; } } // Add Page Anchor if one is selected if (this.AnchorList.SelectedIndex > 0 && this.AnchorList.Items.Count > 1) { fileName = string.Format("{0}#{1}", fileName, this.AnchorList.SelectedItem.Text); } this.Response.Write("<script type=\"text/javascript\">"); this.Response.Write(this.GetJavaScriptCode(fileName, null, true)); this.Response.Write("</script>"); this.Response.End(); } } else if (this.panLinkMode.Visible && !this.panPageMode.Visible) { if (!string.IsNullOrEmpty(this.lblFileName.Text) && !string.IsNullOrEmpty(this.FileId.Text)) { var fileInfo = new FileController().GetFileById(int.Parse(this.FileId.Text), this._portalSettings.PortalId); var fileName = fileInfo.FileName; var filePath = string.Empty; // Relative or Absolute Url switch (this.rblLinkType.SelectedValue) { case "relLnk": { filePath = MapUrl(this.lblCurrentDir.Text); break; } case "absLnk": { filePath = string.Format( "{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, MapUrl(this.lblCurrentDir.Text)); break; } case "lnkClick": { var link = string.Format("fileID={0}", fileInfo.FileId); fileName = Globals.LinkClick(link, int.Parse(this.request.QueryString["tabid"]), Null.NullInteger, this.TrackClicks.Checked); filePath = string.Empty; break; } case "lnkAbsClick": { var link = string.Format("fileID={0}", fileInfo.FileId); fileName = string.Format( "{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, Globals.LinkClick(link, int.Parse(this.request.QueryString["tabid"]), Null.NullInteger, this.TrackClicks.Checked)); filePath = string.Empty; break; } } this.Response.Write("<script type=\"text/javascript\">"); this.Response.Write(this.GetJavaScriptCode(fileName, filePath, false)); this.Response.Write("</script>"); this.Response.End(); } else { this.Response.Write("<script type=\"text/javascript\">"); this.Response.Write( string.Format( "javascript:alert('{0}');", Localization.GetString("Error5.Text", this.ResXFile, this.LanguageCode))); this.Response.Write("</script>"); this.Response.End(); } } }
/// <summary> /// Binds the data. /// </summary> public void BindData() { this.LoadFolders(); this.Files.Items.Clear(); this.Files.DataSource = this.GetFileList(true); this.Files.DataBind(); this.ReloadFiles = false; var _url = Convert.ToString(this.ViewState["Url"]); if (string.IsNullOrEmpty(_url)) { return; } var _urltype = DotNetNuke.Common.Globals.GetURLType(_url).ToString("g").Substring(0, 1); if (_urltype == "F") { var files = new FileController(); if (_url.ToLower().StartsWith("fileid=")) { FileInfo objFile = files.GetFileById(int.Parse(_url.Substring(7)), this.PortalId); if (objFile != null) { _url = objFile.Folder + objFile.FileName; var fileName = _url.Substring(_url.LastIndexOf("/", StringComparison.Ordinal) + 1); var folderPath = _url.Replace(fileName, string.Empty); if (this.Folders.Items.FindByValue(folderPath) != null) { this.Folders.ClearSelection(); this.Folders.Items.FindByValue(folderPath).Selected = true; } else if (this.Folders.Items.Count > 0) { this.Folders.ClearSelection(); this.Folders.Items[0].Selected = true; } if (this.Files.Items.FindByText(fileName) != null) { this.Files.ClearSelection(); this.Files.Items.FindByText(fileName).Selected = true; } } } } this.ViewState["Url"] = _url; }
/// <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; } } }
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 ); } } }
public void UpdateUrlTracking(int PortalID, string Url, int ModuleId, int UserID) { TabType UrlType = Globals.GetURLType(Url); if (UrlType == TabType.File & Url.ToLower().StartsWith("fileid=") == false) { // to handle legacy scenarios before the introduction of the FileServerHandler FileController objFiles = new FileController(); Url = "FileID=" + objFiles.ConvertFilePathToFileId(Url, PortalID); } UrlTrackingInfo objUrlTracking = GetUrlTracking(PortalID, Url, ModuleId); if (objUrlTracking != null) { if (objUrlTracking.TrackClicks) { DataProvider.Instance().UpdateUrlTrackingStats(PortalID, Url, ModuleId); if (objUrlTracking.LogActivity) { if (UserID == -1) { UserID = UserController.GetCurrentUserInfo().UserID; } DataProvider.Instance().AddUrlLog(objUrlTracking.UrlTrackingID, UserID); } } } }
private static void RemoveOrphanedFile( Services.FileSystem.FileInfo objFile, int PortalId ) { FileController objFileController = new FileController(); string strFile = ""; if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem ) { strFile = objFile.PhysicalPath; } else if( objFile.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem ) { strFile = objFile.PhysicalPath + Globals.glbProtectedExtension; } if( !String.IsNullOrEmpty( strFile ) ) { if( !( File.Exists( strFile ) ) ) { objFileController.DeleteFile( PortalId, objFile.FileName, objFile.FolderId, true ); } } }
protected void btnAddAttachment_Click(object sender, EventArgs e) { string url = UserInfo.IsInRole(PortalSettings.AdministratorRoleName) ? ctlAttachment.Url : ctlUserAttachment.Url; if (url == "")//当前没有选择任何文件,直接返回 { return; } FileController fc = new FileController(); DotNetNuke.Services.FileSystem.FileInfo fi = new DotNetNuke.Services.FileSystem.FileInfo(); DotNetNuke.Entities.Portals.PortalController ctlPortal = new DotNetNuke.Entities.Portals.PortalController(); DotNetNuke.Entities.Portals.PortalInfo pi = ctlPortal.GetPortal(PortalId); AttachmentInfo ai = new AttachmentInfo(); if (url.StartsWith("FileID=")) { fi = GetFileInfoById(url); if (fi != null && System.IO.File.Exists(fi.PhysicalPath)) { ai.FilePath = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + fi.FileName; } } List<AttachmentInfo> list = AttachmentList; if (list == null) { list = new List<AttachmentInfo>(); } ai.Id = list.Count;//累加Id list.Add(ai); AttachmentList = list; gvAttachment.DataSource = AttachmentList; gvAttachment.DataBind(); }
public static ArrayList GetFilesByFolder( int PortalId, int folderId ) { FileController objFileController = new FileController(); return CBO.FillCollection( objFileController.GetFiles( PortalId, folderId ), typeof( Services.FileSystem.FileInfo ) ); }
/// <summary> /// cmdSend_Click runs when the cmdSend Button is clicked /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 9/10/2004 Updated to reflect design changes for Help, 508 support /// and localisation /// </history> protected void cmdSend_Click( Object sender, EventArgs e ) { try { ArrayList objRecipients = new ArrayList(); RoleController objRoles = new RoleController(); ListItem objListItem; // load all user emails based on roles selected foreach( ListItem objRole in chkRoles.Items ) { if( objRole.Selected ) { foreach( UserInfo objUser in objRoles.GetUsersByRoleName( PortalId, objRole.Value ) ) { if( objUser.Membership.Approved ) { objListItem = new ListItem( objUser.Email, objUser.DisplayName ); if( ! objRecipients.Contains( objListItem ) ) { objRecipients.Add( objListItem ); } } } } } // load emails specified in email distribution list if( !String.IsNullOrEmpty(txtEmail.Text) ) { string[] splitter = {";"}; Array arrEmail = txtEmail.Text.Split(splitter, StringSplitOptions.None); foreach( string strEmail in arrEmail ) { objListItem = new ListItem( strEmail, strEmail ); if( ! objRecipients.Contains( objListItem ) ) { objRecipients.Add( objListItem ); } } } // create object SendBulkEmail objSendBulkEMail = new SendBulkEmail( objRecipients, cboPriority.SelectedItem.Value, teMessage.Mode, PortalSettings.PortalAlias.HTTPAlias ); objSendBulkEMail.Subject = txtSubject.Text; objSendBulkEMail.Body += teMessage.Text; if( ctlAttachment.Url.StartsWith( "FileID=" ) ) { int fileId = int.Parse( ctlAttachment.Url.Substring( 7 ) ); FileController objFileController = new FileController(); FileInfo objFileInfo = objFileController.GetFileById( fileId, PortalId ); objSendBulkEMail.Attachment = PortalSettings.HomeDirectoryMapPath + objFileInfo.Folder + objFileInfo.FileName; } objSendBulkEMail.SendMethod = cboSendMethod.SelectedItem.Value; objSendBulkEMail.SMTPServer = Convert.ToString( PortalSettings.HostSettings["SMTPServer"] ); objSendBulkEMail.SMTPAuthentication = Convert.ToString( PortalSettings.HostSettings["SMTPAuthentication"] ); objSendBulkEMail.SMTPUsername = Convert.ToString( PortalSettings.HostSettings["SMTPUsername"] ); objSendBulkEMail.SMTPPassword = Convert.ToString( PortalSettings.HostSettings["SMTPPassword"] ); objSendBulkEMail.Administrator = txtFrom.Text; objSendBulkEMail.Heading = Localization.GetString( "Heading", this.LocalResourceFile ); // send mail if( optSendAction.SelectedItem.Value == "S" ) { objSendBulkEMail.Send(); } else // ansynchronous uses threading { Thread objThread = new Thread( new ThreadStart( objSendBulkEMail.Send ) ); objThread.Start(); } // completed UI.Skins.Skin.AddModuleMessage( this, Localization.GetString( "MessageSent", this.LocalResourceFile ), ModuleMessageType.GreenSuccess ); } catch( Exception exc ) //Module failed to load { Exceptions.ProcessModuleLoadException( this, exc ); } }
/// <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 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); } } } }
/// <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; }