locked
Upload files to SSRS server RRS feed

  • Question

  • I'm currently using the RS command to automate uploading an SSRS report.

    I have created a VB.NET program and it works well.

    Problem now is that I need to upload an XSLT file together with this report.  Anyone knows any way of doing this, either using VB or even directly to the SSRS SQL Server db?

     

    Thursday, April 29, 2010 7:52 AM

Answers

  • Finally found the problem.
    The XSLT file was getting uploaded with a trailing null byte at the end of file.  Had to use a Hex viewer to see this. 

    To fix it I copied the array into another array, minus the last character and it's all good now.
       
        Dim Temp() As Byte = New Byte(ArrayLength-1) {}
        For i As Integer = 0 To ArrayLength-1
          Temp(i)=Contents(i)
        Next
        rs.CreateResource(XSLTFileName, ReportFolder, True, Temp, "application/xml", Nothing)

     

    • Marked as answer by ABR1 Friday, May 7, 2010 5:31 AM
    Friday, May 7, 2010 5:31 AM

All replies

  • What I'm looking for is essentially rs.CreateResource, but for XSLT rather than image files.

     

    Monday, May 3, 2010 8:23 AM
  • Hi ABR1,

    The CreateResource also works for uploading Excel 2007 file.
    Below is the code snippet for your reference:

    Public Sub UploadResource()
     Dim definition As [Byte]() = Nothing
      Try
        Dim stream As FileStream = File.OpenRead("D:\Libraries\Documents\Book1.xlsx")
        definition = New [Byte](stream.Length) {}
        stream.Read(definition, 0, CInt(stream.Length))
        stream.Close()
      Catch e As IOException
        Console.WriteLine(e.Message)
      End Try
      Try
        rs.CreateResource("Book1", "/", False, definition , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",Nothing)
    
          Console.WriteLine("Resource: {0} published successfully with no warnings", "Book1")
    
      Catch e As Exception
        Console.WriteLine(e.Message)
      End Try
    End Sub 

    For more information, please see:
    ReportingService2005.CreateResource Method: http://msdn.microsoft.com/en-us/library/reportservice2005.reportingservice2005.createresource.aspx

    If you have any more questions, please feel free to ask.

    Thanks,
    Jin Chen

     


    Jin Chen - MSFT
    Monday, May 3, 2010 9:31 AM
  • Hi Jin,

    Thanks for your reply.

    I did just that, but it still fails.

    It uploads fine, but when I click on the XML file, I get the message 'The XML page cannot be displayed.  Cannot view XML input using XSL style sheet.  Please correct the error and then click the Refresh button, or try again later.  Invalid at the top level of the document.  ERror processing resource 'http://localhost/Reports/Pages/Resource.aspx?ItemPath=... </xsl:stylesheet>

    When I right click on the XSLT file and save it, it tries to save it as a Resouce (type HTML) file.

    The MIMEType I used is "text.xml".  Is this correct?

    When I tried an Excel file as shown above, it works fine.

     

    Tuesday, May 4, 2010 1:17 AM
  • Hi ABR1,

    The MIME type for xml is text/xml.

    Jin Chen


    Jin Chen - MSFT
    Tuesday, May 4, 2010 10:35 AM
  • Hi Jin,

    Apologies -- it was a typo -- I used text/xml and it still does not work.  Any ideas?

     

    Wednesday, May 5, 2010 1:02 AM
  • Probably another way around it:

    How do I programatically upload an XSLT file to an SSRS server database? I would like exactly the same functionality as the 'Upload File', preferably using the 'rs' command.

    I have tried rs.CreateResource, but it doesn't seem to work for XML/XSLT files (though it works for Excel and image files)

    I understand that manipulating the SSRS db is not supported.

    Wednesday, May 5, 2010 3:12 AM
  • Finally found the problem.
    The XSLT file was getting uploaded with a trailing null byte at the end of file.  Had to use a Hex viewer to see this. 

    To fix it I copied the array into another array, minus the last character and it's all good now.
       
        Dim Temp() As Byte = New Byte(ArrayLength-1) {}
        For i As Integer = 0 To ArrayLength-1
          Temp(i)=Contents(i)
        Next
        rs.CreateResource(XSLTFileName, ReportFolder, True, Temp, "application/xml", Nothing)

     

    • Marked as answer by ABR1 Friday, May 7, 2010 5:31 AM
    Friday, May 7, 2010 5:31 AM