Click here to Skip to main content
15,886,578 members
Articles / Web Development / ASP.NET

Programmatically Playing With SSRS Subscriptions

Rate me:
Please Sign up or sign in to vote.
3.63/5 (7 votes)
29 Apr 2009CPOL3 min read 146.7K   2.8K   26  
This article demonstrates how can you dynamically handle SQL Server Reporting Services Subscriptions without using the SSRS interface at all.
<%@ Control Language="C#" AutoEventWireup="true" Inherits="EditSubscription.SubsModifier, EditSubscription, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9788ec69c6526c8a" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<script language="javascript" type="text/javascript">

    function DisableUserToTypeNonNumericValue() {        
    
        if (event.keyCode > 57) {            
            event.keyCode = 0;
            return false;
        }

        if (event.keyCode < 48) {           
            event.keyCode = 0;
            return false;
        }
    }

</script>

<table width="100%" style="background-color:#DDDDFF";>
    <tr>
        <td colspan="5" align="center" 
            style="font-family: Cambria; font-size: 25px; color: #008000">
            <b>Modify Subscription Properties</b></td>
    </tr>
    <tr>
        <td class="style18" colspan="5">
            <asp:Label ID="lblError" runat="server" ForeColor="Red" Font-Names="Century" 
                Font-Size="Medium"></asp:Label>
        </td>
    </tr>
    <tr>
        <td class="style16" colspan="5">
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
<asp:Label ID="lblEnterSubsID" runat="server" Text="Enter Subscription ID: " 
                Font-Names="Century" Font-Size="medium"></asp:Label>
        </td>
        <td class="style17">
<asp:TextBox ID="tbEnterSubsID" runat="server"></asp:TextBox>

        </td>
        <td>
<asp:Button ID="btGetSubs" runat="server" Text="Get Subscription" onclick="BtGetSubs_Click" 
                Font-Names="Century" Font-Size="medium" />


        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td colspan="5" width="15%">
<asp:Label ID="lblSubsDelDet" Font-Bold="True" runat="server" 
                Text="Subscription Delivery Details: " Font-Names="Century"></asp:Label>



        </td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblTO" runat="server" Text="TO: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td class="style17" width="15%">
    <asp:TextBox ID="tbTO" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblCC" runat="server" Text="CC: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td class="style17" width="15%">
    <asp:TextBox ID="tbCC" runat="server" Width="149px"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblBCC" Font-Names="Century" Font-Size="medium" runat="server" Text="BCC: "></asp:Label>
        </td>
        <td>
    <asp:TextBox ID="tbBCC" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblReplyTo" runat="server" Text="Reply To: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td>
    <asp:TextBox ID="tbReplyTo" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblSub" runat="server" Text="Subject: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td>
    <asp:TextBox ID="tbSub" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblPriority" runat="server" Text="Priority: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td>
    <asp:TextBox ID="tbPriority" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblComment" runat="server" Text="Comment: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td class="style17">
    <asp:TextBox ID="tbComment" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td width="15%">
    <asp:Label ID="lblDesc" runat="server" Text="Description: " Font-Names="Century" 
                Font-Size="medium"></asp:Label>
        </td>
        <td>
    <asp:TextBox ID="tbDesc" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;&nbsp; &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;&nbsp; &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;&nbsp;&nbsp;
            &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td colspan="5" width="15%">
<asp:Panel ID="pnl_subscription" runat="server" Width="100%">
    <asp:Label ID="lblSubsSchDet0" Font-Bold="True" runat="server" 
    Text="Subscription Schedule Details: " Font-Names="Century"></asp:Label>
    <br />
    <br />
    <table class="style1">
        <tr>
            <td class="style14">
                <span>
                <h3 style="font-family: Century">
                    Frequency<br />
                    <span class="style3" 
                        style="font-family: Century; font-style: italic; font-size: medium;">Define a schedule that runs on an hourly, daily, weekly, 
                    monthly, or one-time basis.</span></h3>
                </span>
            </td>
            <td>
                <asp:RadioButtonList ID="rbl_duration_list" runat="server" 
                    RepeatDirection="Horizontal" 
                    onselectedindexchanged="rbl_duration_list_SelectedIndexChanged" 
                    AutoPostBack="True" Font-Names="Century" Font-Size="Medium" Width="62%">
                    <asp:ListItem Value="0">Hour</asp:ListItem>
                    <asp:ListItem Value="1">Day</asp:ListItem>
                    <asp:ListItem Value="2">Week</asp:ListItem>
                    <asp:ListItem Value="3">Month</asp:ListItem>
                    <asp:ListItem Value="4">Once</asp:ListItem>
                </asp:RadioButtonList>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td style="font-family: Century;" class="style14">
                <b>Schedule</b><br />
                <span style="font-family: Century; font-style:italic; font-size:medium;">Times are expressed in (GMT-05:00) Eastern Time (US and 
                Canada).</span></td>
            <td>
                <table class="style1">
                    <tr>
                        <td class="style7" colspan="2">
                            <asp:Panel ID="pnl_hour" runat="server" Width="100%">
                                <table class="style1">
                                    <tr>
                                        <td colspan="2">
                                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_hourly0" 
                                                style="font-family: century; font-size: medium">Run the schedule every:</span></span></td>
                                    </tr>
                                    <tr>
                                        <td class="style19">
                                            <asp:TextBox ID="txt_hour_hrs" runat="server" Width="34px" MaxLength="2"></asp:TextBox>
                                            &nbsp;<span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_hourly1" 
                                                class="ms-authoringcontrols"><span 
                                                ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_hourly_hourMinute" 
                                                style="font-family:Century; font-size:medium;">hours</span></span></span></td>
                                        <td style="font-family:Century; font-size:medium;">
                                            <asp:TextBox ID="txt_hour_mins" runat="server" Width="51px" MaxLength="2"></asp:TextBox>
                                            &nbsp; minutes</td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <asp:Panel ID="pnl_day" runat="server" Width="100%">
                                <table class="style1">
                                    <tr>
                                        <td colspan="2" style="font-family:Century; font-size:medium;">
                                            <asp:RadioButtonList ID="rbl_day_option_1" runat="server" 
                                                
                                                RepeatDirection="Horizontal" AutoPostBack="True" 
                                                onselectedindexchanged="rbl_day_option_1_SelectedIndexChanged" 
                                                Font-Names="Century" Font-Size="medium">
                                                <asp:ListItem>On the following days</asp:ListItem>
                                            </asp:RadioButtonList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="font-family:Century; font-size:medium;">
                                            <asp:CheckBox ID="cbl_day_option_sun" runat="server" Text="Sun" />
                                            <asp:CheckBox ID="cbl_day_option_mon" runat="server" Text="Mon" />
                                            <asp:CheckBox ID="cbl_day_option_tue" runat="server" Text="Tue" />
                                            <asp:CheckBox ID="cbl_day_option_wed" runat="server" Text="Wed" />
                                            <asp:CheckBox ID="cbl_day_option_thu" runat="server" Text="Thu" />
                                            <asp:CheckBox ID="cbl_day_option_fri" runat="server" Text="Fri" />
                                            <asp:CheckBox ID="cbl_day_option_sat" runat="server" Text="Sat" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="font-family:Century; font-size:xsmall;" class="style20">
                                            <asp:RadioButtonList ID="rbl_day_option_2" runat="server" 
                                                RepeatDirection="Horizontal" AutoPostBack="True" 
                                                onselectedindexchanged="rbl_day_option_2_SelectedIndexChanged" 
                                                Font-Names="Century" Font-Size="medium">
                                                <asp:ListItem>Repeat after this number of days:</asp:ListItem>
                                            </asp:RadioButtonList>
                                        </td>
                                        <td style="font-family:Century; font-size:medium;">
                                            <asp:TextBox ID="txt_hour_days" runat="server" Width="51px" MaxLength="3"></asp:TextBox>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <asp:Panel ID="pnl_week" runat="server" Width="100%">
                                <table class="style1">
                                    <tr>
                                        <td style="font-family:Century; font-size:medium;" class="style21">
                                            Repeat after this number of weeks:</td>
                                        <td style="font-family:Century; font-size:medium;">
                                            <asp:TextBox ID="txt_week" runat="server" Width="51px" MaxLength="3"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="font-family:Century; font-size:medium;">
                                            On day(s):</td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="font-family:Century; font-size:medium;">
                                            <asp:CheckBox ID="cbl_week_option_3_sun" runat="server" Text="Sun" />
                                            <asp:CheckBox ID="cbl_week_option_3_mon" runat="server" Text="Mon" />
                                            <asp:CheckBox ID="cbl_week_option_3_tue" runat="server" Text="Tue" />
                                            <asp:CheckBox ID="cbl_week_option_3_wed" runat="server" Text="Wed" />
                                            <asp:CheckBox ID="cbl_week_option_3_thu" runat="server" Text="Thu" />
                                            <asp:CheckBox ID="cbl_week_option_3_fri" runat="server" Text="Fri" />
                                            <asp:CheckBox ID="cbl_week_option_3_sat" runat="server" Text="Sat" />
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <asp:Panel ID="pnl_month" runat="server" Width="100%">
                                <table style="font-family:Century; font-size:medium;">
                                    <tr>
                                        <td class="style9" colspan="4">
                                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_monthly" 
                                                style="font-family:Century; font-size:medium;">Select Months:</span></span></td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:CheckBox ID="chk_mnth_jan" runat="server" Text="Jan" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_feb" runat="server" Text="Feb" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_mar" runat="server" Text="Mar" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_apr" runat="server" Text="Apr" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:CheckBox ID="chk_mnth_may" runat="server" Text="May" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_jun" runat="server" Text="Jun" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_jul" runat="server" Text="Jul" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_aug" runat="server" Text="Aug" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:CheckBox ID="chk_mnth_sep" runat="server" Text="Sep" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_oct" runat="server" Text="Oct" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_nov" runat="server" Text="Nov" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chk_mnth_dec" runat="server" Text="Dec" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style9" colspan="4">
                                            On calendar day(s):<br />
                                            <span style="font-family:Century; font-size:small; font-style:italic;">Calendar days must be entered in a format similar to : 1-3,10,15-19.</span></td>
                                    </tr>
                                    <tr>
                                        <td class="style9" colspan="4">
                                            <asp:TextBox ID="txt_cal_dt" runat="server" MaxLength="10"></asp:TextBox>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <asp:Panel ID="pnl_once" runat="server" Width="100%">
                                <table class="style1">
                                    <tr>
                                        <td>
                                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_once" 
                                                style="font-family:Century; font-size:medium;">Report runs only once.</span></span></td>
                                        <td>
                                            &nbsp;</td>
                                    </tr>
                                </table>
                            </asp:Panel>
                        </td>
                    </tr>
                    <tr>
                        <td class="style7" colspan="2">
                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_hourly" 
                                class="ms-authoringcontrols">
                            <span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_hourly_StartTime" 
                                style="font-family:Century; font-size:medium;"><span>Start time:</span></span></span></span></td>
                    </tr>
                    <tr>
                        <td style="font-family:Century; font-size:medium;">
                            <asp:TextBox ID="txt_start_time" runat="server" Width="51px"></asp:TextBox>
                        </td>
                        <td style="font-family:Century; font-size:medium;">
                            <asp:RadioButtonList ID="rbl_start_time" runat="server" 
                                RepeatDirection="Horizontal" style="margin-left: 0px" Font-Names="Century" 
                                Font-Size="medium">
                                <asp:ListItem Selected="True">A.M.</asp:ListItem>
                                <asp:ListItem>P.M.</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2" colspan="2">
                <table class="style1">
                    <tr>
                        <td style="font-family:Century; font-size:medium;" class="style22">
                            <b>Start and End Dates</b><br />
                            <span style="font-size:medium; font-style:italic;">Specify the date to start and optionally end this schedule.</span></td>
                        <td style="font-family:Century; font-size:medium;" class="style23">
                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_startStop0" 
                                >Begin running this schedule on:<br />
                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_startStop1" 
                                class="ms-authoringcontrols"><span class="ms-authoringcontrols">
                            <label for="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_startStop_EndCheckBox">
                            <span style="font-family:Century; font-size:small; font-style:italic;">Please 
                            enter date in &quot;mm/dd/yyyy&quot; format</span></label></span></span></span></span></span></td>
                        <td style="font-family:Century; font-size:medium;">
                            
                            <asp:TextBox ID="txt_start_date" runat="server" MaxLength="10"></asp:TextBox>
                            
                        </td>
                    </tr>
                    <tr>
                        <td class="style22">
                            &nbsp;</td>
                        <td style="font-family:Century; font-size:medium;" class="style23">
                            <asp:CheckBox ID="chk_end_date" runat="server" 
                                oncheckedchanged="chk_end_date_CheckedChanged" AutoPostBack="True" />
                            <span><span ID="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_startStop" 
                                class="ms-authoringcontrols"><span class="ms-authoringcontrols">
                            <label for="ctl00_PlaceHolderMain_ctl01_ctl03_ctl01_startStop_EndCheckBox">
                            Stop running this schedule on:<br />
                            <span style="font-family:Century; font-size:small; font-style:italic;">Please enter date in &quot;mm/dd/yyyy&quot; format</span></label></span></span></span></td>
                        <td style="font-family:Century; font-size:medium;">
                           
                            <asp:TextBox ID="txt_end_date" runat="server" MaxLength="10"></asp:TextBox>
                           
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
</asp:Panel>

        </td>
    </tr>
    <tr>
        <td width="15%" style="font-family:Century; font-size:medium;" colspan="5">
<asp:Label ID="lblParDet0" Font-Bold="true" runat="server" 
                Text="Subscription Parameter Details: "></asp:Label>
        </td>
    </tr>
    <tr>
        <td width="15%" class="style16" colspan="5" 
            style="font-family: century; font-size: medium">
<asp:PlaceHolder EnableViewState="true" ID="pSubsPar" runat="server"></asp:PlaceHolder>
        </td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style18" width="15%">
            &nbsp;</td>
        <td class="style17">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style16" colspan="5" align="center" width="15%">
<asp:Button ID="BtUpdSubs" runat="server" Text="Update Subscription" 
    onclick="BtUpdSubs_Click" Font-Names="Century" Font-Size="medium" />
        </td>
    </tr>
</table>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
A SharePoint Kid playing in Kolkata, India.

Working with one of the leading software company and currently working with SharePoint technologies.

Enjoys Cricket, National & World Music.

Favourite band include Linkin Park, Beatles, Oasis, Match Box 20, Noori, Nirvana, Nickelback etc.

Comments and Discussions