Windows Sharepoint Services

Most of you might have heard about this buzz word WSS (Windows Sharepoint Services), which is an ideal solution for team sites or collaboration sites. It’s freely available and if you wish you can download it from here. But you need to have Windows 2003 server in your machine for WSS 3.0

Once you installed Sharepoint Services you can create a site collection using the Central Administration tool. Site creation so easy and that would take less than a miniute, and Sharepoint will create a site for you.

You can download screencasts here and learn to play with Sharepoint Services, because I used it and I know the power of it. It’s a brilliant solution for having a content management system to maintain by a particular team.

Advertisements

Multiview Control [ASP.net]

This simple article is about using the Multi View control in ASP.net.

The Multi View control is useful when you have different type of content to be display in one page. Multiview control is an ideal solution for that.

  1. First simply create a new project.
  2. Then drag a MultiView control to the page from the tool box.
  3. Now drag n drop view control from the tool box.
  4. So now you can add any content into this view control (Ex:-Textbox)
  5. You can add many view controls as you like, so that you can have separate content in your page.
  6. For your simplicity, I have shown my Default.aspx page so that you can follow that protoype.

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“><html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
    <title>Untitled Page</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
        <br />
        <asp:RadioButtonList ID=”RadioButtonList1″ runat=”server” AutoPostBack=”True” OnSelectedIndexChanged=”RadioButtonList1_SelectedIndexChanged”
            RepeatDirection=”Horizontal”>
            <asp:ListItem Value=”0″>View 1</asp:ListItem>
            <asp:ListItem Value=”1″>View 2</asp:ListItem>
            <asp:ListItem Value=”2″>View 2</asp:ListItem>
        </asp:RadioButtonList><br />
        <br />
        <asp:MultiView ID=”MultiView1″ runat=”server”>
            <asp:View ID=”View1″ runat=”server”>
        <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox><br />
        <br />
        <asp:Button ID=”Button1″ runat=”server” Text=”Button” /> </asp:View>
            <asp:View ID=”View2″ runat=”server”>
                <asp:Calendar ID=”Calendar1″ runat=”server”></asp:Calendar>
            </asp:View>
            <asp:View ID=”View3″ runat=”server”>
                <asp:FileUpload ID=”FileUpload1″ runat=”server” /></asp:View>
        </asp:MultiView><br />
        <br />
    </form>
</body>
</html>

In this example I used a radio button list to display different ‘Views’. You need to provide the handler event for that radioButton list. So poen your Default.aspx.cs and put the code below.using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = Convert.ToInt32(RadioButtonList1.SelectedValue);
    }
}

 Now everything is done, simply run the project. As you select different radio buttons, the page is posted back and different content will be displayed in the same page. cool!

Enjoy!!!

Cross page postback in ASP.net

This is a very simple article about the cross page post back in asp.net.
So for this project I have 2 pages, namely Default.aspx and Page2.aspx. My Default.aspx looks like below.

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“><html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
    <title>Untitled Page</title>
</head>
<body>
    <form id=”form1″ runat=”server” defaultbutton=”Button1″ defaultfocus=”TextBox1″>
    <div>
        <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox><br />
        <br />
        <asp:Button ID=”Button1″ runat=”server” PostBackUrl=”~/Page2.aspx” Text=”Go to Next Page” /> </div>
    </form>
</body>
</html>

As you can see it simply contains a Textbox and a Button.
My Page2.aspx is something like below.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Page2.aspx.cs” Inherits=”Page2″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
    <title>Untitled Page</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        <asp:Label ID=”Label1″ runat=”server” Text=”Label” Width=”414px”></asp:Label><br />
        <br />
        <a href=”Default.aspx” mce_href=”Default.aspx”>Default.aspx</a></div>
    </form>
</body>
</html>

In addition to that I put the following code into my Page2.aspx.cs page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Page2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            TextBox mytext = (TextBox)PreviousPage.FindControl(“TextBox1”);
            Label1.Text = String.Format(“Welcome to the ASP.NET world {0}”, mytext.Text);
        }
    }
}

So make sure that the ID of your textbox in Default.aspx page is “TextBox1” or else you can give any name provided that name should pass into the FindControl function.

Now simply run the appliation, and you’ll see your textbox entry in the Default.aspx page is displayed in the label of the Page2.aspx

Enjoy!!!

A Simple RSS Reader

In this post I thought of publishing a code snippet regarding how to build a simple RSS reader. Here I explained how to build a RSS reader as a user control so that you can re-use it among your web applications.

Follow these steps…

  1. Open VS 2005 & create a new project.
  2. Right-click the project title & select Add New Item. Then from the templates select Web User Control. Name that as ‘RSSList’.
  3. Go to the source view of the user control and put the following code.

  4. <%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”RSSList.ascx.cs” Inherits=”RSSList” %>
    <%@ OutputCache Duration=”3600″ VaryByParam=”None” %>

    <asp:Repeater ID=”Repeater1″ runat=”server”>
    <HeaderTemplate>
    <table border=0 style=”width: 240px; font-size: x-small; color: black; font-family: Verdana;”>
    <thead>
    <tr style=”font-weight: bold;”>
    <td><%#this.Title%></td>
    </tr>
    <tr style=”font-style: italic;”>
    <td><%#this.Description%></td>
    </tr>
    </thead>
    </table>
    </HeaderTemplate>

    <ItemTemplate>
    <table>
    <tr bgcolor=”LightBlue” >
    <td>
    <a target=”article” style=”text-decoration: none; color: black;” href=<%# DataBinder.Eval(Container.DataItem, “link”) %>>
    <%# DataBinder.Eval(Container.DataItem, “title”) %> </a>
    </td>
    </tr>
    <tr bgcolor=”Ivory”>
    <td style=”color: CornflowerBlue;”>
    <%# DataBinder.Eval(Container.DataItem, “description”) %>
    </td>
    </tr>
    <tr style=”font-size: x-small; color: black; font-family: Verdana;”>
    <td>Published
    <%#DataBinder.Eval(Container.DataItem, “pubDate”)%>
    </td>
    </tr>
    </table>
    </ItemTemplate>

    </asp:Repeater>

  5. Now open the RSSList.ascx.cs file & put the follwing code..

  6. using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net;
    using System.Data;

    public partial class RSSList : System.Web.UI.UserControl
    {

    public string Title;
    public string Description;

    protected void Page_Load(object sender, EventArgs e)
    {
    DataSet _rssData = RefreshFeed();

    object[] channelItems = _rssData.Tables[1].Rows[0].ItemArray;
    int titleColumn = _rssData.Tables[1].Columns[“title”].Ordinal;
    int descriptionColumn = _rssData.Tables[1].Columns[“description”].Ordinal;
    Title = channelItems.GetValue(titleColumn).ToString();
    Description = channelItems.GetValue(descriptionColumn).ToString();

    Repeater1.DataSource = _rssData.Tables[2];
    Repeater1.DataBind();

    }

    private DataSet RefreshFeed()
    {
    HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(“http://localhost/Search1/Rss.xml&#8221;);
    DataSet rssData = new DataSet();
    rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());

    return rssData;

    }
    }

  7. Now here you can give any web address of a rss news channel, but for this example I used my own xml file called ‘Rss.xml’ which is inside my IIS virtual directory. For your convenience I’ll publish my Rss.xml file at the end.
  8. Now our user control is ok, we need to test it. Therefore create a new aspx page and simply drag & drop the RSSList.acsx from the solution explorer to the design view of the page.
  9. Now you can see a new control in the design view of the page. Now our work is done. Simply run the web application.
  10. If you use my Rss.xml file you have to put it inside same virtual directory structure that I have used as in this example.
  11. When you run the application you ‘ll be able to see the News items from the news chanel that you’ve provided. (In my example it is Rss.xml)
  12. Enjoy…!!

This is my Rss.xml file…

<rss version=”2.0″>
<channel>
<title>Liftoff News</title> </channel></rss>
<link />http://liftoff.msfc.nasa.gov/ <description>Liftoff to Space Exploration.</description>
<language>en-us</language>
<pubdate>Tue, 10 Jun 2003 04:00:00 GMT</pubdate> <lastbuilddate>Tue, 10 Jun 2003 09:41:01 GMT</lastbuilddate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs&gt;
<generator>Weblog Editor 2.0</generator>
<managingeditor>editor@example.com</managingeditor>
<webmaster>webmaster@example.com</webmaster>
<item>
<title>Second post</title>
<description>This is a sample description for the second post..</description>
<time>10/16/2006 10:26:25 AM</time>
<month>October/2006</month>
</item>
<item>
<title>First post</title>
<description>here goes some sample description for the first post. I updated this news.</description>
<time>10/16/2006 10:27:34 AM</time>
<month>October/2006</month>
</item>
<item>
<title>Star City</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp <description>How do Americans get ready to work with Russians aboard the
International Space Station? They take a crash course in culture, language
and protocol at Russia’s Star City.</description>
<pubdate>Tue, 03 Jun 2003 09:39:21 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid&gt;
<time>10/10/2006 1:22:27 PM</time>
<month>November/2006</month>

<item>
<title>Space Exploration</title> </item>
<link />http://liftoff.msfc.nasa.gov/ <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada
will experience a partial eclipse of the Sun on Saturday, May 31st.</description>
<pubdate>Fri, 30 May 2003 11:06:42 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid&gt;
<time>10/10/2006 1:11:27 PM</time>
<month>December/2006</month>

<item>
<title>The Engine That Does More</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp <description>Before man travels to Mars, NASA hopes to design new engines
that will let us fly through the Solar System more quickly. The proposed
VASIMR engine would do that.</description>
<pubdate>Tue, 27 May 2003 08:37:32 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid&gt;
<time>10/10/2006 1:44:27 PM</time>
<month>November/2006</month>

<item>
<title>Astronauts’ Dirty Laundry</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp <description>Compared to earlier spacecraft, the International Space
Station has many luxuries, but laundry facilities are not one of them.
Instead, astronauts have other options.</description>
<pubdate>Tue, 20 May 2003 08:56:02 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid&gt;
<time>10/10/2006 1:31:27 PM</time>
<month>July/2006</month>

ASP.net Ajax and Javascript web features

This particular code snippet is about creating rich user interfaces using Ajax + Javascript in the .Net environment. For this example I used the atlas control toolkit which freely available to download here.

First open Visual Studio and create a new Atlas web site.

Go to the source view of Default.aspx page

Within the <head> element insert the following code.

<script type=”text/javascript”> function Show(){

document.getElementById(“display”).style.visibility=”visible”;

}

function DontShow()

{

document.getElementById(“display”).style.visibility=”hidden”;

}

</script>

Within the <form> tag put the following code

<asp:Panel ID=”display” runat=”server” Height=”59px” Width=”242px” style=”z-index: 101; left: 11px; width: 229px; position: absolute; top: 41px;

height: 88px; background-color: #ffffcc; visibility:hidden; border-right: #330000 thin solid; border-top: #330000 thin solid; border-left: #330000 thin solid; border-bottom: #330000 thin solid;”>

this is some sample tool tip

<div style=”position:absolute; left: 184px; top: 2px;”><a href=”#” onclick=”DontShow()”>Close</a></div>

</asp:Panel>

<div>

<a href=”#” onmouseover=”Show()” >Show my simple tool tip</a>

</div>

<cc1:DragPanelExtender ID=”DragPanelExtender1″ runat=”server”>

<cc1:DragPanelProperties TargetControlID=”display” DragHandleID=”display”></cc1:DragPanelProperties>

</cc1:DragPanelExtender>

Make sure that thew Register directive is placed at the beginning of the code (just after the page directive)

<%@ Register Assembly=”AtlasControlToolkit” Namespace=”AtlasControlToolkit” TagPrefix=”cc1″ %>

Now simply run the application. You can see that when you move the mouse over the link, a tool tip appears, and you can freely drag that tool tip anywhere in the document.

Web parts in ASP.NET

I thought of publishing this article showing how to play with Web parts in ASP.net. If you use VS 2005 you can try this out..

enjoy…..

 for this particular example, first you need to drag & drop a Webpart Manager control from the tool box. Then simply add a Webpart zone, so that you can drag the web parts between different Webpart zones.

And additioally I added a Webpart editor zone to allow to modify the web parts. finally simply add some controls to the Web parts that you ‘ve added so that you can view the different parts clearly.

So that’s it. Go ahead and copy the code below to the .cs file and ‘run’.using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

WebPartManager _wpmanager;

protected void Page_Load(object sender, EventArgs e)

{

}

void Page_Init(object sender, EventArgs e)

{

Page.InitComplete += new EventHandler(Init_Complete);

}

public void Init_Complete(object sender, System.EventArgs e)

{

_wpmanager = WebPartManager.GetCurrentWebPartManager(Page);

foreach (WebPartDisplayMode mymode in _wpmanager.SupportedDisplayModes)

{

string modeName = mymode.Name;

if (mymode.IsEnabled(_wpmanager))

{

ListItem myItem = new ListItem(modeName, modeName);

DropDownList1.Items.Add(myItem);

}

}

}

void Page_PreRender(object sender, EventArgs e)

{

ListItemCollection myList = DropDownList1.Items;

int sel_index = myList.IndexOf(myList.FindByText(_wpmanager.DisplayMode.Name));

DropDownList1.SelectedIndex = sel_index;

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

string selectedItem = DropDownList1.SelectedValue;

WebPartDisplayMode _mode = _wpmanager.SupportedDisplayModes[selectedItem];

if (_mode != null)

_wpmanager.DisplayMode = _mode;

}

}

 So hope this code snippet become useful to you. If you have any comments please publish them..