Welcome to MSDN Blogs Sign in | Join | Help

Piyush Shah's Blog

Software Development Engineer @ MSDN & Technet
Get SharePoint Template Id's for any List

Recently I was writing a "Sharepoint Feature" and I wanted to find the Template Id for "Pages Library" and it took me a while to find it. However I discovered a way to find it without frantically searching for it or writing code to loop through all the Lists in a Site. To find a Template Id for a particular list -

  • Go to List view of the template. E.g. For Pages Library it is typically

http://ServerName/Pages/Forms/AllItems.aspx

For Images it will be - http://ServerName/PublishingImages/Forms/AllItems.aspx 

  • Do View Source and search for "ctx.listTemplate"

For Pages Library it will show - "ctx.listTemplate = 850;" and for Images it will show "ctx.listTemplate = 101;"

Windows server 2008 Tips

I installed Windows Server 2008 RTM over this weekend. It is pretty cool and FAST!

Here are some Tips/Tricks I made to it -

  1. Desktop Features –
    1. To have the Desktop features like Windows Media player, Themes, Sidebar, etc. you will have to enable the Feature in Server Manager. As shown below -
    2. Start the “Themes” Service – This is disabled by default. Run “Services.msc” and Enable the service and Set it to Automatic.
    3. Go to Control Panel\Appearance and Personalization\Personalization and select “Window Color and Appearance” and click on “Open Classic Apperance”. Select “Windows Aero”
  2. Internet Explorer enhanced - If you want to disable IE Enhanced security, again go into Server Manager and Click on "IE ESC"
  3. Terminal Services Console - Usually I terminal service into a machine in console mode and to my surprise that did not work in Server 2008. The correct command is mstsc /admin
  4. Hyper V - This is the next version of Virtualization. With Server 2008 RTM, Hyper V is still Beta. But I like this feature the most in Server 2008. Unlike previous versions of Virualization, this time the virtualization runs directly on the system hardware rather than going through a Virtual server host. Additional features include the ability to take snapshots of your VM's, compact if they are too bloated or expand if they are filled up, etc.
  5. Hyper V Network Adapter not recognized - If you have run into a situation where the Network Adapter is not being recognized in the VM. Add "Legacy Network Adapter" to your VM in HyperV as shown below

 

Start the VM and you should have a Network connection in your VM.

 

If you know any more, I would like to add it to the list. Please let me know.

 

How much time does it take to copy 9GB file on Longhorn?

Recently I tried to copy a 9GB file. See below on the time it shows the task would complete - 24606 Days and 2 hours, which means I need to wait for 67.5 years.

Oh BTW this is in Longhorn RC0. But in all fairness after a few seconds it changed to 34 minutes. Phew! at least I don't have to wait a Long(horn) time.

ASP.Net RssToolkit Version 2.0

I have been part of the team working on the latest version ASPNET RssToolkit, originally created by Dmitry Robsman. We enhanced this awesome Toolkit and have just released version 2.0 of the Toolkit. Please check out Codeplex to download this toolkit.

Here are some of the changes in this version –

  • Consume and publish Atom/Rdf/Opml feeds.
  • Strongly typed classes, close to Rss specification.
  • Feeds Aggregation using OPML. The outlines in OPML can have Rss/Atom/Rdf.
  • Rss Schema validation during aggregation.
  • Download Manager can be used to download any Url and return a Stream. It also has inbuilt caching mechanism. 
  • Added support for Extensions and Enclosures.
  • Added Visual Studio Testing Framework Unit Tests.
  • Rearranged Namespaces to closely match the features.

Here is how to use the RssToolkit. I have taken excerpts from ScottGu’s review on the original RssToolkit.

Consuming Feeds using RssToolkit -

A.      Using RssDataSource – This webcontrol gives you the ability to databind to an Rss/Atom/Rdf/Opml feed. It inherits from DataSourceControl to give itself the ability serve as a data source to data-bound controls. Here are the steps you can take to use RssDataSource in your page or user control –

1.       Add the RssDataSource and RssHyperLink to the Toolbox in Visual Studio.

Toolbox 

2.       In your Web form, drop the RssDataSource.

3.       Click the control and “Configure Data Source”

Configure RssDataSource 

4.       It ask you for the feed Url. The RssDataSourceConfigForm.cs is used in this case.

You can provide RSS/ATOM/RDF/OPML and RssDataSource will automatically identify the feed type and provide Databinding capability.

As you can see below, I’m actually providing an Atom feed URL to the RssDataSource.

RssDataSourceConfigForm 

5.       You can then bind a control like Gridview to this DataSource.

Configure Grid to use RssDataSource 

6.       I will “Edit Columns” on the GridView and have 2 columns, as shown –

Grid Columns for RssDataSource 

7.       You can also specify the number of items you want to be returned back. I will go in the code behind and change that to 5

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="RssToolkit" Namespace="RssToolkit.Web.WebControls" TagPrefix="cc1" %>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Consuming Google News using RssToolkit</title>

</head>

<body>

    <form id="form1" runat="server">

    Google News (Atom Format)

    <div>

        <cc1:rssdatasource id="RssDataSource1" runat="server" maxitems="5" url="http://news.google.com/?output=atom"></cc1:rssdatasource>

    </div>

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="RssDataSource1">

            <Columns>

                <asp:HyperLinkField DataNavigateUrlFields="link" DataTextField="link" HeaderText="Link"/>

                <asp:BoundField DataField="title" HeaderText="Title" SortExpression="title" />

            </Columns>

        </asp:GridView>

    </form>

</body>

</html>

 

8.       Compile and View the page in browser –

RssDataSource Output 

B.      Consume using RssDocument.cs – RssDocument.cs class can be used from your code if you want to consume/publish or manipulate feeds. It provides various overloads for Loading a feed –

RssDocument Class 

·         Load - takes 3 overloads System.Uri, Xml string and XmlReader. You can provide Rss/Atom/Rdf/Opml type of formats for these 3 overloads and it will automatically identify the base feed type and construct the class.

·         SelectItems – this method returns IEnumerable which gives the ability to iterate over the collection. It is also used internally to provide data binding capability to RssDataSource.

·         ToXml – this method which returns an Xml as a string, provides the capability of publishing the feed into Rss/Atom/Rdf/Opml formats. The input parameter (DocumentType enum) suggests the format of Xml returned by this method.

·         ToDataSet – this method returns the feed as a DataSet.

Here is how to use the RssDocument –

void Page_Load(object sender, EventArgs e)

 {

    RssToolkit.Rss.RssDocument rss = RssToolkit.Rss.RssDocument.Load(new System.Uri("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml"));

    Image1.ImageUrl = rss.Channel.Image.Url;

    GridView1.DataSource = rss.SelectItems();

    GridView1.DataBind();

 }

C.      Consume using Custom Generated Class and RssDl.exe – Let’s say you want to consume a feed which has some extensions that is not specified in the Rss specification such as Media Rss by Yahoo.
An example of Media Rss tags are -
<media:player url="http://youtube.com/?v=dMH0bHeiRNg" />
<media:thumbnail url="http://sjc-static6.sjc.youtube.com/vi/dMH0bHeiRNg/2.jpg" width="120" height="90" />
<media:title>Evolution of Dance</media:title>
<media:category label="Tags">Dancing comedy</media:category>
<media:credit>judsonlaipply</media:credit>


You can still get strong typing for these extensions by generating a custom class using the RssDl.exe

 

Usage – RssDl.exe “URL” “ClassName.cs”

E.g.

RssDl.exe “http://youtube.com/rss/global/top_favorites.rss” “YouTube.cs”

RssDl.exe “http://news.google.com/?output=rss” “GoogleNews.vb”

  As shown below I created a custom class for YouTube’s Top favorites feed, which has Media Rss tags.

RssDl 

                If you open the newly created class “YouTube.cs” you will see the extensions as Strongly typed properties inside the class.

    [XmlElement("player", Namespace="http://search.yahoo.com/mrss/")]

    public YoutubePlayer Player {

        get {

            return _player;

        }

        set {

            _player = value;

        }

    }

   

    [XmlElement("thumbnail", Namespace="http://search.yahoo.com/mrss/")]

    public YoutubeThumbnail Thumbnail {

        get {

            return _thumbnail;

        }

        set {

            _thumbnail = value;

        }

    }

   

    [XmlElement("category", Namespace="http://search.yahoo.com/mrss/")]

    public YoutubeCategory Category {

        get {

            return _category;

        }

        set {

            _category = value;

        }

    }

   

    [XmlElement("credit", Namespace="http://search.yahoo.com/mrss/")]

    public string Credit {

        get {

            return _credit;

        }

        set {

            _credit = value;

        }

    }

 

 

You will have to embed this class in your application or put in App_Code folder of your website. You can then use the class just like RssDocument.cs.

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Youtube Media Rss</title>

 

    <script language="c#" runat="server">

        void Page_Load(object sender, EventArgs e)

        {

            YoutubeRss rss = YoutubeRss.Load();

            DataList1.DataSource = rss.Channel.Items;

            DataList1.DataBind();

        }

    </script>

 

</head>

<body>

    <form id="form1" runat="server">

        You Tube Top Favories(Media Rss)

        <asp:DataList ID="DataList1" runat="server" RepeatColumns="3" GridLines="both">

            <ItemTemplate>

                <asp:Image ID="Image1" runat="Server" ImageUrl='<%# Eval("Thumbnail.Url")  %>' /><br />

                        <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# Eval("Player.Url") %>' Text='Link' runat="server" />

            </ItemTemplate>

        </asp:DataList>

    </form>

</body>

</html>

 

Here is what the page looks like -

Consuming Media Rss using RssToolkit 

Aggregation

RssToolkit provides Aggregation using Outline Processor Markup Language (OPML). Check out the OPML specification here. OPML is used for creating a list of feeds known as Outlines to be shared or aggregated. Here is what an OPML format looks like –

<?xml version="1.0" encoding="iso-8859-1"?>

<opml version="1.1">

  <head>

    <title>List of Feeds News Feeds</title>

    <dateCreated>Tue, 11 Nov 2003 19:47:24 GMT</dateCreated>

    <dateModified>Tue, 11 Nov 2003 19:47:28 GMT</dateModified>

    <ownerName>Webmaster</ownerName>

    <ownerEmail>owner@msdn.com</ownerEmail>

    <expansionState></expansionState>

    <vertScrollState>3</vertScrollState>

    <windowTop>93</windowTop>

    <windowLeft>127</windowLeft>

    <windowBottom>585</windowBottom>

    <windowRight>710</windowRight>

  </head>

  <body>

    outline text='BBC News’ description='Updated every minute of every day - FOR PERSONAL USE ONLY' htmlUrl='http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/default.stm' language='unknown' title='BBC News' type='rss' version='RSS' xmlUrl='http://news.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss091.xml'/>

    <outline text='CNET News.com' description='Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media.' htmlUrl='http://news.com.com/' language='unknown' title='CNET News.com' type='rss' version='RSS2' xmlUrl='http://news.com.com/2547-1_3-0-5.xml'/>

  </body>

</opml>

 

As seen above the Outline has the information of the feeds to be aggregated, XmlUrl provides the Url of the Feed.

To aggregate Feeds using RssToolkit you need to provide the location of the OPML file or proved the OPML Xml. You can use the Load method in the RssDocument.cs Class for Aggregation. As shown before the Load of RssDocument has 3 overloads –

public static RssDocument Load(string xml);
public static RssDocument Load(Uri url);
public static RssDocument Load(XmlReader reader);

 

Example -

RssDocument rssAggregatedFeed = RssDocument.Load (new System.Uri("http://static2.podcatch.com/blogs/gems/opml/mySubscriptions.opml"));

Publishing your Feeds

 

RssHyperLink – This WebControl can be used for publishing your Feed. You can point this tool to the feed location and it automatically generates link tag -

<link rel="alternate" type="application/rss+xml" title="Rss" href="~/RssHyperLink.ashx" />

 

This tag enables Feed Autodiscovery in browsers. It enables the Rss Autodiscovery in IE and FireFox. To publish the feeds using RssToolkit, you can use one of the mechanisms below –

 

A.       Using ASP.Net Buildprovider mechanism – RssToolkit uses ASP.Net BuildProvider class to automatically detect certain files created or modified in the filesystem. It automatically generates code and compiles the code for any files with extension *.rss or *.rssdl. RssToolkit then uses RssDocument.cs class and De-serializes the feed. It also builds an HttpHandler, which you can then inherit from to publish your feed.

In the samples provided. The App_Code folder has Sample5.Rss

<?xml version="1.0" encoding="utf-8"?>

<rss version="2.0">

    <channel>

        <title>Sample Channel</title>

        <link>~/RssHyperlinkFromCustomClass.aspx</link>

        <description>Channel For Scenario5 in ASP.NET RSS Toolkit samples.</description>

        <ttl>10</ttl>

        <name></name>

        <user></user>

        <pubDate>Tue, 10 Apr 2007 23:01:10 GMT</pubDate>

        <lastBuildDate>Tue, 10 Apr 2007 23:01:10 GMT</lastBuildDate>

        <webMaster>webmaster@email.com</webMaster>

        <item>

            <title></title>

            <description></description>

            <link></link>

        </item>

        <item>

            <title></title>

            <description></description>

            <link></link