Modify dynamically a rdlc report (c#)

不问归期 提交于 2019-12-14 03:59:39

问题


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.


回答1:


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 .


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?




回答2:


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 :)



来源:https://stackoverflow.com/questions/33763028/modify-dynamically-a-rdlc-report-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!