Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

Get Knowledge Article Content Programmatically Using the SDK

$
0
0

I’ve had a few people ask how to do this recently so, here goes!

Getting knowledge article objects using the SDK is the same as getting any other kind of object except with a slight twist.  The System.Knowledge.Article class is one of the few classes in the data model out of the box that has binary data type properties.  Here is a look at the class properties on the System.Knowledge.Article class:

clip_image001

See those two properties there that are binary data type – EndUserContent and AnalystContent?  That’s the tricky bit (pun intended!).

When we are working with a binary data type property we have to first cast the property value to a Microsoft.EnterpriseManagement.Common.BinaryStream object.  Microsoft.EnterpriseManagement.Common.BinaryStream derives from the System.IO.Stream class in the .Net Framework.

Let’s walk through some code.  First get a knowledge article object.  This is standard stuff.

image

 

Next we are going to get the EndUserContent property value and cast it to a BinaryStream object:

image

Now that we have a Stream to work with we can use a StreamReader to read the binary content into a string:

image

 

Viola!  Now, another twist is that knowledge in SCSM is stored in RTF format.  You don’t want to show the user the RTF format content so you need to use something like a RichTextBox class control to display the content to the user with the RTF formatting tags hidden and showing the text in the correct format.

In this example I simply assign the string (which contains RTF content) to the .Rtf property of the RichTextBox control:

image

 

Here is what the simple demo app looks like after I have clicked the button that has a knowledge article containing RTF formatted text in the EndUserContent property:

image

 

I’ve uploaded this code sample project to the TechNet Gallery if you want to grab it.

http://gallery.technet.microsoft.com/Get-SCSM-Knowledge-Article-78e1ec58


Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>