Walkthroughs Copyright © 2004 Business Objects Page 414 10. From the Properties window: Set the ID to "display" Set the Text to "Display Report" 11. From the File menu, click Save All. To create and configure a DropDownList Control and Button Control on the Windows Form 1. Open the Windows form. 2. From the View menu, click Designer. 3. From the Toolbox, drag a ComboBox control to the web form. Place the control above the CrystalReportViewer control. Note If a Smart Task appears on the ComboBox (when using Visual Studio 2005), press Esc to close it. 4. Click on the ComboBox control to select it. 5. From the Properties window, set the Name to "reportsList" 6. From the Toolbox, drag a Button control to the right of the ComboBox control. 7. Click the Button control to select it. 8. From the Properties window: Set the Name to "display" Set the Text to "Display Report" 9. From the File menu, click Save All. In the next step, you write code to automatically populate the DropDownList or ComboBox control. Adding a Helper Method to Access Crystal Reports Web Services In this section, you create a helper method that will access a server through Crystal Reports web services and generate a list of reports. Note This procedure requires access to a machine that has been configured to use Crystal Reports web services. Before proceeding, please ensure that your machine has been configured correctly. To create a Helper Method to Access Crystal Reports Web Services 1. Open the Web or Windows form. 2. From the View menu, click Code. 3. Add three private class level variables. [Visual Basic] Private myServerFileReport As ServerFileReport Private myReportManagerRequest As ReportManagerRequest Private myServerFileReportManagerProxy As ServerFileReportManagerProxy [end] [C#] Walkthroughs Copyright © 2004 Business Objects Page 415 private ServerFileReport serverFileReport; private ReportManagerRequest reportManagerRequest; private ServerFileReportManagerProxy serverFileReportManagerProxy; [end] 4. Create a new private helper method that returns an ArrayList . [Visual Basic] Protected Function getReports() As ArrayList End Function [end] [C#] protected ArrayList getReports() { } [end] 5. Inside of the helper method, instantiate a new ServerFileReport instance. [Visual Basic] myServerFileReport = New ServerFileReport() [end] [C#] serverFileReport = new ServerFileReport(); [end] 6. Set the ReportPath property of the ServerFileReport instance to a null string. [Visual Basic] myServerFileReport.ReportPath = "" [end] [C#] serverFileReport.ReportPath = ""; [end] 7. Set the WebServiceURL property of the ServerFileReport to the viewer's virtual directory for your installed version of Crystal Reports, see Appendix: Viewers' Virtual Directory. In this sample code, the viewers' virtual directory is configured for Crystal Reports for Visual Studio 2005. [Visual Basic] myServerFileReport.WebServiceUrl = "http://localhost:80/CrystalReportsWebServices2005/serverfilereportserv ice.asmx" [end] [C#] Walkthroughs Copyright © 2004 Business Objects Page 416 serverFileReport.WebServiceUrl = "http://localhost:80/CrystalReportsWebServices2005/serverfilereportserv ice.asmx"; [end] Note This tutorial assumes that your report server is your local machine, thus you use http://localhost:80/ as the Web Service URL. In order to use a different machine as your report server, replace http://localhost:80/ with the address and port number of your report server. 8. Instantiate a new ReportManagerRequest instance. [Visual Basic] myReportManagerRequest = New ReportManagerRequest() [end] [C#] reportManagerRequest = new ReportManagerRequest(); [end] 9. Assign the result of the GetExtraData method of the serverFileReport instance to the ExtraData property of the ReportManagerRequest instance. This sets the ExtraData property to the Web Service URL. [Visual Basic] myReportManagerRequest.ExtraData = myServerFileReport.GetExtraData() [end] [C#] reportManagerRequest.ExtraData = serverFileReport.GetExtraData(); [end] 10. Assign the result of the ToUri method of the serverFileReport instance to the ParentUri property of the ReportManagerRequest instance. This identifies the directory on the server machine that contains the reports to be listed. [Visual Basic] myReportManagerRequest.ParentUri = myServerFileReport.ToUri() [end] [C#] reportManagerRequest.ParentUri = serverFileReport.ToUri(); [end] 11. Instantiate a new ServerFileReportManagerProxy instance. [Visual Basic] myServerFileReportManagerProxy = New ServerFileReportManagerProxy() [end] [C#] serverFileReportManagerProxy = new ServerFileReportManagerProxy(); [end] Walkthroughs Copyright © 2004 Business Objects Page 417 12. Set the Url property of the ServerFileReportManagerProxy to the Server File Report Manager for your installed version of Crystal Reports, see Appendix: Viewers' Virtual Directory. In this sample code, the viewers' virtual directory is configured for Crystal Reports for Visual Studio 2005. [Visual Basic] myServerFileReportManagerProxy.Url = "http://localhost:80/CrystalReportsWebServices2005/serverfilereportmana ger.asmx" [end] [C#] serverFileReportManagerProxy.Url = "http://localhost:80/CrystalReportsWebServices2005/serverfilereportmana ger.asmx"; [end] 13. Create and instantiate a new ReportManagerResponse object. [Visual Basic] Dim myReportManagerResponse As ReportManagerResponse = new ReportManagerResponse() [end] [C#] ReportManagerResponse reportManagerResponse = new ReportManagerResponse(); [end] 14. Call the ListChildObjects() method of the serverFileReportManagerProxy instance and assign the result to the ReportManagerResponse instance. The ListChildObjects method returns a list of files located on the report server. [Visual Basic] myReportManagerResponse = myServerFileReportManagerProxy.ListChildObjects(myReportManagerRequest) [end] [C#] reportManagerResponse = serverFileReportManagerProxy.ListChildObjects(reportManagerRequest); [end] 15. Create and instantiate a new ArrayList . [Visual Basic] Dim myRemoteReports As ArrayList = New ArrayList() [end] [C#] ArrayList remoteReports = new ArrayList(); [end] Walkthroughs Copyright © 2004 Business Objects Page 418 16. Next, create a For Each loop that loops through each element of reportManagerResponse . [Visual Basic] For Each myReportUriString As String In myReportManagerResponse.ReportUris Next [end] [C#] foreach (string reportUriString in reportManagerResponse.ReportUris) { } [end] 17. Inside of the For Each loop, create a new instance of serverFileReport . [Visual Basic] myServerFileReport = New ServerFileReport() [end] [C#] serverFileReport = new ServerFileReport(); [end] 18. Set the serverFileReport Uri to the value of reportUriString . [Visual Basic] myServerFileReport = ServerFileReport.FromUri(myReportUriString) [end] [C#] serverFileReport = ServerFileReport.FromUri(reportUriString); [end] 19. Still inside of the For Each loop, create an If conditional block that verifies that the ObjectType property of the ServerFileReport is of type REPORT. Note The ListChildObjects method will return both directories and reports. In this tutorial you will filter the list of objects for report files. [Visual Basic] If (myServerFileReport.ObjectType = EnumServerFileType.REPORT) Then End If [end] [C#] if (serverFileReport.ObjectType == EnumServerFileType.REPORT) { } [end] Walkthroughs Copyright © 2004 Business Objects Page 419 20. Inside of the If conditional block, add the reportUriString instance to the remoteReport ArrayList . [Visual Basic] myRemoteReports.Add(myReportUriString) [end] [C#] remoteReports.Add(reportUriString); [end] 21. Finally, outside of the For Each loop, return the remoteReports ArrayList . [Visual Basic] Return myRemoteReports [end] [C#] return remoteReports; [end] 22. From the File menu, click Save All. In the next step, you write code to automatically populate the DropDownList or ComboBox control with a list of reports. For a Web Site, continue to Populating the DropDownList Control in a Web Site. For a Windows Project, continue to Populating the ComboBox Control in a Windows Project. Populating the DropDownList Control in a Web Site In this section, you write code to populate a DropDownList control with a list of non-embedded reports. You will use the getReports() helper method to generate a list of reports from Crystal Reports web services and then bind this list to the DropDownList control. For a Windows Project, see Populating the ComboBox Control in a Windows Project. Populating the DropDownList Control in a Web Site In this procedure, you populate a sorted list of reports using Crystal Reports Web Services. 1. Open the Web Form. 2. From the View menu, click Code. 3. Above the class signature, add an "Imports"[Visual Basic] or "using"[C#] declaration to the top of the class for the System.IO and System.Collections namespaces. [Visual Basic] Imports System.IO Imports System.Collections [end] [C#] Walkthroughs Copyright © 2004 Business Objects Page 420 using System.IO; using System.Collections; [end] 4. Within the page_load() event handler, create a Not IsPostBack conditional block. [Visual Basic] If Not IsPostBack Then Else End If [end] [C#] if(!IsPostBack) { } else { } [end] Note The Not IsPostBack conditional block is used to encapsulate code that should only be run the first time the page loads. Controls are typically bound to data values within Not IsPostBack conditional blocks so that their data values (and any subsequent control events) are not reset during page reloads. 5. Inside of the If block, use the getReports() helper method to retrieve the list of reports from the Web Service. Assign the result to an ArrayList. [Visual Basic] Dim myReports As ArrayList = getReports() [end] [C#] ArrayList reports = getReports(); [end] 6. On the next line, instantiate the SortedList class and pass it to its parent interface, IDictionary . [Visual Basic] Dim mySortedList As IDictionary = New SortedList [end] [C#] IDictionary sortedList = new SortedList(); [end] 7. Next, create a For Each loop that loops through each element of reports . [Visual Basic] For Each myPath As String In myReports Walkthroughs Copyright © 2004 Business Objects Page 421 Next [end] [C#] foreach (string path in reports) { } [end] 8. The next block of code uses string manipulation methods to remove the file path from the name of each report and replace escape characters with string literals. Insert these lines inside of the For Each loop. [Visual Basic] Dim myReportNamePrefix As Integer = myPath.LastIndexOf("/") + 1 Dim myReportNameSufix As Integer = myPath.LastIndexOf("?") Dim myReportNameLength As Integer = myReportNameSufix - myReportNamePrefix Dim myReportName As String = myPath.Substring(myReportNamePrefix, myReportNameLength) reportName = reportName.Replace("%20", " ") [end] [C#] int reportNamePrefix = path.LastIndexOf(@"/") + 1; int reportNameSufix = path.LastIndexOf(@"?"); int reportNameLength = reportNameSufix - reportNamePrefix; string reportName = path.Substring(reportNamePrefix, reportNameLength); myReportName = myReportName.Replace("%20", " "); [end] 9. Still inside the For Each loop, add a line of code that adds the truncated report name to the sortedList IDictionary. [Visual Basic] mySortedList.Add(myPath, myReportName) [end] [C#] sortedList.Add(path, reportName); [end] Binding the Sorted List to the DropDownList Control In this section, you learn how to bind the IDictionary data source to the DropDownList control. First, you define a relationship between the elements of the IDictionary collection and the DropDownList fields. Then, you bind the IDictionary data source to the DropDownList control. 1. Outside of the For Each loop, add code to assign the Value field of the DropDownList to the key property of the sortedList instance. Walkthroughs Copyright © 2004 Business Objects Page 422 [Visual Basic] reportsList.DataTextField = "value" [end] [C#] reportsList.DataTextField = "value"; [end] 2. Next, assign the Value field of the DropDownList control to the key property of the sortedList instance. [Visual Basic] reportsList.DataValueField = "key" [end] [C#] reportsList.DataValueField = "key"; [end] 3. Assign the SortedList instance to the dataSource property of the DropDownList control. [Visual Basic] reportsList.DataSource = mysortedList [end] [C#] reportsList.DataSource = sortedList; [end] 4. Finally, bind the data source to the DropDownList . [Visual Basic] reportsList.DataBind() [end] [C#] reportsList.DataBind(); [end] You have now completed the contents of the If Not IsPostBack conditional block. In the next section, you will write code inside of the Else conditional block to define what happens if the page is refreshed without assigning a new value to the ServerFileReport instance. 5. Inside of the else statement, assign the ServerFileReport instance to the report that is currently held in session. [Visual Basic] myServerFileReport = CType(Session("myServerFileReport"), ServerFileReport) [end] [C#] serverFileReport = (ServerFileReport)Session["serverFileReport"]; [end] Walkthroughs Copyright © 2004 Business Objects Page 424 4. Within the Form1_Load event handler, use the getReports() helper method to retrieve the list of reports from the Web Service. Assign the result to the reports array. [Visual Basic] Dim myReports As ArrayList = getReports() [end] [C#] ArrayList reports = getReports(); [end] 5. On the next line, instantiate an ArrayList object. [Visual Basic] Dim myArrayList As ArrayList = New ArrayList() [end] [C#] ArrayList arrayList = new ArrayList(); [end] 6. Next, create a For Each loop that loops through each element of reports . [Visual Basic] For Each myPath As String In myReports Next [end] [C#] foreach (string path in reports) { } [end] 7. The next block of code uses string manipulation methods to remove the file path from the name of each report and replace escape characters with string literals. Insert these lines inside of the For Each loop. [Visual Basic] Dim myReportNamePrefix As Integer = myPath.LastIndexOf("/") + 1 Dim myReportNameSufix As Integer = myPath.LastIndexOf("?") Dim myReportNameLength As Integer = myReportNameSufix - myReportNamePrefix Dim myReportName As String = myPath.Substring(myReportNamePrefix, myReportNameLength) myReportName = myReportName.Replace("%20", " ") [end] [C#] int reportNamePrefix = path.LastIndexOf(@"/") + 1; int reportNameSufix = path.LastIndexOf(@"?"); [...]... that Uses Crystal Reports for Visual Studio NET 2002 or 2003 Merge Modules Deployment Copyright © 2004 Business Objects Page 444 Walkthroughs Migrating a Project that Uses Crystal Reports for Visual Studio NET 2002 or 2003 Merge Modules Deployment To migrate a project that uses Crystal Reports for Visual Studio NET 2002 or 2003 from Merge Modules deployment to Crystal Reports for Visual Studio 2005 Windows... Windows application or Web Site that uses Crystal Reports for Visual Studio NET 2002 or 2003 to a Visual Studio 2005 project Then, create a new setup project to deploy the Windows application or Web Site Finally, use the msi Windows Installer file to deploy your application To convert a Visual Studio NET 2002 or 2003 project to a Visual Studio 2005 project 1 In Visual Studio, on the File menu, point to Open... setup project: For a Web Site, see Creating a new Web Site Deployment Project with Windows Installer For a Windows Application, Creating a new Windows Application Deployment Project with Windows Installer Copyright © 2004 Business Objects Page 445 Walkthroughs Crystal Reports For Visual Studio 2005 Deployment Tutorial: Migrating a Project that Uses Crystal Reports for Visual Studio 2005 Merge Modules... Creating and Binding a Report In this section, you create a Crystal report that binds to a CrystalReportViewer control To set up a Windows project in Crystal Reports for Visual Studio 2005 1 Launch Visual Studio 2005 2 From the File menu, select New, and then click Project 3 In the New Project dialog box, select a language folder for C# or Visual Basic from the Project Types list 4 From the Templates... for Visual Studio 2005 Merge Modules Deployment Copyright © 2004 Business Objects Page 446 Walkthroughs Migrating a Project that Uses Crystal Reports for Visual Studio 2005 Merge Modules Deployment To migrate an existing project that uses Crystal Reports for Visual Studio 2005 from Merge Modules deployment to Windows Installer deployment, follow the instructions in this section First, remove the merge... application that uses Crystal Reports for Visual Studio 2005 Then, add output files that are necessary for the application to run Finally, you build the installer files that will deploy your Windows application Creating a Setup Project for Windows Applications In this section, you create a Setup Project for Windows Applications from the deployment projects that are available in Visual Studio You need to... reportsList [Visual Basic] myServerFileReport.ReportPath = "\" + reportsList.SelectedItem.ToString [end] [C#] serverFileReport.reportPath = @"\" + reportsList.selectedItem.toString(); [end] 6 Set the WebServiceUrl property of the ServerFileReport instance to the location of serverfilereportservice.asmx [Visual Basic] myServerFileReport.WebServiceUrl = "http://localhost :80 /CrystalReportsWebServices2005/serverfilereportserv... Project/Solution… 2 Select the Visual Studio NET 2002 or 2003 Windows application or Web Site, and click Open The Visual Studio Conversion Wizard opens 3 Follow the steps Visual Studio Conversion Wizard and click Finish to convert the project to Visual Studio 2005 To create a new setup project 1 In Solution Explorer, right-click an existing setup project, and click Remove Repeat this step for any other existing... the setup Copyright © 2004 Business Objects Page 447 Walkthroughs Crystal Reports For Visual Studio 2005 Deployment Tutorial: Performing a Silent Installation with a Windows Installer Copyright © 2004 Business Objects Page 4 48 Walkthroughs Performing a Silent Installation with a Windows Installer With a Windows Installer you can perform a silent installation on a client machine A silent installation... "http://localhost :80 /CrystalReportsWebServices2005/serverfilereportserv ice.asmx" [end] [C#] serverFileReport.WebServiceUrl = "http://localhost :80 /CrystalReportsWebServices2005/serverfilereportserv ice.asmx"; [end] 7 For a Web Site, assign the report into Session, using the report variable name as the Session identifier string [Visual Basic] Session("ServerFileReport") = myServerFileReport [end] [C#] Session["ServerFileReport"] = serverFileReport; 8 Set . Crystal Reports For Visual Studio 2005 Deployment Tutorials Walkthroughs Copyright © 2004 Business Objects Page 433 Crystal Reports For Visual Studio 2005 . section, you create a Crystal report that binds to a CrystalReportViewer control. To set up a Windows project in Crystal Reports for Visual Studio 2005 1. Launch Visual Studio 2005. 2. From the. configured for Crystal Reports for Visual Studio 2005. [Visual Basic] myServerFileReport.WebServiceUrl = "http://localhost :80 /CrystalReportsWebServices2005/serverfilereportserv ice.asmx"