1

I have a web service to an SSRS server from which I download and serialize reports to XML in C#, and then later save as .rdl files.

I have the possibility to get the all the Data Source's aswell, with

ReportingService2005 rs = new ReportingService2005();
DataSource dataSource = new DataSource();
DataSourceDefinition dataSourceDefinition = rs.GetDataSourceContents(path);
dataSource.Item = dataSourceDefinition;

I want to save the data source objects as .ds or .rds files but I don't know how. Is there a way I can do this using XML serializing or are there any easier methods?

Daniel B
  • 8,770
  • 5
  • 43
  • 76
  • 1
    Is there a reason you're not just grabbing this all out of the ReportServer.dbo.Catalog table? – kyzen Jun 24 '14 at 14:37

2 Answers2

3

I had the same issue, I used the XML serialize to serialize the DataSource object here is the code snipet:

DataSource ds = new DataSource();
                    DataSourceDefinition dsDefinition = rs.GetDataSourceContents(item.Path);
                    ds.Item = dsDefinition;
                    sOutFile = string.Format(@"{0}{1}.rds", sOutputDir, item.Name);
                    if (File.Exists(sOutFile))
                        File.Delete(sOutFile);
                    SerializeObject(sOutFile, ds);   // serializes the dataSource object and save it

here is the SerializeObject method, it serializes and then saves the file in XML format:

private void SerializeObject(string filename, DataSource d)
    {
        try
        {
            XmlSerializer serializer =
            new XmlSerializer(typeof(DataSource));
            // Create an XmlTextWriter using a FileStream.
            Stream fs = new FileStream(filename, FileMode.Create);
            XmlWriter writer =
            new XmlTextWriter(fs, Encoding.Unicode);
            // Serialize using the XmlTextWriter.
            serializer.Serialize(writer, d);
            writer.Close();
        }
        catch (Exception e) { MessageBox.Show("inside serializeObject Method "+e.Message); }
    }

I hope this helps if someone is stuck with this issue

sujay
  • 681
  • 1
  • 8
  • 23
0

As kyzen suggested in the comment, I used a combination of some custom code and this post from SO Listing all Data Sources and their Dependencies (reports, items, etc) in SQL Server 2008 R2 to get the result I wanted.

Community
  • 1
  • 1
Daniel B
  • 8,770
  • 5
  • 43
  • 76