Listing 1: Upload a file to the Web server

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PBLUpload.aspx.cs"
 Inherits="PBLUpload" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>PBL upload</title>
    <link rel="stylesheet" type="text/css" href="include/style.css"/>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<!-#include file="include\\header.asp"->

<script language="C#" runat="server">
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
  string strFileNameOnServer = txtServername.Value;
  string strPath = "pbl\\";
  string strBaseLocation = Server.MapPath(strPath);

  if ("" == strFileNameOnServer)
  {
    txtOutput.InnerHtml = "Error - a file name must be specified.";
    return;
  }

  if (null != uplTheFile.PostedFile)
  {
    try 
    {
      string strFullFileOnServer =
	   System.IO.Path.GetFullPath(strBaseLocation+strFileNameOnServer);
      uplTheFile.PostedFile.SaveAs(strFullFileOnServer);
      txtOutput.InnerHtml = "File <b>" + 
	  strBaseLocation+strFileNameOnServer+"</b> uploaded successfully";
    }
    catch (Exception e) 
    {
      txtOutput.InnerHtml = "Error saving <b>" + 
	  strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
    }
  }
}
</script>

<form id="Form1" enctype="multipart/form-data" runat="server">
<table>
<tr>
  <td>Select file:</td>
  <td style="width: 291px"><input id="uplTheFile" type="file" runat="server"
   style="width: 300px"/></td>
</tr>
<tr>
  <td>Name on server:</td>
  <td style="width: 291px"><input id="txtServername" type="text" runat="server"
   style="width: 170px"/></td>
</tr>
<tr>
  <td colspan="2">
  <center><input type="button" id="btnUploadTheFile" value="Upload" 
  onserverclick="btnUploadTheFile_Click" runat="server"/></center>
  </td>
</tr>
</table>
</form>

<span id="txtOutput" style="font: 8pt verdana;" runat="server" />
<!-#include file="include\\footer.asp"->
</body>
</html>


Listing 2: Show available libraries

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PBLChoose.aspx.cs"
 Inherits="include_PBLChoose" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Choose Library</title>
</head>
<body>
<!-#include file="include\\header.asp"->

<form id="Form2" runat="server">
Find libraries whose names contain:
<asp:TextBox id="txtQuery" runat="server" /><br />
<input type="submit" value="Find Files" />
    <P/>

    <div>
        <asp:GridView ID="dgFileList" runat="server" BorderColor="#0" BorderWidth="1px"
		 CellPadding="0"
            CellSpacing="1" HeaderStyle-BackColor="#EEEEEE" HeaderStyle-ForeColor="#FFFFFF"
			HeaderStyle-Font-Bold="True" AutoGenerateColumns="False">
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFormatString="~/ShowDWs.aspx?pbl={0}"
				 DataTextField="Name"
                    HeaderText="File Name:" DataNavigateUrlFields="Name"
					 NavigateUrl="~/ShowDWs.aspx" />
                <asp:BoundField DataField="Length" HeaderText="File Size:">
                    <ItemStyle HorizontalAlign="Right" />
                </asp:BoundField>
                <asp:BoundField DataField="LastWriteTime" HeaderText="Date Created:" />
            </Columns>
            <HeaderStyle BackColor="#EEEEEE" Font-Bold="True" ForeColor="Black" />
        </asp:GridView>
    </div>
</form>
<!-#include file="include\\footer.asp"->
</body>
</html>


Listing 3: Read available libraries

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class include_PBLChoose : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strPath = "pbl\\";
        string strQuery = ".pbl";
        DirectoryInfo myDirInfo;

        strQuery = txtQuery.Text;
        if (strQuery.Equals(""))
            strQuery = ".pbl";

        myDirInfo = new DirectoryInfo(Server.MapPath(strPath));

        dgFileList.DataSource = myDirInfo.GetFiles("*" + strQuery + "*");
        dgFileList.DataBind();

    }
}


Listing 4: Show available DataWindow objects

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowDWs.aspx.cs"
 Inherits="include_ShowDWs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Show DataWindow objects</title>
</head>
<body>
<!-#include file="include\\header.asp"->
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="dgDWList" runat="server" BorderColor="#0" BorderWidth="1px"
		CellPadding="0" CellSpacing="1" HeaderStyle-BackColor="#EEEEEE"
		 HeaderStyle-ForeColor="#FFFFFF"
		 HeaderStyle-Font-Bold="True" AutoGenerateColumns="False" AllowSorting="True"
		  EnableSortingAndPagingCallbacks="True">
            <Columns>
                <asp:HyperLinkField DataNavigateUrlFormatString="~/ShowReport.aspx?dwo={0}&pbl=" DataTextField="Name"
HeaderText="Report Name:" DataNavigateUrlFields="Name" NavigateUrl="~/ShowDWs.aspx" />
                <asp:BoundField DataField="Comments" HeaderText="Comment:">
                    <ItemStyle HorizontalAlign="Right" />
                </asp:BoundField>
                <asp:BoundField DataField="LastModifyTime" HeaderText="Date Created:" />
            </Columns>
            <HeaderStyle BackColor="#EEEEEE" Font-Bold="True" ForeColor="Black" />
        </asp:GridView>
    </div>
    </form>
<!-#include file="include\\footer.asp"->
 </body>
</html>


Listing 5: Read available DataWindow objects

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Sybase.DataWindow;

public partial class include_ShowDWs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strPath = "pbl\\";
        string strPBL = "";
        string strLib;

        if (Request.Params["pbl"] == null)
        {
            if (Session["pbl"] == null)
                Response.Redirect("PBLChoose.aspx");
            else
                strPBL = Session["pbl"].ToString();
        }
        else
            strPBL = Request.Params["pbl"];

        strLib = Server.MapPath(strPath + strPBL);

        if (!System.IO.File.Exists(strLib))
            Response.Redirect("PBLChoose.aspx");
        else
        {

            DataWindowObjectEntry[] dwEntries =
			 Sybase.DataWindow.Utility.GetDataWindowObjectEntries(strLib);

            //foreach (DataWindowObjectEntry dwEntry in dwEntries)
            //{
            //    Response.Write(dwEntry.Name + "<br/>");
            //}
            dgDWList.DataSource = dwEntries;
            dgDWList.DataBind();
            Session["pbl"] = strPBL;
        }
    }
}


Listing 6: The page holding the StreamImageContainer

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DWStreamImage.aspx.cs"
 Inherits="include_Default" %>

<%@ Register Assembly="WebDataWindow" Namespace="Sybase.DataWindow.Web" TagPrefix="dw" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>DWStreamImage</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dw:streamimagecontainer id="StreamImageContainer1" runat="server" height="235px"
		width="571px"></dw:streamimagecontainer>
    </div>
    </form>
</body>
</html>


Listing 7: Page showing the actual report

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowReport.aspx.cs"
 Inherits="ShowReport" %>

<%@ Register Assembly="WebDataWindow" Namespace="Sybase.DataWindow.Web" TagPrefix="dw" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>DataWindow Report</title>
</head>
<body  id="PageBody" runat="server">
<!-#include file="include\\header.asp"->
    <form id="form1" runat="server">
        <div>
             
            <dw:WebDataWindowControl ID="dwReport" runat="server" 
			BorderStyle="None" ClientFormatting="True"
			ClientScriptable="True" Height="663px" Width="919px" 
			AutoRestoreDataCache="True"
			AutoSaveDataCacheAfterRetrieve="True">
                <GraphConfigurations 
				GraphDynamicImageFileUrlPath="~/images" 
				StreamImageContainerPage="~/include/DWStreamImage.aspx" />
            </dw:WebDataWindowControl>
            <br />
            <asp:Button ID="bnSavePDF" runat="server" OnClick="bnSavePDF_Click" 
			Text="Save as PDF" Width="921px" /><br />
            <asp:TextBox ID="tbError" runat="server" 
			Visible="False" Width="551px">
            </asp:TextBox></div>
    </form>
    <!-#include file="include\\footer.asp"->

</body>
</html>


Listing 8: The report pages server part

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ShowReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["pbl"] == null)
            Response.Redirect("PBLChoose.aspx");
        string strDWO = Request.Params["dwo"];

        Sybase.DataWindow.AdoTransaction sqlca;
        System.Data.OleDb.OleDbConnection oleDbASA = new System.Data.OleDb.OleDbConnection();

        oleDbASA.ConnectionString = "User ID=dba;Data Source=EAS Demo DB V110
		 DWD;Provider=\"ASAProv.90\"";

        if (!Page.IsPostBack)
        {
            try
            {
                oleDbASA.Open();
                sqlca = new Sybase.DataWindow.AdoTransaction(oleDbASA);
                sqlca.BindConnection();

                dwReport.LibraryList = Server.MapPath("~\\pbl\\" + (string)Session["pbl"]);
                dwReport.DataWindowObject = strDWO;
                dwReport.SetTransaction(sqlca);
                dwReport.Retrieve();

            }
            catch (Exception ex)
            {

                tbError.Text = ex.ToString();
                tbError.Visible = true;
                dwReport.Visible = false;
            }
            finally
            {

                oleDbASA.Close();
            }
        }
    }
    protected void bnSavePDF_Click(object sender, EventArgs e)
    {
        String pdfFileName;
        String pdfUrl;
        String uniqueName;

 
        uniqueName = System.Guid.NewGuid().ToString() + ".pdf";
        pdfUrl = "pdfs/" +  uniqueName;
        pdfFileName = Page.MapPath("") + "\\pdfs\\" + uniqueName;

        dwReport.SaveAs(pdfFileName, Sybase.DataWindow.FileSaveAsType.Pdf);
        HtmlGenericControl body;
        body = this.FindControl("PageBody") as HtmlGenericControl;
        body.Attributes.Clear(); 
        body.Attributes.Add("onLoad", "pdfWindow=window.open ('" + 
		HttpUtility.UrlEncode(pdfUrl) + 
		"', 'pdf', 'dependent');pdfWindow.focus();");
        body.Attributes.AddAttributes(new   HtmlTextWriter(Response.Output));

    }
}