2

I have a font stored in a database, and I have to set all my fileds with that font. I set bind my report like this :

FormBudgReelReport form = new FormBudgReelReport();
form.Viewer.LocalReport.ReportEmbeddedResource = _NomRessourceRpt;
form.Viewer.LocalReport.DataSources.Add(source);
form.ShowDialog();

If I could load my rdlc as an XmlDocument, I know how to do this, but is there a way to do this? I can't use a formula like =Parameters!Police.Value because I have a lot of reports to change.

davejagoda
  • 2,420
  • 1
  • 20
  • 27
Loïc Haye
  • 61
  • 2
  • 8

2 Answers2

1

Ok ! I could load my rdlc as a xmlDocument by this code :

Stream st = this.GetType().Assembly.GetManifestResourceStream(_NomRessourceRpt);

// convert stream to string
StreamReader reader = new StreamReader(st);
string reportDef = reader.ReadToEnd();

XmlDocument document = new XmlDocument();
document.LoadXml(reportDef);

Thanks for the help :)

Loïc Haye
  • 61
  • 2
  • 8
0

If I could load my rdlc as an XmlDocument, I know how to do this, but is there a way to do this?

In the Solution Explorer you can right-click the .rdlc file and select <Open With...> to choose the editor .

enter image description here


Update:

I am seeking for a way to load my rdlc in a xmlDocument object and then edit xml nodes in runtime.

The following code snippet helps you to load the .rdlc report file from the resources folder to an Xml document:

using System;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Resources;

 private void LoadRDLCFromResources()
 {
    //Declare variables
    XmlDocument objXmlDocument = new XmlDocument();
    Byte[] byteArray;
    Stream objStream = null;
    ResourceManager resourceManager = null;

    try
    {
        // Initialize ResourceManager object
        resourceManager = new ResourceManager("your_namespace_name.Properties.Resources", GetType().Assembly);
        if (resourceManager != null)
        {
            //Load the resource file "Sample.rdlc" into ByteArray
            byteArray = (Byte[])resourceManager.GetObject("Sample");
            if (byteArray != null)
            {
                //Load this bytearray into MemoryStream
                objStream = new MemoryStream(byteArray);
                if (byteArray.Length > 0)
                {
                    //Load this stream object into XML document and  
                    //thus you get the rdlc file loaded as an XML 
                    //document. 
                    objXmlDocument.Load(objStream);

                    // Code for using this xml document as per your use
                }
            }
        }
    } 
    //MissingManifestResourceException is an exception thrown when the resource manager fails to initialize appropriately. In such case, please check the namespace name.
    catch (MissingManifestResourceException ex)
    {

        MessageBox.Show("Exception -> " + ex.Message,
           "Sample Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception -> " + ex.Message,
            "Sample Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    finally
    {
        // Clear the objects in finally block. This is required for memory management issues.
        // If xml document is not required further then clear it in the following manner
        if (objXmlDocument != null)
        {
            objXmlDocument.DocumentElement.RemoveAllAttributes();
            objXmlDocument.DocumentElement.RemoveAll();   

            objXmlDocument.RemoveAll();
        }
        //Clear the memory stream object 
        if (objStream != null)
        {
            objStream.Flush();
            objStream.Close();
            objStream.Dispose();
        }
        // Clear resource manager 
        resourceManager.ReleaseAllResources();
    }
}

Source: How to load a rdlc file from resources folder into an XML document dynamically?

Oceans
  • 3,445
  • 2
  • 17
  • 38
  • If I do this, I have to edit all my reports by myself. I am seeking for a way to load my rdlc in a xmlDocument object and then edit xml nodes in runtime. Thanks for your help, if there's no other solution, I will do this – Loïc Haye Nov 18 '15 at 08:43
  • I should've realized that this was what you were looking for. I updated my answer. – Oceans Nov 18 '15 at 09:50
  • Thank you again but I still have a problem. This code can't run if my .rdlc are not in Resources.resx. I tried to show every thing in this with resourceManager.GetResourceSet and a foreach, but there is no rdlc. I think we are close to the goal ! – Loïc Haye Nov 18 '15 at 15:32
  • With this.GetType().Assembly.GetManifestResourceStream(_NomRessourceRpt); I can load my rdlc into a xmlDocument. Sounds good, I continue – Loïc Haye Nov 18 '15 at 15:59