Esempio n. 1
0
        private void RunRenderMht(IStreamGen sg)
        {
            OneFileStreamGen temp = null;
            FileStream       fs   = null;

            try
            {
                string tempHtmlReportFileName = Path.ChangeExtension(Path.GetTempFileName(), "htm");
                temp = new OneFileStreamGen(tempHtmlReportFileName, true);
                RunRender(temp, OutputPresentationType.HTML);
                temp.CloseMainStream();

                // Create the mht file (into a temporary file position)
                MhtBuilder mhtConverter = new MhtBuilder();
                string     fileName     = Path.ChangeExtension(Path.GetTempFileName(), "mht");
                mhtConverter.SavePageArchive(fileName, "file://" + tempHtmlReportFileName);

                // clean up the temporary files
                foreach (string tempFileName in temp.FileList)
                {
                    try
                    {
                        File.Delete(tempFileName);
                    }
                    catch {}
                }

                // Copy the mht file to the requested stream
                Stream os = sg.GetStream();
                fs = File.OpenRead(fileName);
                byte[] ba = new byte[4096];
                int    rb = 0;
                while ((rb = fs.Read(ba, 0, ba.Length)) > 0)
                {
                    os.Write(ba, 0, rb);
                }
            }
            catch (Exception ex)
            {
                rl.LogError(8, "Error converting HTML to MHTML " + ex.Message +
                            Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                if (temp != null)
                {
                    temp.CloseMainStream();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                _Cache = new RCache();
            }
        }
		/// <summary>
		/// Save the file.  The extension determines the type of file to save.
		/// </summary>
		/// <param name="FileName">Name of the file to be saved to.</param>
		/// <param name="ext">Type of file to save.  Should be "pdf", "xml", "html", "mhtml", "csv", "rtf", "excel", "tif".</param>
		public void SaveAs(string FileName, string type)
		{
			LoadPageIfNeeded();

			string ext = type.ToLower();
			OneFileStreamGen sg = new OneFileStreamGen(FileName, true);	// overwrite with this name
            if (!(ext == "pdf" || ext == "tif" || ext == "tiff" || ext == "tifbw"))
            {
                ListDictionary ld = GetParameters();		// split parms into dictionary
                _Report.RunGetData(ld);                     // obtain the data (again)
            }
			try
			{
				switch(ext)
				{
					case "pdf":	
						_Report.RunRenderPdf(sg, _pgs);
						break;
                    case "tif":
                    case "tiff":
                        _Report.RunRenderTif(sg, _pgs, true);
                        break;
                    case "tifbw":
                        _Report.RunRenderTif(sg, _pgs, false);
                        break;
					case "csv":
						_Report.RunRender(sg, OutputPresentationType.CSV);
						break;
                    case "rtf":
                        _Report.RunRender(sg, OutputPresentationType.RTF);
                        break;
                    case "dmp":
                        _Report.RunRender(sg, OutputPresentationType.DMP);
                        break;
                    case "excel":
                    case "xlsx":
                        _Report.RunRender(sg, OutputPresentationType.Excel);
                        break;
                    case "xml":
                        _Report.RunRender(sg, OutputPresentationType.XML);
                        break;
                    case "html":
                    case "htm":
						_Report.RunRender(sg, OutputPresentationType.HTML);
						break;
					case "mhtml": case "mht":
						_Report.RunRender(sg, OutputPresentationType.MHTML);
						break;
					default:
						throw new Exception("Unsupported file extension for SaveAs");
				}
			}
			finally
			{
				if (sg != null)
				{
					sg.CloseMainStream();
				}

			}
			return;
		}
Esempio n. 3
0
		private void RunRenderMht(IStreamGen sg)
		{
			OneFileStreamGen temp = null;
			FileStream fs=null;
			try
			{
				string tempHtmlReportFileName = Path.ChangeExtension(Path.GetTempFileName(), "htm");
				temp = new OneFileStreamGen(tempHtmlReportFileName, true);
				RunRender(temp, OutputPresentationType.HTML);
				temp.CloseMainStream();

				// Create the mht file (into a temporary file position)
				MhtBuilder mhtConverter = new MhtBuilder();
				string fileName = Path.ChangeExtension(Path.GetTempFileName(), "mht");
				mhtConverter.SavePageArchive(fileName, "file://" + tempHtmlReportFileName);

				// clean up the temporary files
				foreach (string tempFileName in temp.FileList)
				{
					try
					{
						File.Delete(tempFileName);
					}
					catch{}
				}

				// Copy the mht file to the requested stream
				Stream os = sg.GetStream();
				fs = File.OpenRead(fileName);
				byte[] ba = new byte[4096];
				int rb=0;
				while ((rb = fs.Read(ba, 0, ba.Length)) > 0)
				{
					os.Write(ba, 0, rb);
				}
				
			}
			catch (Exception ex)
			{
				rl.LogError(8, "Error converting HTML to MHTML " + ex.Message + 
									Environment.NewLine + ex.StackTrace);
			}
			finally
			{
				if (temp != null)
					temp.CloseMainStream();
				if (fs != null)
					fs.Close();
                _Cache = new RCache();
            }
		}