Thursday, 12 July 2012

Welcome Screen Web part to see current login user name and their details from list in sharepoint 2010

  • Create Visual webpart project in visual studio 2010.
  • Open Visual webpart .ascx file and design ur requirement.
  • Here i posted my coding for reference
  • <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="EMPPortalWelcomeScreen.VisualWebPart1.VisualWebPart1UserControl" %>

    <style type="text/css">
    .style3
    {
        font-size:20px;
       
        font-family: Calibri;
       
    }

    .style5
    {
        font-size:20px;
        font-family: Calibri;
       
    }
    .style6
    {
        font-size:20px;
       font-family: Calibri;
       
    }


    </style>
    <table style="background: url('/sites/site collection name/Style%20Library/oie_jpg.png'); background-repeat: no-repeat; width: 610px; height: 480px">
        <tr>
            <td align="center">
                <table style="width: 580px; height: 50px;">
                    <tr>
                        <td>
                            <h1 style="font-family: Calibri; color: #000000; text-align: left; font-size: 20px">Title of ur webpart</h1>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align="center" valign="middle">
                <table style="width: 580px; height: 350px; border: 1px solid #000;">
                    <tr>
                        <td align="left" valign="top">
                            <h1 style="color: #000000; font-size: 20px; font-family: Calibri; text-align: center">WELCOME MESSAGE</h1>
                            <asp:Label ID="Label1" runat="server" Style="font-family: Calibri; color: #000000; text-align: left; font-size: 20px; margin-left: 20px"></asp:Label>
                            <br />
                            <asp:Label ID="Label2" runat="server" Style="font-family: Calibri; color: #000000; text-align: left; font-size: 20px; margin-left: 20px"></asp:Label>
                            <asp:Label ID="Label3" runat="server" Style="font-family: Calibri; color: #000000; text-align: left; font-size: 20px"></asp:Label>
                           </td>
                <tr>
                </table>
                               
                        </td>
                    </tr>
                </table>
           
  • Open visual webpart .cs file and paste the below coding
  • using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;


    namespace name.VisualWebPart1
    {
        public partial class VisualWebPart1UserControl : UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
              
                string username;
                SPSite mySite = SPContext.Current.Site;
                SPWeb web = mySite.OpenWeb();
                SPUser user = web.CurrentUser;
                username = user.LoginName;
                username = user.ToString();
                username = user.Name;
                //
                SPList list = web.Lists["list name"];
                SPListItemCollection listitemcollection = list.Items;
                DataTable table = new DataTable();
                DataTable dtList = list.GetItems().GetDataTable();
                DataRow[] drUser = dtList.Select("[Member] = '" + username + "'");                                      if (drUser.Length > 0)
                {
                    string strUserName = drUser[0]["Member"].ToString();
                    Label1.Text = strUserName;
  • //According to ur requirement u can use ur field
                    string strUserRole = drUser[0]["Role"].ToString();
                    Label2.Text = strUserRole+",";
                    string strUserBoard = drUser[0]["Board"].ToString();
                    Label3.Text = strUserBoard;                                                                                              }}}}
     
  • Then go to ur sharepoint site
  • In that Edit Page->Place the cursor in any of your home page->Add Webpart->Custon->Visual webpart(ur webpart) then give ok now it ll come in your welcome screen
  • You can see ur output now.
  • If u have any doubt in this please post it below.

1 comment:

  1. How to send multiple row values in single mail using designer workflow..???

    ReplyDelete