by Keyvan Nayyeri via Keyvan Nayyeri on 12/18/2006 4:09:40 PM
As I described before, TextParts are a special type of TextTokens in blog application. You can use them to create some text shortcuts to replace them with a longer text when post is being rendered. In Community Server 2.1 TextParts are known as Snippets.
Before talking about development details it's worth to have a background about TextParts structure. Each TextPart consists of several colon delimited values that build it. For example, suppose this TextPart: [Keyvan:Nayyeri:1984]. It consists of three separate values: Keyvan, Nayyeri and 1984.
In Community Server APIs two classes and one namespace provide appropriate tools to work with TextParts:
Now it's time to see some details about above classes and namespace.
TextPart class has four properties:
This class also has three main methods:
Note that you can refer to a specific element in a TextPart using an index because it represent elements like an array. For example by using TextPart[1] in my example, you can get "Nayyeri" value. On the other hand you can use Get() method to do this.
TextPartSet is another class which works as a collection for TextPart objects. You'll see its usage in next section when I describe static methods in TextPartManager but for now I'd like to say you can retrieve an instance of TextPart object by referring to an index or by calling Get() method in this class. You can also iterate through all TextPart objects in it.
This namespace is where you can find two useful static methods:
Let's discover a sample. In below code, I write a function which parses current post and finds all TextParts in its body then replaces all TextParts with "Here was a TextPart" text. It finally returns a new value for post body.
String GetFormattedBody()
{
CSContext context = CSContext.Current;
String body = context.Post.Body;
TextPartSet textParts = TextPartManager.Parse(body);
foreach (TextPart textPart in textParts)
body = textPart.Replace(body, "Here was a TextPart");
}
TextPart part = new TextPart();
return body;
Now playing: Fandango Nights - Willie And Lobo
Original Post: CS Dev Guide: TextParts
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.