Lanciare windows application da una webform

lunedì 26 gennaio 2004 - 14.53

jordi75 Profilo | Junior Member

Ciao a tutti!!!
Ho creato una windows application che, quando lanciata, crea un documento word di stampaunione e lo salva in un path predefinito.
Se uso direttamente la windows application funziona tutto perfettamente.

Ho quindi creato una web form nella mia web application con un pulsante che mi lancia la windows application.Quest'ultima, da quello che ho capito, funziona in background, e infatti nel task manager vedo il processo attivo con utente Network service.
Il problema è che non mi salva il documento word, e ho notato che winword non è presente tra i processi.
Forse ci sono problemi a lanciare word?
Quello che vorrei ottenere è che l'utente lanci la windows application sul server e crei il documento che poi gli renderò disponibile tramite un link.

Grazie dell'aiuto!!!

Brainkiller Profilo | Guru

Ciao l'utente Network Service è un utente particolare e fra l'altro mi pare ci sia solo su Windows 2003, stai usando quello tu? o mi sto sbagliando io ?
Altra cosa, che versione di Office stai utilizzando ?

Non pensi sia più conveniente usare le librerie Office PIAs piuttosto che lanciare una App WinForms esterna ??

ciao
david

jordi75 Profilo | Junior Member

sto usando windows server 2003 e office xp.
Scusa l'ignoranza, ma cosa sono le librerie office PIAs?
Stavo anche provando a creare una dll, ma è la prima volta che lo faccio e non so cosa sto combinando...
Un'altro tentativo che avevo fatto era di scrivere lo stesso codice usato nella win app, in una web app...il risultato è stato un errore del tipo cannot create activex component.
Non vorrei ricevere lo stesso errore una volta creata la dll.

Riporto il codice del file amsx usato per creare la dll se può servire. Una volta che creo un oggetto di tipo modulo e applico il metodo funcmodulo mi dà errore di object refernce not set to an istance of an object.

Imports System.Web.Services

<WebService(Namespace:="modulo")> _
Public Class modulo
Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

Public Sub New()
MyBase.New()

'This call is required by the Web Services Designer.
InitializeComponent()

'Add your own initialization code after the InitializeComponent() call

End Sub

'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

#End Region

<WebMethod()> Public Function funcmoduli(ByVal id As Integer)

Dim wrdApp As Word.ApplicationClass
Dim wrdDoc As Word._Document
Dim wrdDoc1 As Word._Document
Dim indice As Integer
indice = id

Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeFields

Dim StrToAdd As String

' Create an instance of Word and make it visible.
wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True


' Add a new document.

wrdDoc = wrdApp.Documents.Open("\\SISERVER\wwwroot$\prove\moduli\Primo campo.doc")

wrdDoc.Select()

wrdSelection = wrdApp.Selection()
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.



wrdMailMerge.Execute(True)


wrdApp.ActiveDocument.SaveAs("\\SISERVER\wwwroot$\prove\moduli\modulo" & id & ".doc")



wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Function


End Class


jordi75 Profilo | Junior Member

Intendi che invece di scrivere una cosa del genere

wrdDoc = wrdApp.Documents.Open("\\SISERVER\wwwroot$\prove\moduli\Primo campo.doc")

devo scrivere così?

strFilePath="C:\inetpub\wwwroot\inetpub\prove\moduli\Primo Campo.doc"
strFilePath = Server.MapPath(strFilePath)

Ho provato a installare le officePIAs, ho aggiunto i references. Il path del riferimento a Word è questo:
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Word\10.0.4504.0__31bf3856ad364e35\Microsoft.Office.Interop.Word.dll

ho aggiornato il codice (senza creare la dll, ma scrivendolo direttamente nella web application) creando gli oggetti Microsoft.Office.Interop.Word.Application() ecc..

quando lancio l'applicazione mi restituisce questo errore:

File or assembly name Interop.Word, or one of its dependencies, was not found.

jordi75 Profilo | Junior Member

inserisco tutto il testo dell'errore...

=== Pre-bind state information ===
LOG: DisplayName = Interop.Word, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///c:/inetpub/wwwroot/prove
LOG: Initial PrivatePath = bin
Calling assembly : prove, Version=1.0.1486.32762, Culture=neutral, PublicKeyToken=null.
===

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Interop.Word, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/prove/84a34efc/2a271907/Interop.Word.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/prove/84a34efc/2a271907/Interop.Word/Interop.Word.DLL.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/prove/bin/Interop.Word.DLL.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/prove/bin/Interop.Word/Interop.Word.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/prove/84a34efc/2a271907/Interop.Word.EXE.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/prove/84a34efc/2a271907/Interop.Word/Interop.Word.EXE.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/prove/bin/Interop.Word.EXE.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/prove/bin/Interop.Word/Interop.Word.EXE.

jordi75 Profilo | Junior Member

scusate, ma perchè da quando ho installato le officePIAs ogni volta che cerco di creare un nuova istanza tipo

dim wrdapp as new Microsoft.Office.Interop.Word.Application()

se non sono nel primo progetto in cui ho aggiunto i riferimenti PIA, ma in uno diverso, mi dà errore di accesso negato?

Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5