Wednesday, April 18, 2012

Display user image or beside Welcome control in sharepoint foundation

You can find relevant document  Display user profile picture next to welcome Control here.

out come is

Tuesday, April 17, 2012

Create a custom editor for a WebPart

There are situations where you want to use your own custom WebPart editor rather than use the default WebPart editor.
In my scenario i have created Version history webaprt. Here i am binding all lists to dropdown which is having content type either Item or document

Download sample code here

Step 1: The first the thing is to create the WebPart. Then set property attributeWebBrowsable (false)” so that it does not use the default ‘WebPart’ editor. Below is the code snippet for the same font size ‘WebPart’ which has ‘WebBrowsable’ value as false.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Text;
using System.Collections.Generic;

namespace MyWebparts.CustomEditorPart
{
    [ToolboxItemAttribute(false)]
    public class CustomEditorPart : WebPart
    {
        StringBuilder str;
        Label lblDisplay;

        protected string _WebpartTitle = "Version History";
        [Personalizable(), WebBrowsable(false), Category("Webpart Properties"), WebDisplayName("Webpart Header/Title"), WebDescription("Specify the Webpart Header/Title")]

        public string WebpartTitle
        {
            set
            {
                _WebpartTitle = value;
            }
            get
            {
                return _WebpartTitle;
            }
        }


        protected string _listName;
        [Personalizable(), WebBrowsable(false), Category("Webpart Properties"), WebDisplayName("Enter List Name "), WebDescription("Specify the list name to display items history")]

        public string ListName
        {
            set
            {
                _listName = value;
            }
            get
            {
                return _listName;
            }
        }
        protected override void CreateChildControls()
        {
            str = new StringBuilder();
            lblDisplay = new Label();
            this.Controls.Add(lblDisplay);
            str.Append("
");
            str.Append("
");
            try
            {
                str.Append("
");
                str.Append("
");
                using (SPSite siteColl = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb curWeb = siteColl.RootWeb)
                    {
                        SPList docLib = curWeb.Lists.TryGetList(_listName);

                        if (docLib != null)
                        {
                            SPListItemCollection docColl = docLib.Items;
                            if (docColl.Count > 0)
                            {
                                foreach (SPListItem docItem in docColl)
                                {
                                    str.Append("
");
                                    SPListItemVersionCollection docVerColl = docItem.Versions;
                                    str.Append("
");
                                    foreach (SPListItemVersion docVer in docVerColl)
                                    {
                                        str.Append("
");
                                    }
                                    str.Append("
");
                                }
                            }
                            else
                            {
                                str.Append("
");
                            }
                        }
                        else
                        {
                            str.Append("
");
                        }
                    }
                }
                str.Append("
" + _WebpartTitle + "
  
Document/Item Name : " + docItem.Name + "
Versions
" + docVer.VersionLabel + "
  
No items found..
Please configure list name/correct list name
");
                str.Append("
");
                lblDisplay.Text = str.ToString();
            }
            catch (Exception ex)
            {
            }

        }
        protected override void OnPreRender(EventArgs e)
        {
                            //set webpart crometype to None programitically
            this.ChromeType = PartChromeType.None;
        }

        public override EditorPartCollection CreateEditorParts()
        {
            List<EditorPart> editorParts = new List<EditorPart>(1);
            EditorPart part = new CustomEditorPartEditor();
            part.ID = this.ID + "MyWebpart Editor";
            editorParts.Add(part);
            EditorPartCollection baseparts = base.CreateEditorParts();
            return new EditorPartCollection(baseparts, editorParts);
        }
    }
}


Step 2: The other thing which we need to do in the WebPart is override the ‘CreateEditorParts’ method and add our custom WebPart editor. We will be seeing in the next step how we can create the web part editor. For this example, we have created ‘CustomEditorPartEditor’.
        public override EditorPartCollection CreateEditorParts()
        {
                               //create a list collection in which we will be adding the webpart editor
            List<EditorPart> editorParts = new List<EditorPart>(1);
            EditorPart part = new CustomEditorPartEditor();
            part.ID = this.ID + "MyWebpart Editor";
            editorParts.Add(part);
                         //add the same to the collection and return it so SP Environment can understand which webpart editor needs to be used for this webpart
            EditorPartCollection baseparts = base.CreateEditorParts();
            return new EditorPartCollection(baseparts, editorParts);
        }
Step 3: In order to create your custom web part editor, the first step we need to do is inherit from the EditorPart class. Currently we have created a custom web part editor class called CustomEditorPartEditor. In this custom class, we have created text box and dropdownlist. Using textbox will get webpart title and dropdownlist used to bind list.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using Microsoft.SharePoint;
namespace MyWebparts.CustomEditorPart
{
   public class CustomEditorPartEditor:EditorPart
    {
       TextBox txtWebPartTitle;
       DropDownList drList;
       //TextBox txtListName;
       Label lblWebpartTitle;
       Label lblListName;
       protected override void CreateChildControls()
       {
           txtWebPartTitle = new TextBox();
           //txtListName = new TextBox();
           drList = new DropDownList();
           drList.ID = "drList";

           lblWebpartTitle = new Label();
           lblWebpartTitle.Text = "Webpart Tile/Hearder :";

           lblListName = new Label();
           lblListName.Text = "Select Listname :";
           SPWeb curWeb = SPContext.Current.Web;
           SPListCollection listColl = curWeb.Lists;
           foreach (SPList list in listColl)
           {
               foreach (SPContentType ctype in list.ContentTypes)
               {
                   if (ctype.Name == "Item" || ctype.Name == "Document")
                   {
                       drList.Items.Add(list.Title);
                   }
               }
             
                 
              
           }

           this.Controls.Add(lblWebpartTitle);
           this.Controls.Add(new LiteralControl("
"
));
           this.Controls.Add(txtWebPartTitle);
           this.Controls.Add(new LiteralControl("
"
));
           this.Controls.Add(lblListName);
           this.Controls.Add(new LiteralControl("
"
));
           this.Controls.Add(drList);  
       }
       public override bool ApplyChanges()
       {
           this.EnsureChildControls();
           CustomEditorPart myWebPart = (CustomEditorPart)this.WebPartToEdit;
           myWebPart.WebpartTitle = txtWebPartTitle.Text;
           myWebPart.ListName = drList.SelectedValue;
           return true;
       }
       public override void SyncChanges()
       {
           this.EnsureChildControls();
           CustomEditorPart myWebpart = (CustomEditorPart)this.WebPartToEdit;
           txtWebPartTitle.Text = myWebpart.WebpartTitle;
           drList.SelectedValue = myWebpart.ListName;
       }
     
    }
}

Step 4: Two activities take place in general, one is when we the user gives customization values which customizes the web part and the other when we need to synchronize the customization values with the web part.

The web part customization values are stored in a content database according to the user logged in. So when customization data is provided for a web part through our custom web part editor, we need to override theApplyChanges method and push the customization data to the web part object. In other words, the data is pushed from the web part editor to the content database on a per user basis.

Now comes the second aspect where we need to synch the web part data from the content database with the web part itself. For this, we need to override the syncchanges method and push the data from the web part object into the web part editor user interface.
Now if you edit your web part, you can see how the custom editor looks like.


Sunday, December 11, 2011

Enable Upload Multiple Documnets Option in FBA Site

When you implement FBA in SharePoint , you will find that some options are grayed out or some options are missing in menu. No matter you have full permissions on site and you have installed MS Office 2003 or later, Even then below mentioned options are .Missing Items can be as followed:

Upload

Upload Multiple Documents

Actions

Edit in Datasheet

Open with Windows Explorer

Connect to Outlook

Export to Spreadsheet.

Now you wonder that above mentioned options are available in Windows based authentication but not in Form Based Authentication.

Well this is the problem of “Client Integration”. When we create a site in sharepoint using windows based authentication i.e

default site,”Client Integration” is enabled by default but in case of Form Based Authentication this option disabled by default

and we have to enable this. Well no probs at all find detailed steps to resolve the issue.

In SharePoint 2010

1. Open Central Administration

2. Click on Application Management Tab

3. Under Web Applications click on Manage web applications

4. Select Web Application and then select Authentication Provider option from ribbon

5. Select Zone in which FBA is implemented

6. Under Client Integration section that is place in last, click “Yes” in “Enable Client Integration?”

7. Save and you’ve done that.

8. Refresh your site and now you will find that all options that are missed is now available.

In MOSS(SharePoint 2007)

1. Open Central Administration

2. Click on Application Management Tab

3. Under Application Security section, click on Authentication providers

4. Now select desired web application

5. Select Zone in which FBA is implements and clicked that Zone.

6. Under Client Integration section that is place in last, click “Yes” in “Enable Client Integration?”

7. Save and you’ve done that.

8. Refresh your site and now you will find that all options that are missed is now available.

Tuesday, September 27, 2011

SharePoint 2010 / MOSS Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))

This Error occurs when adding a wepart to page or changing webpart from one zone to another zone because the webpart is disposing the spsite or spweb object. If your code looks like below:

using (SPWeb web = SPContext.Current.Web)

{
//some coded here

}

Change it to the format below:

SPWeb web = SPContext.Current.Web;


// your code here

And the Exception (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION)) should be resolved.

Friday, April 1, 2011

Migrating MOSS 2007 SSP/MySites to SharePoint 2010 in a database attach scenario While moving Sharepoint 2007 Mysites and profiles to SharePoint 2010 we have faced lot of issues. first we did this by following spmike blog but we have faced accesing problems other than server(while clicking people search result link). Here i am just modifing the some of the spmike blog content only, so this credit goes to spmike only. Below are the steps.....

1. Backup your existing MySites content database(s) on your MOSS 2007 farm SQL Server

2. Back up existing SSP database on MOSS 2007 farm SQL Server

3. Move both database .BAK files to the new SQL Server

4. Restore the SSP database from .BAK as database named AllProfile_DB(in my case) on your new SQL Server

5. Restore the MySites database from .BAK as database named WSS_Content_MySites (in my case) on your new SQL Server

6. Create a new Web Application in your SharePoint 2010 Central Administration site to host your migrated MySites content (e.g. http://gss.mysites)

7. Create a root site collection in the above created Web Application at location “/” by using My Site Host Template located under the Enterprise Tab (How to create MySite )

8. Attach and upgrade the restored 2007 MySites database (i.e. WSS_Content_MySites) using the SharePoint 2010 Management Shell

Mount-SpcontentDatabase –Name WSS_Content_MySites –WebApplication http://gss.mysites

9. Turn off the following services in your SharePoint 2010 Central Administration

• site User Profile Service

• User Profile Synchronization Service

10. Delete existing User Profile Service Application(s) if they already exist [Central Administration -> Application Management -> Manage Service Applications] Make sure to check the box for delete associated data/content

11. Reset IIS

12. Create a new User Profile Service Application in Central Administration [Central Administration –> Manage Service Applications –> New] Name = User Profile Service Application Create New App Pool “User Profile Service Application” DOMAIN\farm_account Use the restored 2007 SSP database as the “Profile Database Name” (AllProfile_DB) Accept all other default database names Enter the newly created MySites SiteCollectionurl (e.g. http://gss.mysites) as the default MySites location for the new User Profile Service Application

13. Go to “Administrators” in the ribbon menu for the User Profile Service Application and verify that DOMAIN\farm_account has “Full Control” rights

14. Start the User Profile Service in Central Administration [Central Administration –> Application Management –> Manage Services on Server]

15. Start the User Profile Synchronization service in Central Administration [Central Administration –> Application Management –> Manage Services on Server] Use DOMAIN\farm_account credentials This will take a few minutes…

16. Follow progress in ULSViewer.exe if you are concerned it is failing & filter by Category=”User Profile”

17. Reset IIS

18. In service.msc on your Central Administration host server (i.e. “App Server”), verify the two ForeFront Identity Management Windows services Services are started set to startup “Automatic” Running as DOMAIN\farm_account

19. Setup Profile Import [Central Administration -> Manage Service Applications -> User Profile Service Application - click on title] Click on the link to “Add New Synchronization Connection” [see examples below]

Name = DOMAIN

Forest Name = sub.domain.local

Specify a DC = dc.sub.domain.local

Authentication = Windows Authentication

Account Name = DOMAIN\ad_sync_account

Make sure your chosen account has “Replicating Changes” rights in AD [for more details refer to this article] Click “Populate Containers” Click “Select All” “OK”

20. Run a Full Import Central Administration –> Manage Service Applications” -> “User Profile Service Application” -> “Start Profile Synchronization” -> select Full Import radio button option This will take a few minutes..

21. Setup Profile Sync schedules [Central Administration –> Monitoring –> Timer Jobs] Test the MySites site with a domain user account…success!


Might be it will help somebody.....

Sunday, April 12, 2009


A tiny cute SharePoint calendar (Part I)

Have you noticed these cute month calendars that people sometimes put on the homepage of their Website?Now, have you tried to drop a SharePoint month calendar on the home page of your SharePoint site? The result… not so cute: the calendar eats up half of the screen.
In this post I am going to show how with the help of CSS you can shrink your SharePoint calendar and make it fit in the right column of a SharePoint page. The picture shows you the expected result.
So let’s start by dropping on our right column a monthly view of the calendar and a hidden Content Editor Web Part. In the source editor of the CEWP, paste the code below:

/* Remove week blocks */
.ms-cal-weekempty {display:none;}
.ms-cal-week {display:none;}
.ms-cal-weekB {display:none;}
.ms-cal-weekB {display:none;}
/* Shrink cells */
.ms-cal-workitem2B {display:none;}
.ms-cal-noworkitem2B {display:none;}
.ms-cal-nodataBtm2 {display:none;}
.ms-cal-todayitem2B {display:none;}
.ms-cal-workitem {font-size:0px;}
.ms-cal-muworkitem {font-size:0px;}
.ms-cal-noworkitem {font-size:0px;}
.ms-cal-nodataMid {font-size:0px;}
.ms-cal-todayitem {font-size:0px;}
/* thin out header */
.ms-cal-nav {display:none;}
.ms-cal-nav-buttonsltr {display:none;}
.ms-cal-navheader {padding:0px;spacing:0px;}
.ms-calheader IMG {width:15px;}
/* Abbreviate weekdays */
.ms-cal-weekday {letter-spacing:6px; width:22px; overflow: hidden;}

What this CSS does:
· height:- Reduce the height of the calendar cells- Reduce the height of the header
· width:- Only keep the first letter of the weekday names- Simplify the header options to just keep previous and next month- Reduce the “bone” that forces the width of the header- Remove the week boxes to the left of the calendar
Note that if you click on a day, SharePoint will open a full size day view of your calendar – I have chosen to keep this as the expected behavior. If you don’t like it you can simply deactivate the JavaScript that triggers the day view.
We now have our cute calendar that tells us that today is October 6 and that October 28th is a Tuesday.
The next step is to display the list items, so that I know for example that Halloween is on October 31st. This will be the object of part II. Of course, we’ll have to accept some constraints because of the reduced size of the calendar.
Update [Feb 6, 2009]: several people asked about the bottom border. To get it, in the Web Part settings select:Appearance Chrome type border only.
Update [Jan 22, 2009]: the above stylesheet is for SharePoint 2007. For SharePoint 2003, you can try this:

.ms-calMid {height:0px;}
.ms-CalSpacer {height:0px;}
.ms-calhead {padding:0px;spacing:0px;}


Hide Edit Page in Site Actions Menu

Hide Edit Page in Site Actions Menu========================================I had a request from a client to hide the Edit Page option under the Site Actions menu for all users without Full Control permissions. I performed the following steps to remove the edit page option for user's without the managesubwebs right.
Open the master page for the site.Find the following lines of code:
" Description="<%$Resources:wss,siteactions_editpagedescription%>" ImageUrl="/_layouts/images/ActionsEditPage.gif" MenuGroupId="100" Sequence="200" ClientOnClickNavigateUrl="BLOCKED SCRIPTMSOLayout_ChangeLayoutMode(false);" />Add to the following lines to the code: PermissionsString="ManageSubwebs" PermissionMode="Any"The code should now look like: " Description="<%$Resources:wss,siteactions_editpagedescription%>" ImageUrl="/_layouts/images/ActionsEditPage.gif" MenuGroupId="100" Sequence="200" ClientOnClickNavigateUrl="BLOCKED SCRIPTMSOLayout_ChangeLayoutMode(false);" PermissionsString="ManageSubwebs" PermissionMode="Any" />Save the master page and login with an account that does not have Full Control, but is not read only either... The Site Actions drop down should now resemble: