About Me

My photo
Muthupet, TamilNadu, India
SharePoint 2010

Wednesday, November 28, 2012

HyberLink using Sharepoint Grid




using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace Saravanan_Testsolutions.Gridsamples
{
    public partial class GridsamplesUserControl : UserControl
    {
        public SPList olist { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            databind();
        }
        public void databind()
        {
            try
            {
                using(SPSite osite= new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb oweb = osite.OpenWeb(SPContext.Current.Web.Name))
                    {
                        olist = oweb.Lists.TryGetList("Tasks");
                        SPListItemCollection oitemcoll = olist.Items;
                        if (oitemcoll.Count > 0)
                        {
                            grdshow.DataSource = oitemcoll.GetDataTable();
                            grdshow.DataBind();
                        }
                    }
                }
            }
            catch (Exception)
            {
               
                throw;
            }
        }
        protected void grdshow_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink lnk = new HyperLink();
                lnk.Text = e.Row.Cells[0].Text;
                lnk.NavigateUrl =olist.DefaultViewUrl;
                e.Row.Cells[0].Controls.Add((Control)lnk);
            }
        }
    }
}

Friday, November 23, 2012

Available Field Types in SharePoint 2010




Out of the box Field Types




NameUse
AllDayEvent
Attachments
Boolean
BusinessData
Calculated
Choice
Computed
ContentTypeId
Counter
CrossProjectLink
Currency
DateTime
Decimal
File
GridChoice
Guid
Integer
Lookup
LookupMulti
ModStat
MultiChoice
MultiColumn
Note
Number
PageSeperator
Recurrence
Text
ThreadIndex
Threading
Url
User
UserMulti
WorkflowEventType
WorkflowStatus

GROUPBOARD Field Types




NameUse
CallTo
Confirmation
ContactInfo
Facilities
FreeBusy
Overbook
SendTo
WhereAbout

GROUPBOARD Upgrade Field Types (do not use)




NameUse
GbwLocation
GbwParticipants
GbwSREnd
GbwSRStart

Hold Field Types




NameUse
HoldsField
ExemptField

Publishing Field Types




NameUse
HTML
Image
Link
SummaryLinks
LayoutVariationsField
ContentTypeIdFieldType
PublishingScheduleStartDateFieldType
PublishingScheduleEndDateFieldType
MediaFieldType

SPRating Field Types




NameUse
AverageRating
RatingCount

TargetTo Field Types




NameUse
TargetTo

Taxonomy Field Types




NameUse
TaxonomyFieldType
TaxonomyFieldTypeMulti

Thursday, November 8, 2012

How to implement insert/update/delete in GridView for List with Lookup and Choice columns?




<asp:GridView ID="GridView1" runat="server" EnableTheming="False" OnRowCreated="GridView1_RowCreated">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
</asp:GridView>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
  {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataTable dt = new DataTable("nameList");
                dt.Columns.Add("name");
                SPSite site = new SPSite("http://jack-7716f30e37:80");
                using (SPWeb Web = site.OpenWeb())
                {
                    SPList mylist = Web.Lists["MyList"];
                    SPQuery query = new SPQuery();
                    SPListItemCollection items = mylist.GetItems(query);
                    foreach (SPListItem item in items)
                    {
                        DataRow row = dt.NewRow();
                        row["name"] = item["Title"];
                        dt.Rows.Add(row);
                    }
                }

                ((DropDownList)e.Row.FindControl("DropDownList1")).DataSource = dt;
                ((DropDownList)e.Row.FindControl("DropDownList1")).DataTextField = "name";
                ((DropDownList)e.Row.FindControl("DropDownList1")).DataBind();
            }
}

Tuesday, November 6, 2012

SharePoint 2010 TreeView Example

Collect All Site and Sub Site with content

Using <SharePoint:SPTreeView>


<div class="ms-quicklaunchouter" runat="server">
    <div class="ms-treeviewouter">
        <SharePoint:SPRememberScroll runat="server"
            id="RememberScroll1"
            onscroll="javascript:_spRecordScrollPositions(this);"
            style="width: 220px;">
            <Sharepoint:SPTreeView runat="server"
                id="TreeView1"
                ShowLines="false"
                DataSourceId="TreeViewDataSource1"
                ExpandDepth="0"
                SelectedNodeStyle-CssClass="ms-tvselected"
                NodeStyle-CssClass="ms-navitem"
                NodeStyle-HorizontalPadding="2"
                SkipLinkText=""
                NodeIndent="8"
                ExpandImageUrl="/_layouts/images/tvclosed.png"
                ExpandImageUrlRtl="/_layouts/images/tvclosedrtl.png"
                CollapseImageUrl="/_layouts/images/tvopen.png"
                CollapseImageUrlRtl="/_layouts/images/tvopenrtl.png"
                NoExpandImageUrl="/_layouts/images/tvblank.gif"
                NodeWrap="True">
            </Sharepoint:SPTreeView>
        </Sharepoint:SPRememberScroll>
    </div>
</div>
<SharePoint:SPHierarchyDataSourceControl runat="server"
    id="TreeViewDataSource1"
    RootContextObject="Web"
    ShowFolderChildren="true"
    IncludeDiscussionFolders="false"/>

Custom Action Ribbon with Popup Window


 Custom Action Ribbon With Popup Window


 <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="SiteActionsToolbar"
       GroupId="PersonalActions"
       Location="Microsoft.SharePoint.StandardMenu"
       Sequence="1050"
               
       Title="Change Password"
       Description="Change the Password"
       ImageUrl="/_layouts/IMAGES/picture.jpg">
    <UrlAction Url="javascript:OpenPopUpPageWithTitle('{SiteUrl}/_layouts/CustomActionRibbon/Forget Password.aspx', RefreshOnDialogClose, 600, 300,'Change Password')"/>
  </CustomAction>
</Elements>

 

Custom Action Ribbon





<CustomAction
  
    Id="SkynetCustomRibbonButton"
    RegistrationId="101"
    RegistrationType="List"
    Location="CommandUI.Ribbon"
    Sequence="5"
    Title="Move Documents">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
          <Button
              Id="Ribbon.Documents.New.SkynetTestButton"
              Alt="Move Documents"
              Sequence="5"
              Command="Skynet_Test_Button"
              Image32by32="http://igrid108:44/SiteAssets/searchserver.ico"
              Image16by16="http://igrid108:44/SiteAssets/searchserver.ico"
              LabelText="Move Documents"
              TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="Skynet_Test_Button"
          CommandAction="javascript:alert('SharePoint 2010 Rocks!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
--------------------------------------------------------

 <CustomAction
        Id="Comments.Link"
        RegistrationType="List"
        RegistrationId="101"
        Location="EditControlBlock"
        Sequence="350"
        Title="Comments"
        ImageUrl="~/_layouts/1033/IMAGES/CommentsIcon.png"
       Description="Can add comments">
    <UrlAction Url="/_layouts/TR_DMS_DiscussionBoard/TR_DiscussionBoard.aspx?List={ListId}&amp;ID={ItemId}&amp;"/>
  </CustomAction>
----------------------------------------------------------

Thursday, November 1, 2012

Programmatically download documents from document library Sharepoint

Programmatically download documents from document library Sharepoint
Lets look the code to download documents from a Document Library

SPList currentLib = web.Lists["LibraryName"];

Get all items from the document library

foreach (SPListItem item in items)
{

byte[] binfile = item.File.OpenBinary();

FileStream fstream = new FileStream("C:\\" + item.File.Name,
FileMode.Create, FileAccess.ReadWrite);

fstream.Write(binfile, 0, binfile.Length);

fstream.Close();
}