Wednesday, 4 July 2012

DL(DAL)

STEP 1: Create a class file like AppsDL.cs


namespace VCSB.INTRANET.DAL
{
    public class AppsDL
    {
        public static  void GetAppsListItem(DataList Apps)
        {
            SPSite spsite = SPContext.Current.Site;
            SPWeb spweb = spsite.OpenWeb();
            SPList spList = spweb.Lists["AppsCategory"];
            SPList spList1 = spweb.Lists["Apps"];
            SPListItemCollection spListItems = spList.Items;
            SPListItemCollection spListItems1 = spList1.Items;

            var query1 = from SPListItem pi in spList.Items
                         select pi;
            DataTable dd1 = new DataTable();
            dd1.Columns.Add("Title");
            DataRow row;
            foreach (var grp in query1)
            {
                row = dd1.Rows.Add();
                row["Title"] = Convert.ToString(grp.Title);
            }
            Apps.DataSource = dd1;
            Apps.DataBind();

            var query = from SPListItem pi in spList.Items
                        from SPListItem ci in spList1.Items
                        where pi.Title.ToString().Equals(new SPFieldLookupValue(ci["Category"].ToString()).LookupValue)
                        select new { Parent = pi, Child = ci };

            DataTable ds1 = new DataTable();
            ds1.Columns.Add("Title");
            ds1.Columns.Add("Category");
            ds1.Columns.Add("AppsUrl");
            DataRow row1;
            foreach (var grp1 in query)
            {
                row1 = ds1.Rows.Add();
                row1["Title"] = Convert.ToString(grp1.Parent.Title);
                row1["Category"] = Convert.ToString(grp1.Child.Title);
                row1["AppsUrl"] = Convert.ToString(grp1.Child["AppsURL"]);

            }


            DataSet test = new DataSet();
            test.Tables.Add(ds1);

            foreach (DataListItem item in Apps.Items)
            {
                string dataTitle = Convert.ToString(Apps.DataKeys[item.ItemIndex]);
                DataList gvr = (DataList)Apps.Items[item.ItemIndex].FindControl("Appscat");
                DataTable dt = new DataTable();
                dt.Columns.Add("Category");
                dt.Columns.Add("AppsUrl");
                foreach (DataRow item1 in test.Tables[0].Rows)
                {
                    DataRow drr = dt.NewRow();
                    if (Convert.ToString(item1["Title"]) == dataTitle)
                    {
                        drr["Category"] = item1["Category"].ToString();
                        drr["AppsUrl"] = Convert.ToString(item1["AppsUrl"]);
                        dt.Rows.Add(drr);
                    }
                }
                gvr.DataSource = dt;
                gvr.DataBind();
            }
           
        }

    }
}


ASCX(ascx.cs)

STEP 1: Create a VisualWebPart like AppsDetailsPage

STEP 2: Write a coding in AppsDetailsPageUserControl.ascx.cs 


STEP 3:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Linq;
using VCSB.INTRANET.BLL;
using VCSB.INTRANET.DAL;


namespace VCSB01.INTRANET.WebPartDetailsPage.AppsDetailsPage
{
    public partial class AppsDetailsPageUserControl : UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    BindGrid();
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.Add(Convert.ToString(ex.Message), Convert.ToString(ex.StackTrace));
                SPUtility.TransferToErrorPage(MessageHelper.Message(MessageMode.CommonErrorMessage));
            }
        }
       

        public void BindGrid()
        {
            AppsDL.GetAppsListItem(Apps);
           
        }
        protected void Apps_ItemDataBound(object sender, DataListItemEventArgs e)
        {
           
        }
       
    }
}
 

ASCX(.ascx)

STEP 1: Create a VisualWebPart like AppsDetailsPage

STEP 2: Write a coding in AppsDetailsPageUserControl.ascx


STEP 3:

<asp:DataList runat="server" ID="Apps" RepeatColumns="3" RepeatDirection="Horizontal"
    OnItemDataBound="Apps_ItemDataBound" DataKeyField="Title" CellPadding="10" CellSpacing="10">
    <ItemStyle VerticalAlign="Top" />
    <ItemTemplate>
        <table cellpadding="0" cellspacing="0" width="298px" border="0">
            <tr>
                <td class="apps_title">
                    <%# Eval("Title")%>
                </td>
            </tr>
            <tr>
                <td class="apps_center">
                    <asp:DataList ID="Appscat" runat="server">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkbtnUrl" CausesValidation="false" PostBackUrl='<%# Eval("AppsUrl")%>'
                                runat="server">
                                                   <%# Eval("Category")%>
                            </asp:LinkButton>
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
            <tr>
                <td class="apps_bottom">
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>
 

Wednesday, 20 June 2012

ASCX(.ascx)

STEP 1: Create a VisualWebPart like DepartmentImage

STEP 2: Write a coding in DepartmentImageUserControl.ascx


STEP 3:



<div class="menu_bg_sd_new">
    <div class="menu_left_sd_new">
    </div>
    <div class="menu_right_sd_new">
    </div>
</div>
<div class="menu_bg_sd_mid">
    <table width="100%" border="0" style="height: 10px;" cellspacing="0" cellpadding="0">
        <tr class="menu_bg_sd_mid">
            <td class="menu_left_sd_mid" width="2%">
                &nbsp;
            </td>
            <td width="95%" class="content_styleEdit" style="line-height: 10px !important;" align="right">
                <asp:ImageButton ID="ImageButton1" runat="server" Height="20" Width="20" ImageUrl="/_layouts/images/VCSB/note.png" />
            </td>
            <td class="menu_right_sd_mid" width="3%">
                &nbsp;
            </td>
        </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr class="menu_bg_sd_mid">
            <td class="menu_left_sd_mid" width="2%">
                &nbsp;
            </td>
            <td width="80%" class="content_style" align="center">
                <asp:ImageButton ID="imgFileImage" runat="server" ImageUrl="" Height="180" Width="511"
                    ImageAlign="Middle" />
            </td>
            <td class="menu_right_sd_mid" width="3%">
                &nbsp;
            </td>
        </tr>
    </table>
</div>
<div class="menu_bg_sd_bot">
    <div class="menu_left_sd_bot">
    </div>
    <div class="menu_right_sd_bot">
    </div>
</div>

ASCX.CS (ascx.cs)

STEP 1: Create a VisualWebPart like DepartmentImage

STEP 2: Write a coding in DepartmentImageUserControl.ascx.cs 


STEP 3:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using Microsoft.SharePoint;
using VCSB.INTRANET.BLL;
using VCSB.INTRANET.DAL;
using System.Linq;
using Microsoft.SharePoint.Utilities;

namespace VCSB01.INTRANET.VCSBWebPart.DepartmentImage
{
    public partial class DepartmentImageUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDepImage();
            }
        }
        private void BindDepImage()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {    
                      imgFileImage.ImageUrl= GetListAttachments().ToString();
                      
            });
         
        }

        private object GetListAttachments()
        {
            string URL = null;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite spsite= SPContext.Current.Site;
                SPWeb spWeb = spsite.OpenWeb();
                SPList spList = spWeb.Lists["DepartmentImage"];
                SPListItemCollection spListItems = spList.Items;             
                foreach (SPListItem item in spListItems)
                {
                    SPAttachmentCollection collAttachments = item.Attachments;
                        foreach (var attachment in collAttachments)
                        {
                            URL = (SPEncode.HtmlEncode(item.Attachments.UrlPrefix + attachment.ToString()));
                        }
                }

            });
            if (URL != null)
            {
                return URL;
            }
            else
            {

                return URL = @"~\_Layouts\Images\VCSB\photo_not_avl.png";
            }
        }

    }
}
 

Monday, 18 June 2012

ASCX.CS (ascx.cs)

STEP 1: Create a VisualWebPart like RecentlyViewedPages

STEP 2: Write a coding in RecentlyViewedPagesUserControl.ascx.cs 


STEP 3:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;
using VCSB.INTRANET.BLL;

namespace VCSB01.INTRANET.RecentlyViewedPages
{
    public partial class RecentlyViewedPagesUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dtRecent=SiteHelper.GetRecentlyViewedPages();
                if (dtRecent != null && dtRecent.Rows.Count != 0)
                {
                    grdRecentPages.DataSource = dtRecent;
                    grdRecentPages.DataBind();
                }           
            }

        }
    }
}

ASCX(.ascx)

STEP 1: Create a VisualWebPart like RecentlyViewedPages

STEP 2: Write a coding in RecentlyViewedPagesUserControl.ascx


STEP 3:


<%@ 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="RecentlyViewedPagesUserControl.ascx.cs" Inherits="VCSB01.INTRANET.RecentlyViewedPages.RecentlyViewedPagesUserControl" %>






  <div class="menu_bg_sd">
                        <div class="menu_left_sd">
                        </div>
                        <div class="menu_right_sd">
                        </div>
                        <h4>
                            Most Recently Viewed Pages
                        </h4>
                    </div>
  <div class="menu_bg_sd_indtop">
                        <div class="menu_left_sd_indtop">
                        </div>
                        <div class="menu_right_sd_indtop">
                        </div>
                        <div class="box_inner_m">                   
                           <asp:GridView ID="grdRecentPages" GridLines="None" AutoGenerateColumns="false" runat="server">
                           <Columns>
                           <asp:TemplateField>
                           <ItemTemplate>
                           <asp:LinkButton ID="hypRecentPages" PostBackUrl='<%# Eval("Url")%>' runat="server"><%# Eval("Page")%></asp:LinkButton>            
                           </ItemTemplate>
                           </asp:TemplateField>
                           </Columns>
</asp:GridView>
                        </div>
                  
                    </div>
  <div class="menu_bg_sd_bot">
                        <div class="menu_left_sd_bot">
                        </div>
                        <div class="menu_right_sd_bot">
                        </div>
                    </div>
 

SharePoint online - Get List-item attachments and Display to div

Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...