|
-
Aug 21st, 2005, 07:47 AM
#1
Thread Starter
Fanatic Member
Why won't this file open ?
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:
Private Sub btn_excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_excel.Click
'Get data into datatable.
Dim Qid As Integer = CInt(Session("QID"))
Dim filename As String = "\\bls2mbr25\HPT\RESULTS\" & CType(Qid, String) & " - " & CType(Session("ReportName"), String) & " RESULTS ANALYSIS.xls"
Dim cnn As New SqlConnection("Data Source=BLS5TEST2;Initial Catalog=HPT;User Id=HPT;Password=kibby1;")
Dim cmd As New SqlDataAdapter("SELECT * FROM vw_answers WHERE Qid = '" & Qid & "' and Staffname <> '" & User.Identity.Name & "'", cnn)
Dim tlcmd As New SqlDataAdapter("SELECT * FROM vw_answers WHERE Qid = '" & Qid & "' and Staffname = '" & User.Identity.Name & "'", cnn)
'Fill the dataset here.
Dim ds As New DataSet
cmd.Fill(ds, "TeamAnswers")
tlcmd.Fill(ds, "LeaderAnswers")
Dim RowNbr As Int32 = 0
Dim Answers(ds.Tables(0).Rows.Count) As Object
Dim Leader(ds.Tables(1).Rows.Count) As Object
'get Teamanswers into array
For Each Rw As DataRow In ds.Tables(0).Rows
Answers(RowNbr) = Rw.ItemArray()
RowNbr += 1
Next Rw
'get Leaderanswers into array
RowNbr = 0
For Each lRw As DataRow In ds.Tables(1).Rows
Leader(RowNbr) = lRw.ItemArray()
RowNbr += 1
Next lRw
'Get data into EXCEL
Dim xl As Excel.Application
Try
xl = GetObject(, "Excel.Application")
Catch ex As Exception
xl = New Excel.Application
End Try
Dim wkbk As Excel.Workbook
Dim wkst As Excel.Worksheet
Dim wksttl As Excel.Worksheet
xl.Visible = False
xl.DisplayAlerts = False
'wkbk = xl.Workbooks.Open(Server.MapPath(Request.ApplicationPath) & "\\bls2mbr25\HPT\HPT Questionnaire Results.xlt")
wkbk = xl.Workbooks.Open("\\bls2mbr25\HPT\HPTResults.xlt")
wkst = wkbk.Sheets("rawdata")
'Export Team Answers
Dim x As Integer
Dim y As Integer
Dim range As String
For x = 0 To Answers.GetUpperBound(0)
y = x + 2
range = "A" & y & ":D" & y
wkst.Range(range).Value = Answers(x)
Next
'Export TeamLeader Answers
For x = 0 To Leader.GetUpperBound(0)
y = x + 2
range = "E" & y & ":G" & y
wkst.Range(range).Value = Leader(x)
Next
'Tidy up
Answers = Nothing
Leader = Nothing
ds.Dispose()
ds = Nothing
wkbk.Sheets(1).activate()
wkbk.SaveAs(filename)
xl.DisplayAlerts = True
xl.Quit()
ReleaseComObject(wkst)
ReleaseComObject(wkbk)
ReleaseComObject(xl)
xl = Nothing : wkst = Nothing : wkbk = Nothing
System.GC.Collect()
'Send the user to the file
Response.Redirect(filename)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|