}//public static void ResponseOutputStreamWrite()

        ///<summary>ResponseOutputStreamWrite</summary>
        ///<remarks>MSDNBrasil.com.br/forum/ShowPost.aspx?PostID=91538</remarks>
        public static void ResponseOutputStreamWrite
        (
            ref System.Web.UI.WebControls.FileUpload fileUpload,
            ref string exceptionMessage
        )
        {
            HttpContext httpContext = System.Web.HttpContext.Current;

            byte[] buffer              = null;
            int    bytesRead           = -1;
            int    fileExtensionIndex  = -1;
            string responseContentType = null;
            Stream stream              = null;

            try
            {
                if (httpContext == null)
                {
                    return;
                }
                if (fileUpload.HasFile == false)
                {
                    return;
                }
                responseContentType = httpContext.Response.ContentType;
                fileExtensionIndex  = UtilityFile.FileExtensionIndex(fileUpload.PostedFile.FileName);
                stream = fileUpload.PostedFile.InputStream;
                httpContext.Response.Clear();
                httpContext.Response.AppendHeader("Content-Length", fileUpload.PostedFile.ContentLength.ToString());
                if (fileExtensionIndex > -1)
                {
                    httpContext.Response.ContentType = UtilityFile.FileExtension[fileExtensionIndex][UtilityFile.FileExtensionRankContentType];
                }
                else
                {
                    httpContext.Response.ContentType = UtilityFile.DefaultContentType;
                }
                buffer = new byte[ByteSize];
                while (true)
                {
                    bytesRead = stream.Read(buffer, 0, ByteSize);
                    if (bytesRead <= 0)
                    {
                        break;
                    }
                    httpContext.Response.OutputStream.Write(buffer, 0, buffer.Length);
                } //while ( true )
            }     //try
            catch (Exception exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
            httpContext.Response.End();
            httpContext.Response.ContentType = responseContentType;

            /*
             * httpContext.Server.Transfer( httpContext.Request.ServerVariables["PATH_INFO"] );
             * httpContext.Response.Redirect( httpContext.Request.ServerVariables["PATH_INFO"] );
             */
            httpContext.Server.Transfer(httpContext.Request.ServerVariables["PATH_INFO"]);
        }//public static void ResponseOutputStreamWrite()
示例#2
0
        /// <summary>EternalXml</summary>
        public static void EternalXml
        (
            ref EternalArgument eternalArgument,
            ref string exceptionMessage
        )
        {
            DataSet   dataSet           = null;
            ArrayList databaseName      = null;
            ArrayList sqlStatementUnion = null;
            ArrayList objectName        = null;
            ArrayList ownerName         = null;
            ArrayList unionIndex        = null;
            String    filenameXml       = null;

            try
            {
                UtilityDatabase.DatabaseQuery
                (
                    DatabaseConnectionString,
                    ref exceptionMessage,
                    ref dataSet,
                    eternalArgument.sqlQuery,
                    CommandType.Text
                );
                if (exceptionMessage != null)
                {
                    return;
                }
                ;
                UtilityDatabase.SQLSelectParse
                (
                    eternalArgument.sqlQuery,
                    ref unionIndex,
                    ref sqlStatementUnion,
                    ref databaseName,
                    ref ownerName,
                    ref objectName,
                    ref exceptionMessage
                );
                if (exceptionMessage != null)
                {
                    return;
                }
                ;
                if (dataSet.Tables.Count < 1)
                {
                    return;
                }//if ( dataSet.Tables.Count < 1 )
                dataSet.DataSetName = (String)databaseName[0];
                for (int objectNameCount = 0; objectNameCount < objectName.Count; ++objectNameCount)
                {
                    dataSet.Tables[objectNameCount].TableName = (String)objectName[objectNameCount];
                }//for ( int objectNameCount = 0; objectNameCount < objectName.Count; ++objectNameCount )
                ScriptureReference.ScriptureReferenceURI
                (
                    DatabaseConnectionString,
                    FilenameConfigurationXml,
                    ref exceptionMessage,
                    ref dataSet
                );
                if (exceptionMessage != null)
                {
                    return;
                }
                ;
                if (eternalArgument.date)
                {
                    filenameXml = UtilityFile.DatePostfix(eternalArgument.filenameXml);
                }
                else
                {
                    filenameXml = eternalArgument.filenameXml;
                }
                UtilityXml.WriteXml
                (
                    dataSet,
                    ref exceptionMessage,
                    ref filenameXml,
                    ref eternalArgument.filenameStylesheet
                );
                if (exceptionMessage != null)
                {
                    return;
                }
                ;
            }
            catch (Exception exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
        }
        ///<summary>ResponseOutputStreamWrite</summary>
        ///<remarks>Ben Reichelt DotNetJunkies.com/WebLog/barblog/archive/2005/01/02/40588.aspx Can't stream mp3 file in .net</remarks>
        public static void ResponseOutputStreamWrite
        (
            ref string path,
            ref string exceptionMessage
        )
        {
            HttpContext httpContext = System.Web.HttpContext.Current;

            byte[] buffer             = null;
            int    bytesRead          = -1;
            int    fileExtensionIndex = -1;
            long   fileLength         = -1;
            string filename           = null;

            System.IO.FileInfo   fileInfo   = null;
            System.IO.FileStream fileStream = null;
            try
            {
                if (string.IsNullOrEmpty(path))
                {
                    path = @"D:\Audio\Christian\Junko\Junko_-_AsForMeAndMyHouse.mp3";
                }
                if (File.Exists(path) == false)
                {
                    return;
                }
                fileInfo           = new FileInfo(path);
                filename           = System.IO.Path.GetFileName(path);
                fileExtensionIndex = UtilityFile.FileExtensionIndex(filename);
                fileLength         = fileInfo.Length;
                if (httpContext == null)
                {
                    return;
                }
                httpContext.Response.Buffer = true;
                httpContext.Response.Clear();
                httpContext.Response.ClearContent();
                httpContext.Response.ClearHeaders();
                //httpContext.Response.AddHeader( "Accept-Header", fileLength.ToString() );
                httpContext.Response.AppendHeader("Content-Disposition", "inline; filename=" + httpContext.Server.UrlEncode(filename));
                //httpContext.Response.AddHeader( "Content-Disposition", "attachment;filename=" + filename );

                /*
                 * if ( fileLength > -1 )
                 * {
                 * httpContext.Response.AppendHeader( "Content-Length", fileLength.ToString() );
                 * }
                 */
                //httpContext.Response.WriteFile( path );
                if (fileExtensionIndex > -1)
                {
                    httpContext.Response.ContentType = UtilityFile.FileExtension[fileExtensionIndex][UtilityFile.FileExtensionRankContentType];
                }
                else
                {
                    httpContext.Response.ContentType = UtilityFile.DefaultContentType;
                }
                fileStream = new System.IO.FileStream
                             (
                    path,
                    System.IO.FileMode.Open,
                    System.IO.FileAccess.Read,
                    System.IO.FileShare.ReadWrite
                             );
                buffer = new byte[ByteSize];
                while (true)
                {
                    bytesRead = fileStream.Read(buffer, 0, ByteSize);
                    if (bytesRead <= 0)
                    {
                        break;
                    }
                    httpContext.Response.OutputStream.Write(buffer, 0, buffer.Length);
                    httpContext.Response.Flush();
                } //while ( true )
                fileStream.Close();
            }     //try
            catch (Exception exception) { UtilityException.ExceptionLog(exception, exception.GetType().Name, ref exceptionMessage); }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
            httpContext.Response.End();
        }//public static void ResponseOutputStreamWrite()
示例#4
0
  }//public static void WriteXmlStylesheet()  
  
  ///<summary>Write XML.</summary>
  /// <param name="dataSet">Dataset.</param>  
  /// <param name="exceptionMessage">Exception Message.</param>
  /// <param name="filenameXml">Filename XML.</param>
  /// <param name="filenameStylesheet">Filename Stylesheet (XSLT).</param>
  public static void WriteXml
  (
       DataSet dataSet,
   ref string  exceptionMessage,
   ref string  filenameXml,
   ref string  filenameStylesheet
  )
  { 

   string                    dataSetName                      = null;
   HttpContext               httpContext                      = HttpContext.Current; 
  
   exceptionMessage = null;
   dataSetName      = dataSet.DataSetName;
 
   if ( filenameXml == null )
   {
    filenameXml = dataSetName + UtilityFile.Extension("xml");
   }
   
   if ( filenameStylesheet == null )
   { 
    filenameStylesheet = dataSetName + UtilityFile.Extension("xslt");
   }

   try
   {
    UtilityDirectory.WebServerFullPath( ref filenameXml );

    //dataSet.WriteXmlSchema(filenameSchema);
    dataSet.WriteXml(filenameXml);
    WriteXmlStylesheet
    (
     ref exceptionMessage,
     ref filenameXml,
     ref filenameStylesheet
    );
   }//try
   catch (SecurityException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SecurityException: {0}", exception.Message );
    httpContext.Response.Write( "SecurityException: " + exception.Message );
   }//catch (SecurityException exception)
   catch (XmlException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "XmlException: {0}", exception.Message );
    httpContext.Response.Write( "XmlException: " + exception.Message );
   }//catch (XmlException exception)
   catch (SystemException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SystemException: {0}", exception.Message );
    httpContext.Response.Write( "SystemException: " + exception.Message );
   }//catch (SystemException exception)
   catch (Exception exception)
   {
    exceptionMessage = exception.Message;   
    System.Console.WriteLine( "Exception: {0}", exception.Message );
    httpContext.Response.Write( "Exception: " +  exception.Message );    
   }//catch (Exception exception)
  }//WriteXml()    
示例#5
0
  }//public static void WriteXmlStylesheet()  
  
  ///<summary>Write XML.</summary>
  /// <param name="dataSet">Dataset.</param>  
  /// <param name="exceptionMessage">Exception Message.</param>
  /// <param name="filenameXml">Filename XML.</param>
  /// <param name="filenameStylesheet">Filename Stylesheet (XSLT).</param>
  public static void WriteXml
  (
       DataSet dataSet,
   ref string  exceptionMessage,
   ref string  filenameXml,
   ref string  filenameStylesheet
  )
  { 
   string       dataSetName         =  null;
   string       directoryName       =  null;
   HttpContext  httpContextCurrent  =  HttpContext.Current;
  
   exceptionMessage = null;
   dataSetName      = dataSet.DataSetName;
 
   if ( filenameXml == null )
   {
    filenameXml = dataSetName + UtilityFile.Extension("xml");
   }

   try
   {
    UtilityDirectory.WebServerFullPath( ref filenameXml );
    directoryName = Path.GetDirectoryName( filenameXml );
    if ( directoryName != "" && Directory.Exists( directoryName ) == false )
    {
     Directory.CreateDirectory( directoryName );
    }
    //dataSet.WriteXmlSchema(filenameSchema);
    dataSet.WriteXml(filenameXml);
    if ( string.IsNullOrEmpty( filenameStylesheet ) == false )
    {
     WriteXmlStylesheet
     (
      ref exceptionMessage,
      ref filenameXml,
      ref filenameStylesheet
     );
    }
   }//try
   catch (SecurityException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SecurityException: {0}", exception.Message );
   }//catch (SecurityException exception)
   catch (XmlException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "XmlException: {0}", exception.Message );
   }//catch (XmlException exception)
   catch (SystemException exception)
   {
    exceptionMessage = exception.Message;
    System.Console.WriteLine( "SystemException: {0}", exception.Message );
   }//catch (SystemException exception)
   catch (Exception exception)
   {
    exceptionMessage = exception.Message;   
    System.Console.WriteLine( "Exception: {0}", exception.Message );
   }//catch (Exception exception)
   #if (DEBUG)
    if ( httpContextCurrent != null && exceptionMessage != null )
    {
     httpContextCurrent.Response.Write( "Exception: " + exceptionMessage );
    }//if ( httpContextCurrent != null && exceptionMessage != null )
   #endif
  }//WriteXml()