views:

172

answers:

2

Hi all, 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. Thanks

A: 

This is the code SSMS generated when I tried to upload an xml file:- Dim Resource As String = "home" Dim Parent As String = "/" Dim Overwrite As Boolean = false Dim Contents() As Byte = New Byte() {} Dim MimeType As String = "text/xml" Dim Properties(-1) As Microsoft.SqlServer.ReportingServices2005.[Property]

RS.CreateResource(Resource, Parent, Overwrite, Contents, MimeType, Properties)

Are you specifying the correct MimeType?

SPE109
I'm trying your code above.Could you please write the next couple of lines of your code?The part where you put data into Contents -- did you use stream.Read(...)?
xt_20
The code was scripted out of SSMS. But I think you would be able to do something like:- stream = File.OpenRead("<FILE NAME AND PATH>") fileData = New [Byte](stream.Length) {} stream.Read(fileData, 0, CInt(stream.Length))
SPE109
Yup that's what I did.My code:Dim stream As FileStream = File.OpenRead(dir + filename)Dim Contents() As Byte = New Byte(stream.Length) {}stream.Read(Contents, 0, CInt(stream.Length))stream.Close()rs.CreateResource(XSLTFilename, ReportFolder, True, Contents, "application/xml", Nothing)
xt_20
A: 

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)
xt_20