I'm a semi-beginner with c# and am having a problem effectively implementing
a switch statement. I've created an asp.net app that runs a report depending
on which item was selected from a drop down box from a previous page. I
then have an Export button to convert the resultant report into pdf. I have
it working but wanted to stream line the code.
The oStream variable is set with the switch statement. After the switch I
attempt to use the oStream variable but receive and error message that its
unassigned. If I move the code to with each case it works fine. Its as if
the variable is local to the switch and I can't use it outside the statement.
This is probably super-simple to fix, I'm just not sure how to do it. Can
someone tell me where I'm going wrong?
private void cmdExport_Click(object sender, System.EventArgs e)
{
string report = Request.QueryString["report"];
MemoryStream oStream; // Using System.IO
switch(report)
{
case "con004":
oStream = (MemoryStream) rptCon004.ExportToStream(CrystalDecisions.
Shared.ExportFormatType.PortableDocFormat);
break;
case "con012":
oStream = (MemoryStream) rptCon012.ExportToStream(CrystalDecisions.
Shared.ExportFormatType.PortableDocFormat);
break;
case "con020":
oStream = (MemoryStream) rptCon020.ExportToStream(CrystalDecisions.
Shared.ExportFormatType.PortableDocFormat);
break;
case "routeHome":
oStream = (MemoryStream) rptRouteHome.ExportToStream(CrystalDecisions.
Shared.ExportFormatType.PortableDocFormat);
break;
case "emergencyContact":
oStream = (MemoryStream) rptEmergencyContact.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.Portable DocFormat);
break;
default:
break;
}
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200512/1