locked
SSRS Programmatic Import of Excel Workbook RRS feed

  • Question

  • I can manually load an excel workbook into ssrs by clicking upload and then pointing to the workbook.  The workbook appears in a section called "EXCEL WORKBOOKS"

    When I look at the record it creates, I see the workbook and the type for excel is 14.  How do I programatically upload for that Item Type?  I'm trying:

    Dim warnings As SSRS.Warning() = Nothing
    Dim parent As String = "/"
    Dim strItemType As String = "Resource"
    Dim props(0) As SSRS.[Property]
    props(0) = New SSRS.[Property]()
    props(0).Name = "MimeType"
    props(0).Value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    Dim strName As String = "JobLog.xlsx"
    Dim report As SSRS.CatalogItem = rs.CreateCatalogItem(strItemType, strName, parent, True, definition, props, warnings)
    Using "Resource" uploads a document, but it is unusable.  What is the correct setting for ItemType for this?  Thank you.

    Wednesday, February 7, 2018 6:05 PM

Answers

  • The issue was a trailing character in the Byte variable.  Solved it with:

    Dim strServerPath As String = "C:\JobLog.xlsx"
    Dim stream As FileStream = File.OpenRead(strServerPath)
    Dim definition As Byte() = Nothing
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()
    Dim warnings As SSRS.Warning() = Nothing
    Dim parent As String = "/"
    Dim strItemType As String = "Resource"
    Dim props(0) As SSRS.[Property]
    props(0) = New SSRS.[Property]()
    props(0).Name = "MimeType"
    props(0).Value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    Dim strName As String = "JobLog.xlsx"
    Dim report As SSRS.CatalogItem = rs.CreateCatalogItem(strItemType, strName, parent, True, definition, props, warnings)

    • Marked as answer by Clay Borne Friday, February 9, 2018 5:03 PM
    Friday, February 9, 2018 5:02 PM

All replies

  • Hi Clay Borne,

    Based on my research, I find similar posts to upload file on Report Manager.

    They use sample like this 

    Public Sub UploadResource()
     Dim definition As [Byte]() = Nothing
     Try
      Dim stream As FileStream = File.OpenRead("<file path>")
      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("Book for SSRS", "/", False, definition , "application/pdf",Nothing)
       Console.WriteLine("Resource: {0} published successfully with no warnings", "Book for SSRS")
     Catch e As Exception
      Console.WriteLine(e.Message)
     End Try
    End Sub 

    You could refer to this post and this post for details.

    Best Regards,
    Zoe Zhi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 8, 2018 5:24 AM
  • The issue was a trailing character in the Byte variable.  Solved it with:

    Dim strServerPath As String = "C:\JobLog.xlsx"
    Dim stream As FileStream = File.OpenRead(strServerPath)
    Dim definition As Byte() = Nothing
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()
    Dim warnings As SSRS.Warning() = Nothing
    Dim parent As String = "/"
    Dim strItemType As String = "Resource"
    Dim props(0) As SSRS.[Property]
    props(0) = New SSRS.[Property]()
    props(0).Name = "MimeType"
    props(0).Value = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    Dim strName As String = "JobLog.xlsx"
    Dim report As SSRS.CatalogItem = rs.CreateCatalogItem(strItemType, strName, parent, True, definition, props, warnings)

    • Marked as answer by Clay Borne Friday, February 9, 2018 5:03 PM
    Friday, February 9, 2018 5:02 PM