We help IT Professionals succeed at work.
Get Started

create C# method from code

DB_Fury
DB_Fury asked
on
378 Views
Last Modified: 2013-12-17
i want to make the following code into its own method so i can use it multiple times.  can someone show me how to do that?
ReportViewer rview = new ReportViewer();
        rview.ServerReport.ReportServerUrl = new Uri(WebConfigurationManager.AppSettings["ReportServer"]);

        List<ReportParameter> paramList = new List<ReportParameter>();

        paramList.Add(new ReportParameter("FacilityID", Globals.FacilityID.ToString()));

        rview.ServerReport.ReportServerCredentials = new ReportCredentials("xxxx", "xxxx", "xxxx");
        rview.ServerReport.ReportPath = "/BoardAssessment/AssessmentReport";
        rview.ServerReport.SetParameters(paramList);
        string mimeType, encoding, extension, deviceInfo;
        deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>";
        string[] streamids;

        Warning[] warnings;
        byte[] bytes = rview.ServerReport.Render("Excel", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
        Response.ContentType = "application/Excel";
        Response.AddHeader("Content-disposition", "attachment;filename=BoardAssessment.xls");

        Response.OutputStream.Write(bytes, 0, bytes.Length);
        Response.OutputStream.Flush();
        Response.OutputStream.Close();
        Response.Flush();
        Response.Close();

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE