|
ActiveReports for .NET allows developers to save the layout of a report at runtime with the SaveLayout method. However, the overloads for the SaveLayout method use different encoding methods. The SaveLayout(string) method uses UTF-8 encoding. The SaveLayout(stream) method uses UTF-16 encoding. This becomes a problem when loading a report saved with the stream overload if the LoadLayout(stream) is not used. The following code allows both the string and stream overloads to work. private void btnSave_Click() { //Save Report to Stream System.IO.MemoryStream stream = new System.IO.MemoryStream(); ActiveReport1 rpt = new ActiveReport1(); rpt.SaveLayout(stream); stream.Position = 0; System.IO.StreamReader reader = new System.IO.StreamReader(stream); string text = reader.ReadToEnd(); System.IO.StreamWriter writer = System.IO.File.CreateText(Application.StartupPath + @"/report.rpx"); writer.Write(text); writer.Close(); } private void btnLoad_Click() { DataDynamics.ActiveReports.ActiveReport rpt= new DataDynamics.ActiveReports.ActiveReport(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Text.UnicodeEncoding unicodeEncoding = new System.Text.UnicodeEncoding(); System.IO.StreamWriter writer = new System.IO.StreamWriter(stream, unicodeEncoding); StreamReader sr = new StreamReader(Application.StartupPath + @"/report.rpx", System.Text.Encoding.UTF8); string sRPT = sr.ReadToEnd(); sr.Close(); writer.Write(sRPT); writer.Flush(); stream.Position = 0; try { rpt.LoadLayout(stream); rpt.Run(); this.viewer1.Document = rpt.Document; } catch(System.Exception ex) { MessageBox.Show(ex.ToString()); } }
Applies To: ActiveReports for .NET 1.0 ActiveReports for .NET 2.0
|