Guys,

Why can't I open this Excel file ? It does exist, it is in the correct folder !

When my code comes to open the file, firstly I have to login to the server ? Then I get the following error . . .

'\\bls2mbr25\HPT\HPTResults.xlt' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.

I have posted the full text of the error below, and also my code module !

Any help please !!!
Thanks
bob


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: '\\bls2mbr25\HPT\HPTResults.xlt' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[COMException (0x800a03ec): '\\bls2mbr25\HPT\HPTResults.xlt' could not be found. Check the spelling of the file name, and verify that the file location is correct.

If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.]
Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
HPT.HPTReports.btn_excel_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\HPT\HPTReports.aspx.vb:217
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277

VB Code:
  1. Private Sub btn_excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_excel.Click
  2.  
  3.        
  4.         'Get data into datatable.
  5.         Dim Qid As Integer = CInt(Session("QID"))
  6.         Dim filename As String = "\\bls2mbr25\HPT\RESULTS\" & CType(Qid, String) & " - " & CType(Session("ReportName"), String) & " RESULTS ANALYSIS.xls"
  7.         Dim cnn As New SqlConnection("Data Source=BLS5TEST2;Initial Catalog=HPT;User Id=HPT;Password=kibby1;")
  8.         Dim cmd As New SqlDataAdapter("SELECT * FROM vw_answers WHERE Qid = '" & Qid & "' and Staffname <> '" & User.Identity.Name & "'", cnn)
  9.         Dim tlcmd As New SqlDataAdapter("SELECT * FROM vw_answers WHERE Qid = '" & Qid & "' and Staffname = '" & User.Identity.Name & "'", cnn)
  10.  
  11.  
  12.         'Fill the dataset here.
  13.         Dim ds As New DataSet
  14.         cmd.Fill(ds, "TeamAnswers")
  15.         tlcmd.Fill(ds, "LeaderAnswers")
  16.  
  17.         Dim RowNbr As Int32 = 0
  18.         Dim Answers(ds.Tables(0).Rows.Count) As Object
  19.         Dim Leader(ds.Tables(1).Rows.Count) As Object
  20.  
  21.         'get Teamanswers into array
  22.         For Each Rw As DataRow In ds.Tables(0).Rows
  23.             Answers(RowNbr) = Rw.ItemArray()
  24.             RowNbr += 1
  25.         Next Rw
  26.  
  27.         'get Leaderanswers into array
  28.         RowNbr = 0
  29.         For Each lRw As DataRow In ds.Tables(1).Rows
  30.             Leader(RowNbr) = lRw.ItemArray()
  31.             RowNbr += 1
  32.         Next lRw
  33.  
  34.         'Get data into EXCEL
  35.         Dim xl As Excel.Application
  36.         Try
  37.             xl = GetObject(, "Excel.Application")
  38.         Catch ex As Exception
  39.             xl = New Excel.Application
  40.         End Try
  41.  
  42.         Dim wkbk As Excel.Workbook
  43.         Dim wkst As Excel.Worksheet
  44.         Dim wksttl As Excel.Worksheet
  45.  
  46.         xl.Visible = False
  47.         xl.DisplayAlerts = False
  48.  
  49.        
  50.         'wkbk = xl.Workbooks.Open(Server.MapPath(Request.ApplicationPath) & "\\bls2mbr25\HPT\HPT Questionnaire Results.xlt")
  51.         wkbk = xl.Workbooks.Open("\\bls2mbr25\HPT\HPTResults.xlt")
  52.         wkst = wkbk.Sheets("rawdata")
  53.  
  54.         'Export Team Answers
  55.         Dim x As Integer
  56.         Dim y As Integer
  57.         Dim range As String
  58.         For x = 0 To Answers.GetUpperBound(0)
  59.             y = x + 2
  60.             range = "A" & y & ":D" & y
  61.             wkst.Range(range).Value = Answers(x)
  62.         Next
  63.  
  64.         'Export TeamLeader Answers
  65.         For x = 0 To Leader.GetUpperBound(0)
  66.             y = x + 2
  67.             range = "E" & y & ":G" & y
  68.             wkst.Range(range).Value = Leader(x)
  69.         Next
  70.  
  71.         'Tidy up
  72.         Answers = Nothing
  73.         Leader = Nothing
  74.         ds.Dispose()
  75.         ds = Nothing
  76.  
  77.         wkbk.Sheets(1).activate()
  78.  
  79.         wkbk.SaveAs(filename)
  80.         xl.DisplayAlerts = True
  81.         xl.Quit()
  82.  
  83.         ReleaseComObject(wkst)
  84.         ReleaseComObject(wkbk)
  85.         ReleaseComObject(xl)
  86.         xl = Nothing : wkst = Nothing : wkbk = Nothing
  87.         System.GC.Collect()
  88.  
  89.         'Send the user to the file
  90.         Response.Redirect(filename)
  91.  
  92.     End Sub