Beispiel #1
0
        private string ExportModule(int moduleID, string fileName, IFolderInfo folder)
        {
            var strMessage = "";
            if (Module != null)
            {
                if (!String.IsNullOrEmpty(Module.DesktopModule.BusinessControllerClass) && Module.DesktopModule.IsPortable)
                {
                    try
                    {
                        var objObject = Reflection.CreateObject(Module.DesktopModule.BusinessControllerClass, Module.DesktopModule.BusinessControllerClass);
                        
						//Double-check
						if (objObject is IPortable)
                        {
                            var content = Convert.ToString(((IPortable)objObject).ExportModule(moduleID));
                            if (!String.IsNullOrEmpty(content))
                            {
								//remove invalid chars in content
	                            content = Regex.Replace(content, _invalidCharsRegex, string.Empty);
								//add attributes to XML document
                                content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(Module.DesktopModule.ModuleName) + "\" version=\"" +
                                          Module.DesktopModule.Version + "\">" + content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                var objPortalController = new PortalController();
                                var strFile = PortalSettings.HomeDirectoryMapPath + folder.FolderPath + fileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, content.Length))
                                {
                                    //add file to Files table
									using (var fileContent = new MemoryStream(Encoding.UTF8.GetBytes(content)))
									{
										FileManager.Instance.AddFile(folder, fileName, fileContent, true, true, "application/octet-stream");
									}
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                }
            }
            return strMessage;
        }
Beispiel #2
0
        private string ExportModule(int moduleID, string fileName, string folder)
        {
            var strMessage = "";
            if (Module != null)
            {
                if (!String.IsNullOrEmpty(Module.DesktopModule.BusinessControllerClass) && Module.DesktopModule.IsPortable)
                {
                    try
                    {
                        var objObject = Reflection.CreateObject(Module.DesktopModule.BusinessControllerClass, Module.DesktopModule.BusinessControllerClass);

                        //Double-check
                        if (objObject is IPortable)
                        {
                            var content = Convert.ToString(((IPortable)objObject).ExportModule(moduleID));
                            if (!String.IsNullOrEmpty(content))
                            {
                                //add attributes to XML document
                                content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(Module.DesktopModule.ModuleName) + "\" version=\"" +
                                          Module.DesktopModule.Version + "\">" + content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                var objPortalController = new PortalController();
                                var strFile = PortalSettings.HomeDirectoryMapPath + folder + fileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, content.Length))
                                {
                                    //save the file
                                    var objStream = File.CreateText(strFile);
                                    objStream.WriteLine(content);
                                    objStream.Close();

                                    //add file to Files table
            #pragma warning disable 612,618
                                    FileSystemUtils.AddFile(fileName, PortalId, folder, PortalSettings.HomeDirectoryMapPath, "application/octet-stream");
            #pragma warning restore 612,618
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                }
            }
            return strMessage;
        }
Beispiel #3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The CheckDestFolderAccess helper method Checks to make sure file copy/move 
        /// operation will not exceed portal available space
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[DYNST]	        2/1/2004	Created
        ///     [Jon Henning]	11/1/2004	Updated to use ClientAPI/DNNTree
        ///     [cnurse]        12/2/2004   Updated to use Localization
        /// </history>
        /// -----------------------------------------------------------------------------
        public string CheckDestFolderAccess(long intSize)
        {
            if (Request.IsAuthenticated)
            {
                string strDestFolder = PathUtils.Instance.AddTrailingSlash(UnMaskPath(DestPath));
                var objPortalController = new PortalController();

                if (objPortalController.HasSpaceAvailable(FolderPortalID, intSize) || Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                {
                    return "";
                }
                else
                {
                    return Localization.GetString("NotEnoughSpace", LocalResourceFile);
                }
            }
            else
            {
                return Localization.GetString("PleaseLogin", LocalResourceFile);
            }
        }
        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>
        /// 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 static string UploadFile( string RootPath, HttpPostedFile objHtmlInputFile, bool Unzip )
        {
            // Obtain PortalSettings from Current Context
            PortalSettings settings = PortalController.GetCurrentPortalSettings();
            int PortalId = GetFolderPortalId( settings );
            bool isHost = Convert.ToBoolean( ( ( settings.ActiveTab.ParentId == settings.SuperTabId ) ? true : false ) );

            PortalController objPortalController = new PortalController();
            string strMessage = "";
            string strFileName = RootPath + Path.GetFileName( objHtmlInputFile.FileName );
            string strExtension = Path.GetExtension( strFileName ).Replace( ".", "" );
            string strFolderpath = Globals.GetSubFolderPath( strFileName );

            if( objPortalController.HasSpaceAvailable( PortalId, objHtmlInputFile.ContentLength ) )
            {
                string a = "," + settings.HostSettings["FileExtensions"].ToString().ToUpper();
                if( ( a.IndexOf( "," + strExtension.ToUpper(), 0 ) + 1 ) != 0 || isHost )
                {
                    //Save Uploaded file to server
                    try
                    {
                        strMessage += AddFile( PortalId, objHtmlInputFile.InputStream, strFileName, objHtmlInputFile.ContentType, objHtmlInputFile.ContentLength, strFolderpath, true, true );

                        //Optionally Unzip File?
                        if( Path.GetExtension( strFileName ).ToLower() == ".zip" & Unzip )
                        {
                            strMessage += UnzipFile( strFileName, RootPath, settings );
                        }
                    }
                    catch( Exception )
                    {
                        // save error - can happen if the security settings are incorrect
                        strMessage += "<br>" + string.Format( Localization.GetString( "SaveFileError" ), strFileName );
                    }
                }
                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 );
            }

            return strMessage;
        }
		/// <summary>
		/// Validates disk space available
		/// </summary>
		/// <param name="virtualPathAndName">The system path. ie: C:\WebSites\DotNetNuke_Community\Portals\0\sample.gif</param>
		/// <param name="contentLength">Content Length</param>
		/// <returns>The error message or empty string</returns>
		/// <remarks></remarks>
		private object Check_DiskSpace(string virtualPathAndName, long contentLength)
		{
			try
			{
				string fileName = Path.GetFileName(virtualPathAndName);
				PortalController portalCtrl = new PortalController();
				if (! (portalCtrl.HasSpaceAvailable(PortalController.GetCurrentPortalSettings().PortalId, contentLength)))
				{
					return string.Format(Localization.GetString("DiskSpaceExceeded"), ToEndUserPath(virtualPathAndName));
				}
			}
			catch (Exception ex)
			{
				return LogUnknownError(ex, virtualPathAndName, contentLength.ToString());
			}

			return string.Empty;
		}
        /// <summary>
        /// The CheckDestFolderAccess helper method Checks to make sure file copy/move
        /// operation will not exceed portal available space
        /// </summary>
        /// <history>
        /// 	[DYNST]	        2/1/2004	Created
        ///     [Jon Henning]	11/1/2004	Updated to use ClientAPI/DNNTree
        ///     [cnurse]        12/2/2004   Updated to use Localization
        /// </history>
        public string CheckDestFolderAccess( long intSize )
        {
            if( Request.IsAuthenticated )
            {
                FileSystemUtils.AddTrailingSlash( UnMaskPath( DestPath ) );
                PortalController objPortalController = new PortalController();

                if( objPortalController.HasSpaceAvailable( FolderPortalID, intSize ) || ( PortalSettings.ActiveTab.ParentId == PortalSettings.SuperTabId ) )
                {
                    return "";
                }
                else
                {
                    return Localization.GetString( "NotEnoughSpace", this.LocalResourceFile );
                }
            }
            else
            {
                return Localization.GetString( "PleaseLogin", this.LocalResourceFile );
            }
        }