Sunday, February 19, 2012

CreateResource

I haven't seen any examples floating around dealing with uploading a resource (ie Excel, Word...) to the report server through the CreateResource method. Does anyone have any experiences with this or some insite to share?Take a look at the following C# code snippet. It will read short file from
your current directory and publish it into report server detecting the mime
type. Code is not perfect but it will get you started.
sourceFileName - contains file name only
rs - is the proxy for the web service
string mimeType = "";
FileInfo fi = new FileInfo( sourceFileName );
if( fi.Extension != null && fi.Extension.Length != 0 ) {
RegistryKey ctrk = Registry.ClassesRoot.OpenSubKey( fi.Extension );
if( null != ctrk ) {
mimeType = (string)ctrk.GetValue( "Content Type" );
}
ctrk.Close();
}
Stream s = File.Open(sourceFileName, FileMode.Open, FileAccess.Read);
byte[] ResourceData = new Byte[s.Length];
s.Read(ResourceData, 0, (int)s.Length);
s.Close();
rs.CreateResource( sourceFileName, "/", false, ResourceData, mimeType,
null );
Dmitry Vasilevsky, SQL Server Reporting Services Developer
This posting is provided "AS IS" with no warranties, and confers no rights.
--
---
"Dean" <Dean@.discussions.microsoft.com> wrote in message
news:744C1CDB-30F4-4912-9C47-D51634917E2C@.microsoft.com...
> I haven't seen any examples floating around dealing with uploading a
resource (ie Excel, Word...) to the report server through the CreateResource
method. Does anyone have any experiences with this or some insite to share?|||Should work just fine. Nothing really to it. Here is an example:
byte[] contents = null;
ReportingService rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
FileStream stream = File.OpenRead("Test Document.doc");
contents = new Byte[stream.Length];
stream.Read(contents, 0, (int) stream.Length);
stream.Close();
rs.CreateResource("Test Document", "/", true, contents,
"application/msword", null);
Bryan Keller
Developer Documentation
SQL Server Reporting Services
A friendly reminder that this posting is provided "AS IS" with no
warranties, and confers no rights.
"Dean" <Dean@.discussions.microsoft.com> wrote in message
news:744C1CDB-30F4-4912-9C47-D51634917E2C@.microsoft.com...
> I haven't seen any examples floating around dealing with uploading a
resource (ie Excel, Word...) to the report server through the CreateResource
method. Does anyone have any experiences with this or some insite to share?

No comments:

Post a Comment