1: using System;
3: using System.Linq;
2: using System.Collections.Generic;
4: using System.Text;
5: using System.Web.Services;
6:
7: namespace UploadMultipleReports
8: {
9: public class ConfigureReports
10: {
11: private const string Root = "/";
12: private ReportingService2010 rs;
13:
14: public ConfigureReports()
15: {
16: try
17: {
18: // Connect to Reporting Services
19: rs = new ReportingService2010();
20: rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
21: rs.Url = "http://localhost/reportserver/ReportService2010.asmx";
22: }
23: catch (System.Exception ex)
24: {
25: Console.WriteLine(ex.Message);
26: }
27:
28: }
29: public void CheckReportServerFolder(string foldername)
30: {
31: int count = 0;
32: int datasourcecount =0;
33: try
34: {
35: CatalogItem[] list = rs.ListChildren("/", false);
36: foreach (CatalogItem c in list)
37: {
38: if ((c.TypeName == "Folder") & (c.Name == foldername))
39: count += 1;
40: if((c.TypeName=="Data Source")& (c.Name == "PowerManagementDataSource"))
41: datasourcecount+=1;
42: }
43: if (count == 0)
44: rs.CreateFolder(foldername, "/", null);
45: }
46: catch (Exception e)
47: {
48: Console.WriteLine(e.Message);
49: }
50: }
51: public void UploadReports(string ParentFolder,byte[] definition,string ReportName)
52: {
53: try
54: {
55: string parent = "/" + ParentFolder;
56: /// Create the Reports
57: ///
58: Warning[] warnings = null;
59: rs.CreateCatalogItem("Report", ReportName, parent, true, definition, null, out warnings);
60: if (warnings != null)
61: {
62: Console.WriteLine("Report {0} could not be uploaded to folder {1}", ReportName, ParentFolder);
63: foreach(Warning war in warnings)
64: Console.WriteLine("Warning Generated {0}", war.Message);
65: }
66: }
67: catch (Exception e)
68: {
69: Console.WriteLine(e.Message);
70: }
71:
72: }
73: public void UploadDataSource(string name, string extension, string connstring)
74: {
75: const string Parentpath = "/";
76: DataSourceDefinition definition = new DataSourceDefinition();
77: definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated;
78: definition.ConnectString = connstring;
79: definition.Extension = extension;
80: definition.Enabled = true;
81: definition.EnabledSpecified = true;
82: definition.ImpersonateUserSpecified = true;
83: // Use the default prompt string.
84: definition.Prompt = null;
85: definition.WindowsCredentials = false;
86: try
87: {
88: rs.CreateDataSource(name, Parentpath, false, definition, null);
89: }
90: catch (Exception e)
91: {
92: Console.WriteLine(e.Message);
93: }
94: }
95: }
96: }