Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

ReportDocument.Export() for reports without parameters

$
0
0

I currently run a Windows service that exports Crystal Reports to PDF on schedule. Out of the 66 reports that run, 5 or so have never had parameters defined. They are currently run by the Task Scheduler, after taking them off the Christian Steven Crystal scheduling software suite.

Using the Crystal Reports DLL, I understand that the ReportDocument.Export() method requires parameters, as I have been experiencing the "missing parameter values" exception when it hits the ReportDocument.Export() method.

I'm currently doing my set parameters in this method:

private void SetParameters(string rawParameters = null)

        {

            var crystalParameters = new Dictionary<string, object>();

            var parameters = String.IsNullOrEmpty(rawParameters) ? null : HttpUtility.ParseQueryString(rawParameters);

 

 

            if(parameters == null)

            {

                ParameterFieldDefinition parameterFieldDefinition = this.reportDocument.DataDefinition.ParameterFields[0];

                ParameterValues defaultParameters = parameterFieldDefinition.DefaultValues;

                this.reportDocument.SetParameterValue(0, defaultParameters);

            }

            else

            {

                foreach (string rawKey in parameters.AllKeys)

                {

                    var value = parameters[rawKey];

                    // Check for array value (e.g. key[0]=value)

                    var arrayCheck = Regex.Match(rawKey, @"^(.+)\[[0-9]?\]$");

                    if (arrayCheck.Success)

                    {

                        var key = arrayCheck.Groups[1].Value;

                        // Existing entry for this key, reconstruct object array with this added

                        if (crystalParameters.ContainsKey(key))

                        {

                            var newParameterArray = new object[((object[])crystalParameters[key]).Count() + 1];

                            int i = 0;

                            foreach (object item in (object[])crystalParameters[key])

                            {

                                newParameterArray[i++] = item;

                            }

                            newParameterArray[i++] = (object)value;

                            crystalParameters[key] = (object)newParameterArray;

                        }

                        // New array value

                        else

                            crystalParameters[key] = (object)new object[] { value };

                    }

                    // Discrete value

                    else

                        crystalParameters[rawKey] = (object)parameters[rawKey];

                }

 

 

 

 

                foreach (string parameter in crystalParameters.Keys)

                {

                    try

                    {

                        this.reportDocument.SetParameterValue(parameter, crystalParameters[parameter]);

                    }

                    catch (Exception ex)

                    {

                        // Ignore invalid parameter exceptions, otherwise throw again

                        if (ex.HResult != -2147352565)

                        {

                            throw ex;

                        }

                    }

                }

            }

        }

 

My IDE is Visual Studio 2015 (initially developed on VS2013) and cuirrently uses SP 15 of the Crystal Reports runtime for .NET.

 

My question is - Is there are particular way for the .NET runtime to export reports without parameters? If so, what is the best way to approach this? Thank you.


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>