Export Crystal Report Through CodeBehind

The program below shows how to retrieve all IP addresses of the local machine.

			
                            public static bool ExportReport(ReportDocument crReportDocument, string ExpType,string ExportPath, string filename)
                            {
                              filename = filename + "." + ExpType;
                              if (!Directory.Exists(ExportPath)) 
                              {
                                Directory.CreateDirectory(ExportPath);
                              }
                              DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
                              ExportOptions crExportOptions = crReportDocument.ExportOptions;
                              crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                              crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                              crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
                              switch(ExpType)
                              {
                                case "rtf": 
                                  crExportOptions.ExportFormatType = ExportFormatType.RichText;
                                  break;
                                case "pdf":
                                  crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                                  break;
                                case "doc":
                                  crExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
                                  break;
                                case "xls":
                                  crExportOptions.ExportFormatType = ExportFormatType.Excel;
                                  break;
                                case "rpt":
                                  crExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
                                  break;
                                case "htm":
                                  HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
                                  crExportOptions.ExportFormatType = ExportFormatType.HTML40;
                                  HTML40Formatopts.HTMLBaseFolderName = ExportPath + filename; 
                                  HTML40Formatopts.HTMLFileName = "HTML40.html";
                                  HTML40Formatopts.HTMLEnableSeparatedPages = true;
                                  HTML40Formatopts.HTMLHasPageNavigator = true;
                                  HTML40Formatopts.FirstPageNumber = 1;
                                  HTML40Formatopts.LastPageNumber = 3;
                                  crExportOptions.FormatOptions = HTML40Formatopts;
                                  break;
                              }
                              try
                              {
                                crReportDocument.Export();
                                return true;
                              }
                              catch (Exception err)
                              {
                                return false;
                              }
                            }
                            public static byte[] ExportReportToStream(ReportDocument crReportDocument,ExportFormatType exptype)
                            {
                              Stream st;
                              st = crReportDocument.ExportToStream(exptype);
                              byte[] arr = new byte[st.Length];
                              st.Read(arr,0,(int) st.Length);
                              return arr;
                            }
                            public static string ExportReportToString(ReportDocument crReportDocument)
                            {
                              Stream st;
                              st = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat);
                              byte[] arr = new byte[st.Length];
                              st.Read(arr,0,(int) st.Length);
                              string rep = new UnicodeEncoding().GetString(arr);
                              return rep;
                            }