howto handle exception in StiWebDesigner.GetPreviewDataSet

Stimulsoft Ultimate discussion
Post Reply
hellenschmidt
Posts: 32
Joined: Fri Dec 07, 2012 1:40 pm

howto handle exception in StiWebDesigner.GetPreviewDataSet

Post by hellenschmidt »

Hi,

is there a possibility to send a error message to the client in case of an exception in StiWebDesigner.GetPreviewDataSet? The Error #2032 and "Server message is empty" is not very helpful

Code: Select all

        protected void stiWebDesigner_GetPreviewDataSet(object sender, StiWebDesigner.StiPreviewDataSetEventArgs e)
        {
            try
            {
                e.PreviewDataSet = CreateDataSet();
            }
            catch (Exception ex)
            {
                // howto send message to client?
            }
        }
.
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: howto handle exception in StiWebDesigner.GetPreviewDataS

Post by Vladimir »

Hello,

Unfortunately there is no standard way to display the error in the PreviewReport event (GetPreviewDataSet in previous versions of the product). You can use the method below:

Code: Select all

    protected void StiWebDesigner1_PreviewReport(object sender, StiWebDesigner.StiPreviewReportEventArgs e)
    {
        Page.Response.ClearHeaders();
        Page.Response.Cache.SetExpires(DateTime.MinValue);
        Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Page.Response.ContentEncoding = Encoding.UTF8;
        Page.Response.ContentType = "text/xml";

        string myError = "Some error in Preview";
        byte[] buffer = Encoding.UTF8.GetBytes("ServerError:" + myError);
        if (StiWebDesigner1.DataCompression) buffer = StiGZipHelper.Pack(buffer);

        string dataBase64 = Convert.ToBase64String(buffer);
        buffer = Page.Request.ContentEncoding.GetBytes(dataBase64);

        Page.Response.BinaryWrite(buffer);

        try
        {
            Page.Response.Flush();
            Page.Response.End();
        }
        catch (ThreadAbortException) { }
        catch { }
    }
Thank you.
Post Reply