Page 1 of 1

howto handle exception in StiWebDesigner.GetPreviewDataSet

Posted: Fri Jul 17, 2015 1:46 pm
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?
            }
        }
.

Re: howto handle exception in StiWebDesigner.GetPreviewDataS

Posted: Mon Jul 20, 2015 10:21 am
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.