aspnet page javascript Word/Excel

aspnet page javascript Word/Excel

am 08.04.2008 23:24:33 von David C

I have an intranet aspnet page that uses Attributes.Add to populate an
onclick event in a DataGrid that displays files in a directory. Everything
works fine as far as displaying the file names and creating hyperlinks to
call an ActiveX object in Javascript. The function to open Microsoft Word
works perfectly but the same exact process for Excel does not. I also found
in testing that if I add "file:" to the path then Word and the file open
fine. When I try the same with Excel it tells me it cannot find the name.
Can anyone see what might be wrong?

Below is what shows in the view source of the page:

onclick="openWord('file:\\server\\shared\\FileDocs\\File0902 16\\0009Quarles
and Brady (Misc-No File Num)\\Check Requests - Bad Invoice Dates.doc');"
id="articleList_ctl03_LBtnOpen"
href="javascript:__doPostBack('articleList$ctl03$LBtnOpen',' ')">Word


onclick="openExcel('file:\\server\\shared\\FileDocs\\File090 216\\0009Quarles
and Brady (Misc-No File Num)\\Fileroom Company List.xls');"
id="articleList_ctl04_LBtnOpen"
href="javascript:__doPostBack('articleList$ctl04$LBtnOpen',' ')">Excel


And these are my javascript functions:

function openWord(spath)
{
var wdApp = new ActiveXObject("Word.Application");
wdApp.Visible = 'True';
var wdDoc = wdApp.Documents;
wdDoc.Open(spath);
}
function openExcel(spath)
{
var xlApp = new ActiveXObject("Excel.Application");
xlApp.Visible = 'True';
var wb = xlApp.Workbooks;
wb.Open(spath);
}

Below is my ItemDataBound subroutine:

Protected Sub articleList_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs)
' First, make sure we are NOT on a Header or Footer row
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
Dim strFileName As String =
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Name"))
If Left(strFileName, 1) <> "~" Then
strFileName = Replace(strFileName, Chr(35), "@@")
Dim strNewFile As String = ""
Dim varControl
varControl = e.Item.FindControl("HLFile")
varControl.NavigateURL = "ShowDocs.aspx?doc=" & strFileName
Dim strFullPath As String = strPathPhy & "\" & strFileName
varControl = e.Item.FindControl("LBtnOpen")
Select Case LCase(Right(strFileName, 3))
Case "doc"
strNewFile = Replace(strFullPath, "\", "\\", 3)
strNewFile = Replace(strNewFile, "@@", Chr(35))
varControl.Attributes.Add("onclick",
"openWord('file:\\" & strNewFile & "')")
varControl.Text = "Word"

Case "xls"
strNewFile = Replace(strFullPath, "\", "\\", 3)
strNewFile = Replace(strNewFile, "@@", Chr(35))
varControl.Attributes.Add("onclick",
"openExcel('file:\" & "\" & strNewFile & "')")
varControl.Text = "Excel"

Case Else
varControl.Text = ""

End Select
End If
End If
End Sub