.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 21st, 2004, 07:37 AM
katerahul katerahul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 katerahul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face Asp.net & Vba

Hello Everybody

I am working on a web based ASP.NET project wherein I am trying to open a user selected word document in the browser window using VB.NET. I have tried the Shell() Command, Tried CreateObject(), also tried using Word.ApplicationClass. After using Word.ApplicationClass I have also done the security settings for the Word.olb file. But I am yet not able to open the file. If I try to do that using the first 2 methods it works in case of WINForms. But not for WebForms. Please Suggest me tha appropriate way of opening word, excel, PDF. Please confirm if I can use OLE Control somehow in ASP.NET
My Code goes somewhat like this

1)My First Approach
THIS WORKS FINE WITH WINFORMS BUT DOESNOT WORK WITH WEBFORMS.
Code:
Dim XLApp As Excel.Application

Dim XLBook As Excel.Workbook

Dim XLsheet As Excel.Worksheet

XLApp = CType(CreateObject("Excel.Application"), Excel.Application)

XLBook = CType(XLApp.Workbooks.Open("C:\Cyber School Docs\RahulKate.xls"), Excel.Workbook)

XLsheet = CType(XLBook.Worksheets(1), Excel.Worksheet)

XLsheet.Application.Visible = True

2)My Second Approach

This also works fine with Winforms using VB.NET but not with Webforms
Code:
Shell("C:\Program Files\Microsoft Office\Office\WINWORD.EXE " & "C:\Rahul1.doc", vbMaximizedFocus)

3) My Third approach

This doesnot work with either.
Code:
Dim MyApp As New Word.ApplicationClass()

Dim FName As String

FName = "C:\Cyber School Docs\Rahul.doc"

Dim MyDoc As New Word.Document()

MyDoc = MyApp.Documents.Open(FName)

MyDoc.Activate()
Kindly Suggest some way of working it out. Its very urgent.

Regards

Rahul

Reply With Quote
  #2  
Old March 4th, 2004, 11:25 PM
adurstew's Avatar
adurstew adurstew is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Charlotte, NC
Posts: 114 adurstew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 33 sec
Reputation Power: 7
Send a message via AIM to adurstew Send a message via Yahoo to adurstew
If you just want them to view it why don't you just binary the file to them and let them IE do the rest? No need to make it complicated.
__________________
Andrew J Durstewitz
ASP.NET,VB.NET,SQL Developer

http://madashellnc.blogspot.com

Reply With Quote
  #3  
Old March 26th, 2004, 03:26 PM
DCKat DCKat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 DCKat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to do something simmilar. Did you ever resolve the issue?

Reply With Quote
  #4  
Old November 1st, 2005, 09:58 AM
Acobar Acobar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: Kansas City
Posts: 1 Acobar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 48 sec
Reputation Power: 0
If you haven't resolved the issue....I was doing this (of course probably not the most efficient way....) I think you're basically just missing excel_workbook.Activate()

note: this is also not cleaned up, I apologize.

Code:
Imports Excel
Imports System.IO
Imports System.Runtime.Serialization

Namespace spread
    <Serializable()> Public Class XlsFile

        
        Private _filename, _
                _client_filepath As String
        Private _file_size As Integer


        Public Property filename() As String
            Get
                Return _filename
            End Get
            Set(ByVal Value As String)
                _filename = Value
            End Set
        End Property

        Public Property client_filepath() As String
            Get
                Return _client_filepath
            End Get
            Set(ByVal Value As String)
                _client_filepath = Value
            End Set
        End Property

        Public Property file_size() As Integer
            Get
                Return _file_size
            End Get
            Set(ByVal Value As Integer)
                _file_size = Value
            End Set
        End Property



        'Public Function GetBinary(ByVal name As String) As FileStream
        '    If (File.Exists("name")) Then
        '        Return New FileStream("name", FileMode.Open, FileAccess.Read, FileShare.Read)
        '    End If
        'End Function

        Public Sub New()
            xls = New Excel.Application
            xls.Visible = False
        End Sub

        Public Sub Close()
            'xls.Workbooks(1).Close(False)
            ReleaseComObject(wb)
            ReleaseComObject(ws)
            ReleaseComObject(xls)
        End Sub

        Public Sub Open(ByRef fi As FileInfo, Optional ByRef isBinary As Boolean = False)
            'myWorkbooks = CType(xls.Workbooks.Open(fileName), Excel.Workbook)
            'myWorksheets = CType(xls.Worksheets(1), Excel.Worksheet)
            If (isBinary) Then
                wb = xls.Workbooks.Open(ConfigurationSettings.AppSettin  gs("binPath") + filename + ".bin")
            Else
                wb = xls.Workbooks.Open(fi.FullName)
            End If
            xls.Visible = True
            wb.Activate()
        End Sub

        Private Sub ReleaseComObject(ByRef ref As Object)
            Try
                Do Until _
                 System.Runtime.InteropServices.Marshal.ReleaseComO  bject(ref) <= 0
                Loop
            Catch
            Finally
                ref = Nothing
            End Try
        End Sub
    End Class
End Namespace


Code:
Imports System.IO
Imports Microsoft.Office

Namespace spread
    Module MainModule
        'Globals
          Public Const GENERAL_EXCEPTION_MESSAGE As String = "An exception has occured: "
        Public Const INVALID_FILE_FORMAT As String = "The file format you attempted to " & _
                            "upload is not a valid format! Only excel file formats are allowed."

        Public excel_file As XlsFile
        Friend xls As Excel.Application = Nothing
        Friend wb As Excel.Workbook = Nothing
        Friend ws As Excel.Worksheet = Nothing
    End Module
End Namespace



Code:

       Private Sub cmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpload.Click
            Dim file As File
            Dim fileName As String = filUpload.PostedFile.FileName.Trim
            Dim fileLength As Integer = 0
            Dim fileContentType As String = Nothing
            Dim uploadSuccess As Boolean = False
            Dim fileExtension As String
            Dim fs As FileStream
            Dim bw As BinaryWriter
            Dim intStatus As Integer
            Dim fi As New FileInfo(fileName)

            Try
                fileLength = filUpload.PostedFile.ContentLength
                fileContentType = filUpload.PostedFile.ContentType

                'validate the file type is acceptable
                If (fileContentType = "application/vnd.ms-excel") Or (fileContentType = "application/octet-stream") Then
                    If file.Exists(fileName + ".bin") Then
                        file.Delete(fileName + ".bin")
                    End If
                    Dim fileContent(fileLength) As Byte
                    excel_file.filename = fi.Name
                    excel_file.client_filepath = fi.FullName
                    excel_file.file_size = filUpload.PostedFile.ContentLength
                    excel_file.Open(fi, False)
                    SerializeFile(excel_file)
                   
                Else
                    lblNotification.Visible = True
                    lblNotification.Text = INVALID_FILE_FORMAT
                End If

            Catch exOra As OracleClient.OracleException
                lblNotification.Text = GENERAL_EXCEPTION_MESSAGE + exOra.Message
                lblNotification.Visible = True
            Catch ex As Exception
                lblNotification.Text = GENERAL_EXCEPTION_MESSAGE + ex.Message
                lblNotification.Visible = True
            Finally
                conn.CloseConnection()
            End Try
        End Sub

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > ASP.NET & VBA


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT