Bonjour,

Pour une de mes applications, j'ai besoin de lancer une impression d'un document sans passer par aucune interface.

Pour cela, je me suis inspiré de ce lien msdn.

Ce document est un report Microsoft (généré dans Visual Studio).
Lorsque je tente de faire un"report.Render([...]);", j'ai droit à une erreur
"Une erreur s'est produite lors du traitement du rapport local."
sans plus de détail...

Voici mon code source :
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
 
public void Print(
    string Titre1,
    string Titre2,
    string Titre3,
    Hashtable Tableau)
{
    //Alimenter DataSet
    Data.Temp Data = new ProBTP.Utils.Reporting.Data.Temp();
    foreach (object key in Tableau.Keys)
    {
        Data.Tab2Cols.Rows.Add(new object[] {key, Tableau[key]});
    }
 
    //Initialiser le report
    LocalReport report = new LocalReport();
    report.ReportPath = @"Reports\HashTable.rdlc"; //A changer
    report.GetParameters();
    ReportParameter[] p = new ReportParameter[3];
    p[0] = new
      ReportParameter("Titre1", Titre1);
    p[1] = new
      ReportParameter("Titre2", Titre2);
    p[2] = new
      ReportParameter("Titre3", Titre3);
    report.SetParameters(p);
 
    report.DataSources.Add(new ReportDataSource("Temp_Tab2Cols", Data.Tab2Cols));
 
    report.Refresh();            
 
    //Partie impression
    string deviceInfo =
      "<DeviceInfo>" +
      "  <OutputFormat>EMF</OutputFormat>" +
      "  <PageWidth>8.5in</PageWidth>" +
      "  <PageHeight>11in</PageHeight>" +
      "  <MarginTop>0.25in</MarginTop>" +
      "  <MarginLeft>0.25in</MarginLeft>" +
      "  <MarginRight>0.25in</MarginRight>" +
      "  <MarginBottom>0.25in</MarginBottom>" +
      "</DeviceInfo>";
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("IMAGE", deviceInfo, CreateStream, out warnings);
 
    foreach (Stream stream in m_streams)
        stream.Position = 0;
 
    if (m_streams == null || m_streams.Count == 0)
        throw new Exception("Error: no stream to print.");
    PrintDocument printDoc = new PrintDocument();
    if (!printDoc.PrinterSettings.IsValid)
    {
        throw new Exception("Erreur : Impossible de trouver l'imprimante par défaut !");
    }
    else
    {
        printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
        m_currentPageIndex = 0;
        printDoc.Print();
    }
}
Où ai-je fait une erreur?

Mon environnement technique : Windows XP Pro SP3 et Visual Studio 2008

Merci,
Taichin.