|
-
Jun 11th, 2007, 05:24 AM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Opening a file in a webpage
I want to know how to open a file using VB in a webpage.
I've created a webpage in Visual Studios 2005 with a treeview. When a user clicks a node of the treeview I want an excel file to open, (in excel).
How do I do this?
When the user selects a treenode the following code runs:
Code:
Sub Select_Change(ByVal sender As Object, ByVal e As EventArgs)
If TreeView1.SelectedNode.Value = "" Then
' A folder is selected, so:
Exit Sub
Else
Dim iPath As String = TreeView1.SelectedNode.Value
If iPath = "0" Then
' The selected node is a folder so:
Exit Sub
Else
' Load the file:
IO.File.Open(iPath, IO.FileMode.Open)
'Shell(iPath, AppWinStyle.MaximizedFocus)
End If
End If
End Sub
(iPath is the full lenght path of the file that I want to load, including .xls)
I've tried: process.start(ipath), but I got an error message saying that process has not been declared.
I tried: Shell(iPath, AppWinStyle.MaximizedFocus) but I got an error message saying that the file does not exist, (but it does, I checked)
And last I tried: IO.File.Open(iPath, IO.FileMode.Open)
This doesn't crash or produce an error message, but it doesn't load the file either.
Can anyone help me?
-
Jun 13th, 2007, 05:07 AM
#2
Thread Starter
Lively Member
Re: [2005] Opening a file in a webpage
After nearly killing myself I finally found a solution to this myself:
Code:
Sub Select_Change(ByVal sender As Object, ByVal e As EventArgs)
If TreeView1.SelectedNode.Value = "" Then
' A folder is selected, so:
Exit Sub
Else
Dim iPath As String = TreeView1.SelectedNode.Value
If iPath = "0" Then ' The selected node is a folder so:
Exit Sub
Else
' Load the file in Excel:
Dim objexcel As New Object
objexcel = CreateObject("Excel.application")
objexcel.Visible = True
objexcel.workbooks.open(iPath)
End If
End If
End Sub
I thought I'd better post the solution in case anyone else has this problem. :P
-
Jun 13th, 2007, 07:34 AM
#3
Re: [RESOLVED] [2005] Opening a file in a webpage
Does this code really opens the selected excel file in the client browser (webpage)? I'm so surprised if it does since it's server side code.
-
Jun 14th, 2007, 04:26 AM
#4
Thread Starter
Lively Member
Re: [RESOLVED] [2005] Opening a file in a webpage
Nah, it opens Excel, then opens a spreadsheet within Excel.
-
Jul 11th, 2007, 12:57 PM
#5
Addicted Member
Re: [RESOLVED] [2005] Opening a file in a webpage
Hi,
I have been trying to do something similar, but haven't seem to get it to work. I felt I should just reply to this post instead of creating a separate one. I have read many posts and then finally found something that appears to be similar to what I want to accomplish. I have tried this approach but it will not display the selected datatable inside of a datagrid because I am confused on the following:
1: How would I be able to display the appropriate data inside of the datatable in a DataGrid based on the value that the user select.
I am able to figure out what node the user has double-clicked. But I need help with displaying the data for the selected datatable.
Here is the code which I have for obtaining the value of the node that the user has selected. Any help would be greatly appreciated. thanks
I am using [VB.NET 2003]
Code:
Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
Dim Node_Value As Integer
'Loop through the entire range and select the
For i As Integer = 0 To 10
If (TreeView1.SelectedNode.Text = i) Then
'
Node_Value = TreeView1.SelectedNode.Text
End If
Next
'''''''
'''''''
'''''''Now display the appropriate datatable that is inside of the Database
'''''''
'''''''
End Sub
Last edited by Srig007; Jul 11th, 2007 at 01:03 PM.
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
|