J
Julia B
Hi
I've got an application where users can select some files to view in the
browser. The files are either .doc or .csv files.
The .doc files open in the browser in Word, but I get an error if I try and
open the .csv file using Excel - the error is that both the contents of the
file and the contents of the current webpage are displayed in the Excel
window. It's very strange. I just can't get the .csv file to open correctly.
Anyone any clues? Here's the code:
Private Sub SearchGrid_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
SearchGrid.RowCommand
Dim index As Integer
Dim selectedRow As GridViewRow
Dim filePath As String
If e.CommandName = "OrigRecord" Or e.CommandName = "OrigReport" Then
'if the user has selected to open the original record
'get the selected row
index = Convert.ToInt32(e.CommandArgument)
selectedRow = Me.SearchGrid.Rows(index)
Response.Clear()
Response.ClearHeaders()
'now get the record name
If e.CommandName = "OrigRecord" Then
filePath = selectedRow.Cells(9).Text
filePath = Global.Global_asax.calRecordFilePath & filePath
Response.AppendHeader("Content-Disposition",
"attachment;filename=" & filePath)
Response.ContentType = "application/vnd.ms-excel"
Else
filePath = selectedRow.Cells(10).Text
filePath = Global.Global_asax.calReportFilePath & filePath
Response.AppendHeader("Content-Disposition",
"attachment;filename=" & filePath)
Response.ContentType = "application/msword"
End If
'now we've got the full path for the file, open it
Response.TransmitFile(filePath)
Response.Buffer = False
Else
'do nothing
End If
End Sub
Note: the user selects the file open option in a gridview from a command
button, if that makes any difference and the gridview is in a content page in
a master page.
Thanks in advance.
Julia
I've got an application where users can select some files to view in the
browser. The files are either .doc or .csv files.
The .doc files open in the browser in Word, but I get an error if I try and
open the .csv file using Excel - the error is that both the contents of the
file and the contents of the current webpage are displayed in the Excel
window. It's very strange. I just can't get the .csv file to open correctly.
Anyone any clues? Here's the code:
Private Sub SearchGrid_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
SearchGrid.RowCommand
Dim index As Integer
Dim selectedRow As GridViewRow
Dim filePath As String
If e.CommandName = "OrigRecord" Or e.CommandName = "OrigReport" Then
'if the user has selected to open the original record
'get the selected row
index = Convert.ToInt32(e.CommandArgument)
selectedRow = Me.SearchGrid.Rows(index)
Response.Clear()
Response.ClearHeaders()
'now get the record name
If e.CommandName = "OrigRecord" Then
filePath = selectedRow.Cells(9).Text
filePath = Global.Global_asax.calRecordFilePath & filePath
Response.AppendHeader("Content-Disposition",
"attachment;filename=" & filePath)
Response.ContentType = "application/vnd.ms-excel"
Else
filePath = selectedRow.Cells(10).Text
filePath = Global.Global_asax.calReportFilePath & filePath
Response.AppendHeader("Content-Disposition",
"attachment;filename=" & filePath)
Response.ContentType = "application/msword"
End If
'now we've got the full path for the file, open it
Response.TransmitFile(filePath)
Response.Buffer = False
Else
'do nothing
End If
End Sub
Note: the user selects the file open option in a gridview from a command
button, if that makes any difference and the gridview is in a content page in
a master page.
Thanks in advance.
Julia