Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Opening a file in a webpage

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    79

    Resolved [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?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    79

    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

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    79

    Re: [RESOLVED] [2005] Opening a file in a webpage

    Nah, it opens Excel, then opens a spreadsheet within Excel.

  5. #5
    Addicted Member
    Join Date
    Nov 2005
    Posts
    200

    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
  •  



Click Here to Expand Forum to Full Width