Populating my blog Sidebar--word 2007 advanced Applications

Source: Internet
Author: User
Tags bind

Populating my blog Sidebar--word 2007 advanced Applications

Suppose the related files in the My blog sidebar are placed in the My Blogs folder, which is structured as shown in the following illustration:

  

Figure 1

Although we can populate the Cbxblogs control by enumerating the subfolders of my blogs, I want to design a class to represent the blog and implement certain data binding. Review previous article "Create my blog Sidebar--word 2007 advanced Application (ii)", "My Blog" sidebar should have the following features:

  

  

  

It reads the relevant information in the My Blogs folder at startup and populates the Cbxblogs control;

When we select a blog in the blog list, it gets the most recent post from the blog via RSS and populates the lbxrecentposts control;

When we select a blog in the blog list, it reads the data in the blog post's draft folder and populates the Lbxdrafts control;

When we select a blog in the blog list, pressing the View Blog button will open the blog's homepage in Internet Explorer.

When we select a post in the list of recent posts, pressing the view Post button will open the page of the post in Internet Explorer.

When we select a draft in the draft list, pressing the Open draft button opens the draft in a new Word 2007.

By clarifying these requirements, we can write code:

For code #01, the following points need to be described:

Post, draft, and blog classes override the ToString () method because controls such as the ComboBox and the ListBox invoke the method and use the returned string as the entry's display, overriding the method to make the entry appear correctly. Of course, if you use a combination of DataSource and DisplayMember, you can also do without rewriting the ToString () method.

The Blog.getrecentposts () method uses the Argotic syndication framework for RSS processing, so you need to download and install it, and then reference the relevant class libraries and ARGOTIC.CORE.RSS namespaces in your project.

The Blog.getrecentposts () method assumes the RSS address, which applies to blogs and other websites, and, of course, you can think of a number of ways to make it universally applicable.

Use NetworkInterface in the Blog.getrecentposts () method. Getisnetworkavailable () method to determine whether the current network connectivity, if the general rules to obtain data, otherwise return an empty array.

The Blog.getdrafts () method does not make any filtering, assuming that the folder contains only. docx and/or. doc files. Since these files will be opened in Word 2007, if you can place a file in a folder that cannot be read by Word 2007, you might want to add a where to the LINQ query statement to filter the necessary.

In the Blog.getdrafts () method, I also assumed that my Blogs folder was placed in my documents, and that the folder name of the blog was the same as the blog name, of course, so that we could not include illegal path characters in the name of the blog.

We can make the name of the folder the same as the name of the blog, but we can't include the URL information of the blog here, and this is the premise of many operations, so I placed a blogs.xml file in my Blogs folder, which contains the following:

With this file, we can successfully access the URL information of the blog. In addition, if you want your blog's name to be not constrained by the path, which can contain illegal path characters, you can extend a directory attribute for the blog element to store the path so that the name attribute can be used specifically for display on the interface.

Value-added service Area

You can go through Path. Getinvalidfilenamechars () or path. Getinvalidpathchars () method to view illegal path characters.

The next step is to populate the "my Blog" sidebar with the data, and go back to MyBlogsUserControl.cs and add the following code in the constructor:

  

For code #02, the following points need to be described:

We use LINQ to XML to get the relevant data for the blogs in Blogs.xml and bind the data to the blog list.

We get the value of the Defaultblog property of the blogs element and use it to set the Cbxblogs.selectedtext property so that the default blog it specifies becomes the currently selected blog.

If we agree that the first blog element is the default blog, then there is no need to use the Defaultblog property and set the SelectedText property, because when we bind a data source to the DataSource property, It sets the first entry to the currently selected item after the binding is complete, and of course, selectedvaluechanged (and other related) events are raised at this time.

Oh, don't forget the Cbxblogs selectedvaluechanged event, here is the event Handler:

  

It is worth reminding that the number of elements of the array returned by the Blog.getrecentposts () method is related to the setting of the corresponding blog:

  

Figure 2

Now look at the effect of the operation:

  

Figure 3

The next chapter will introduce anyone who uses Word 2007 to view blogs, recent posts, and archive drafts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.