Friday, September 01, 2006

FIX: VS.NET 2005 Reporting Services Report Designer bug

There's a nasty bug in VS.NET 2k5's Report Designer where if you use the report wizard, the UI will constantly bomb when you switch to preview mode. The solution is to strip all whitespace in the rdl file in the <rd:mdxquery></rd:MdxQuery> tags. This is very painful to do manually (especially on a report with lots of parameters).

Here's some quick code to do this for you (put this on a form with a textbox with the filename, you can use an open file dialog if you want):

if ( textBox1.Text == "" )
{
MessageBox.Show( "Please select a file." );
return;
}

using( StreamReader reader = new StreamReader(
textBox1.Text ) )
{
using ( StreamWriter writer =
new StreamWriter(
textBox1.Text + ".fix" ) )
{
string s = reader.ReadLine();
bool haveStarted = false;
while ( s != null )
{
if (s.IndexOf( "" ) > -1 )
haveStarted = true;

if ( haveStarted )
{
int i = s.IndexOf( "<" );
writer.Write(
s.Substring( i ) );
}
else
{
writer.WriteLine( s );
}
if ( s.IndexOf( "
" ) > -1 )
{
haveStarted = false;
writer.WriteLine();
}
s = reader.ReadLine();
}
writer.Close();
reader.Close();
}
}
FileInfo f = new FileInfo( textBox1.Text );
f.MoveTo( textBox1.Text + ".broke" );
f = new FileInfo( textBox1.Text + ".fix" );
f.MoveTo( textBox1.Text );

No comments: