Can I send SSRS custom subscription e-mails?

后端 未结 2 814
花落未央
花落未央 2020-12-12 07:18

I need to send some e-mails containing a SSRS report to a list of persons, representing the amount of work items they have left until a certain date. What I would like to d

相关标签:
2条回答
  • 2020-12-12 08:05

    If you do not have enterprise (to utilize data driven subscription as @StephLocke mentioned), you can programmatically generate SSRS subscriptions using the SSRS web service.

    Your code would look something like this (SubscriptionRequest is a custom class I use, its properties should be intuitive):

    static void generateSubscription()
    {
        if (SubscriptionRequests.Count < 1) return;
    
        NetworkCredential credentials = new NetworkCredential("user", "pass");
        reports.ReportingService2005 rs = new reports.ReportingService2005();
        rs.Credentials = credentials;
        DateTime topDatetime = DateTime.Now;
        topDatetime = topDatetime.AddMinutes(2);
    
        foreach (SubscriptionRequest x in SubscriptionRequests)
        {
            reports.ExtensionSettings extensionSettings = new reports.ExtensionSettings();
            List<reports.ParameterValue> extParameters = new List<reports.ParameterValue>();
            List<reports.ParameterValue> parameters = new List<reports.ParameterValue>();
            string description = "Email: ";
            string eventType = "TimedSubscription";
            extensionSettings.Extension = "Report Server Email";
    
            string scheduleXml = "<ScheduleDefinition><StartDateTime>";
            scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
            scheduleXml += "</StartDateTime></ScheduleDefinition>";
    
            parameters.Add(new reports.ParameterValue() { Name = "abc", Value = x.id });
    
    
            extParameters.Add(new reports.ParameterValue() { Name = "RenderFormat", Value = x.renderFormat });
            extParameters.Add(new reports.ParameterValue() { Name = "TO", Value = x.email });
            extParameters.Add(new reports.ParameterValue() { Name = "ReplyTo", Value = x.replyTo });
            extParameters.Add(new reports.ParameterValue() { Name = "IncludeReport", Value = "True" });
            extParameters.Add(new reports.ParameterValue() { Name = "Subject", Value = "subject - " + " (" + x.id.ToString() + ")" });
    
            extParameters.Add(new reports.ParameterValue() { Name = "Comment", Value = x.body });
            extensionSettings.ParameterValues = extParameters.ToArray();
    
            description += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
            description += " (" + x.a + " - " + x.b + " - " + x.c + ")";
            string _reportName = "/report";
            rs.CreateSubscription(_reportName, extensionSettings, description, eventType, scheduleXml, parameters.ToArray());
            topDatetime = topDatetime.AddSeconds(30);
        }           
    }  
    

    More examples can be found here.

    0 讨论(0)
  • 2020-12-12 08:08

    Yes you can use a data driven subscription to do this. Unfortunately this isn't available to every edition (2008+, enterprise only I believe) so you may not be able to use this functionality.

    There are more details available: http://technet.microsoft.com/en-us/library/ms159150.aspx

    0 讨论(0)
提交回复
热议问题