Guys,

This must be a quick fix . . .

I am creating an excel file and saving it back to a share on the web server. I was then trying to open this xls file in the browser (response.redirect) so the user could view the results and do a "save as" to their local machine if required. The ability to view the results in the browser window would be best, alternatively I could just bang a button on screen that would then launch the created file (unc path) in excel, but that gets messy.

In the code below, sFile is the string containing the path/filename we save to, then rFile is the UNC path to that file.


Could anybody suggest a solution to this please ?
Thanks
Bob


VB Code:
  1. Dim oExcel As New Excel.Application
  2.         Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
  3.         Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
  4.         Dim oCells As Excel.Range
  5.         Dim sFile As String, sTemplate As String
  6.         sFile = Server.MapPath(Request.ApplicationPath) & "RESULTS\" & CType(Qid, String) & " - " & CType(Session("ReportName"), String) & " RESULTS.xls"
  7.         sTemplate = Server.MapPath(Request.ApplicationPath) & _
  8.           "\HPTResults.xlt"
  9.         Dim rFile As String 'Results File
  10.         rFile = "\\bls2mbr25\RESULTS\" & CType(Qid, String) & " - " & CType(Session("ReportName"), String) & " RESULTS.xls"
  11.  
  12.         oExcel.Visible = False : oExcel.DisplayAlerts = False
  13.  
  14.         'Start a new workbook
  15.         oBooks = oExcel.Workbooks
  16.         oBooks.Open(Server.MapPath(Request.ApplicationPath) & _
  17.         "\HPTResults.xlt") 'Load template
  18.         oBook = oBooks.Item(1)
  19.         oSheets = oBook.Worksheets
  20.         oSheet = CType(oSheets.Item("rawdata"), Excel.Worksheet)
  21.  
  22.         'Do all the data export here.
  23.         'Export Team Answers
  24.         Dim x As Integer
  25.         Dim y As Integer
  26.         Dim range As String
  27.         For x = 0 To Answers.GetUpperBound(0)
  28.             y = x + 2
  29.             range = "A" & y & ":D" & y
  30.             oSheet.Range(range).Value = Answers(x)
  31.         Next
  32.  
  33.         'Export TeamLeader Answers
  34.         For x = 0 To Leader.GetUpperBound(0)
  35.             y = x + 2
  36.             range = "E" & y & ":G" & y
  37.             oSheet.Range(range).Value = Leader(x)
  38.         Next
  39.  
  40.         oSheet.SaveAs(sFile)
  41.         oBook.Close()
  42.  
  43.         'Quit Excel and thoroughly deallocate everything
  44.         oExcel.Quit()
  45.  
  46.         ReleaseComObject(oSheet)
  47.         ReleaseComObject(oSheets) : ReleaseComObject(oBook)
  48.         ReleaseComObject(oBooks) : ReleaseComObject(oExcel)
  49.         oExcel = Nothing : oBooks = Nothing : oBook = Nothing
  50.         oSheets = Nothing : oSheet = Nothing
  51.         System.GC.Collect()
  52.  
  53.         Label7.Text = rFile
  54.         Response.Redirect(rFile) 'Send the user to the file
  55.  
  56.     End Sub