Bonjour,

je développe une application qui produit des documents word et excel. Lorsque j'essaye de créer mes documents excel je n'ai aucun problème, par contre pour mes documents word je ne parviens à les créer qu'en environnement de développement.

Lorsque je dépose mon application sur le serveur (Windows Server 2003) si j'essaye de créer mes documents word j'ai une exception qui est lancée sans aucun détail.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 388: catch (Exception err)
Line 389: {
Line 390: throw (err);
Line 391: Trace.Write(err.Message);
Line 392: }


Source File: d:\Inetpub\wwwroot\PMPRO\relanceRisque.aspx.cs Line: 390

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
relanceRisque.ButtonEnvoiMail_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\PMPRO\relanceRisque.aspx.cs:390
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Alors qu'en local tout se passe correctement.

J'ai donné les droits d'exécution à l'utilisateur ASPNET et à SERVICE RESEAU. Mais le problème ne semble pas venir de là. Sur le serveur, word se lance mais je ne peux faire aucune opération dessus.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
public static bool docRisques(string redacteur, string destinataire, string validateur, string copie, string tel, string sujet, string corpsDeb, string corpsFin, string date, string path, DataTable info)
        {
            bool result = false;
            object missing = System.Reflection.Missing.Value;
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
            object fileName = path + @"Documents\Relance.doc";
            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
 
            object oTemplate = path + @"Documents\relanceRisque.dot";
            oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
                ref oMissing, ref oMissing);
 
 
            try
            {
                // Ajout de texte sur un signet
                object cible = "Emetteur";
 
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = redacteur;<--- Cette instruction lève l'exception
 
                cible = "Destinataire";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = destinataire;
 
                cible = "Validateur";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = validateur;
 
                cible = "Copie";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = copie;
 
                cible = "Tel";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = tel;
 
                cible = "Objet";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = sujet;
 
                cible = "Corps";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = corpsDeb;
 
                cible = "DateNote";
                oDoc.Bookmarks.get_Item(ref cible).Range.Text = date;
 
                int nbLigne = info.Rows.Count;
                // Création d'une table et insertion des données
                Word.Table oTable;
                cible = "DocsManquants";
                Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref cible).Range;
                oTable = oDoc.Tables.Add(wrdRng, nbLigne + 1, 7, ref oMissing, ref oMissing);
                oTable.Range.ParagraphFormat.SpaceAfter = 6;
                oTable.Cell(1, 1).Range.Text = "Ouverture";
                oTable.Cell(1, 2).Range.Text = "N° de Compte";
                oTable.Cell(1, 3).Range.Text = "Intitulé client";
                oTable.Cell(1, 4).Range.Text = "Conseiller";
                oTable.Cell(1, 5).Range.Text = "N° Bureau";
                oTable.Cell(1, 6).Range.Text = "Bureau";
                oTable.Cell(1, 7).Range.Text = "Groupe";
                oTable.Rows[1].Range.Font.Bold = 1;
 
                int r, c;
                string strText;
                for (r = 1; r <= nbLigne; r++)
                {
                    for (c = 1; c <= 7; c++)
                    {
                        switch (c)
                        {
                            case 1:
                                strText = DateTime.Parse(info.Rows[r - 1][c - 1].ToString()).ToShortDateString();
                                break;
                            case 5:
                                Regex regExp = new Regex(@"(\d+)");
                                MatchCollection theMatches = regExp.Matches(info.Rows[r - 1][c - 1].ToString());
                                strText = theMatches[0].Groups[1].ToString();
                                break;
                            default:
                                strText = info.Rows[r - 1][c - 1].ToString();
                                break;
                        }
                        oTable.Cell(r + 1, c).Range.Text = strText;
                    }
                    oTable.Rows[r + 1].Range.Font.Size = 10;
                }
                oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.Text = corpsFin;
                // Sauvegarde du document
                oDoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing);
 
                // Fermer le document
                oDoc.Close(ref missing, ref missing, ref missing);
                result = true;
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                // Fermeture de word
                oWord.Quit(ref missing, ref missing, ref missing);
            }
            return result;
        }
Je suppose qu'il s'agit d'un problème de paramètrage de windows server 2003. Je sais que ce n'est pas conseillé d'utiliser l'automation d'office côté server mais si je parviens à le faire fonctionner ça me ferait gagner beaucoup de temps.

Merci d'avance