Jun 6, 2012

HTML Editor/ Rich Text Editor Style Customization in SharePoint Ribbon

Hi All,

In this post I am explaining you how to customize the default markup styles in HTML Rich Text Editor of SharePoint 2010 Ribbon. We can change or remove the existing styles and as well as we can add a new custom style . By default we will get these styles from the Mark up Styles Button in the Rich Text Editor pane (Ribbon) as shown below.



Here I am removing the default style i.e Heding2 Style.For this go to the style sheet which you are using for the site (by default COREV4.CSS)

This will be located under the path

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\Themable

Open COREV4.css and find the class ms-rteElement-H2 and remove it

H2.ms-rteElement-H2

{
-ms-name:"Heading 2";
}
.ms-rteElement-H2
{
font-size:1.3em;
font-weight:normal;
}

Now save it and check the site, the Heading 2 is removed



In the similar way If we want to add a new style (our custom style)
H4.ms-rteElement-H4mystyle
{
-ms-name:"MY CUSTOM STYLE";
}
.ms-rteElement-H4mystyle
{
font-size:15px;
font-weight:bold;
color: red;
}

Here I added a style with the properties like font-size of 15px ,font-weight bold and forecolor red. I added this class under CallOut 4 class. So that will be appear under callout4 style as shown with the specified styles like this





Apr 10, 2012

Downloading Wsp from SharePoint Central Admin


Recently I got a requirement to check the contents of a wsp which was already deployed on the Client's SharePoint server.  I have given access to Central Admin, but as you know SharePoint will not provide us any link to download/extract the deployed wsp. 

These are the ways I found on the web to download/extract the wsp..

  • Using Power Shell Script
  •  Using Code

1. Using PowerShell script :




$myFarm = Get-SPFarm
$myWSP = $myFarm.Solutions.Item("documentspacenew.wsp").SolutionFile
$ myWSP.SaveAs("c:\purna\ documentspacenew.wsp")

 

This will be saved as 



 
2.  Using Code :

  protected void btnGetWSP_Click(object sender, EventArgs e)
        {
            SPSolutionCollection allSolutions = SPFarm.Local.Solutions;
            foreach (SPSolution mySolution in allSolutions)
            {
                SPPersistedFile myWSP = mySolution.SolutionFile;
                if (myWSP.Name == "documentspacenew.wsp")
                {
                    myWSP.SaveAs("c:\\Purna\\" + mySolution.Name);
                }
            }
        }

Here the SPSolutionCollection , SPPersistedFile classes are referred from   Microsoft.SharePoint.Administration namespace.

Finally I have got the contents of the downloaded solution by changing the extension from .wsp to .cab.
 

Hope Helpful..!

Apr 9, 2012

Adding Webpart to the Page Programatically in SharePoint

Hi All,

Here I am explaining you how to add a web part to the page programatically.  For this demo I have created a web part page called Demo.aspx  and I am adding a content editor web part to this page through programatically. 

For this first we need to get the reference of the SPLimitedWebPartManager  of the page where we are going to add the webpart.

Here is the code
protected void Addwebpart_Click(object sender, EventArgs e)
        {           
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    //getting reference of SPLimitedWebpartManager of the page
                    SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager("http://sp2010:9999/SitePages/Demo.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);                   
                    //Creation of ContentEdiotr Webpart
                    ContentEditorWebPart myCEWP = new ContentEditorWebPart();
                    myCEWP.ID = "myCEWP";
                    myCEWP.Title = "Demo Content Editor";
                    //Adding Webpart to the page
                    wpManager.AddWebPart(myCEWP, "Main", 1);
                    wpManager.SaveChanges(myCEWP);
                }
            }

        }

If you want to add the Shared Documents (ListView webpart) to the page,  Here is the way..

                    web.AllowUnsafeUpdates = true;
                    SPList lstCDD = web.Lists.TryGetList("Shared Documents");
                    if (lstCDD != null)
                    {
                        SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager("http://sp2010:9999/SitePages/Demo.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

                        XsltListViewWebPart webpartCDD = new XsltListViewWebPart();
                        webpartCDD.ListName = lstCDD.ID.ToString("B").ToUpper();
                        webpartCDD.ViewGuid = lstCDD.DefaultView.ID.ToString("B").ToUpper();
                        wpManager.AddWebPart(webpartCDD, "Main", 2);
                        wpManager.SaveChanges(webpartCDD);

                    }

Here the AddWebpart method expects three parameters, webpart, zoneid(string-Id of the webpartzone where the webpart is being added to like Main, Left etc), zone index(Int-Index of the zone like 1,2,3..)

Cheers,

Jan 20, 2012

Attaching specific W3WP Worker Process in SharePoint Custom Code Debugging


Hi Guys,

This is a small post but very useful  in the sharepoint  custom application development.

While debugging your custom code in the SharePoint instead of attaching all worker processes(w3wp.exe) this is the command to attach/identify only the current application specific w3wp process

Command to get the correct w3wp process

C:\wondows\System32\inetsrv\appcmd list wp




 
Here I have written my custom code on Sharepoint-1122 site and debugging the same. So the processor which attached to this application  is 4736(see above fig).

So attach only one process which is associated (like below) instead all




Have a happy debugging..!

Dec 30, 2011

SharePoint 2010 Modal Dialog


Hi Guys,

This is a small post regarding the Sharepoint Modal Dialog. In this post I am going to expalin you how to call a Sharepoint Modal Dialog from the applications. For this demo I have taken the Sharepoint Project template in visual studio and added an application page to my project. And then I placed a hyper link on this page to call the modal dialog.

The class SP.UI.ModalDialog represents the modal dialog and the method showModalDialog displays the modal dialog with the dialog options which we provide. 

Here is the code (written in C# .cs file) to show the modal dialog by registering a script which calls the modal dialog

 string myScript = @"   var mymodalDialog; 
                                 function ShowDialogTest(myViewUrl) { 
                                    var options = { 
                                        url: myViewUrl, 
                                        tite: 'Demo Page', 
                                        allowMaximize: true, 
                                        showClose: true, 
                                        width: 600, 
                                        height: 400 }; 
                                       mymodalDialog = SP.UI.ModalDialog.showModalDialog(options); 
                                }";
            ScriptManager.RegisterStartupScript(this, this.GetType(), ClientID, myScript, true);
            string strUrl = "http://moresharepoints.blogspot.com";
            hLinkshow.NavigateUrl = "javascript:ShowDialogTest('" + strUrl + "')";


This is the output on click of hyperlink

You can find more on this from msdn.



Dec 1, 2011

Enabling Inline Editing for Share Point lists

You can edit the data of sharepoint lists in line mode. But this is specific to the view of the sharepoint list. Here is the way how to enable the inline editing for the list

This is my announcements list.


Click on List Tab in the Ribbon-->Select Modify View Button




Go to Inline Editing Category (below of Filter Category)




Check Allow the Inline Editing option. Go to your list back you will find this feature like this

On mouse Over of your list item you will find the edit icon, Click On and do the changes


The same way you can add the items inline.

Note : This feature is specific to your view(Here All Items). You can set this using code too.


Nov 1, 2011

SPLongOperation Class in SharePoint

 Hi All,

Recently  I worked with this class in one of my projects to show the user with useful message when a long operation/activity is taking place in the background..I thought to share with you...

Here is the sample to use this..a webpart with a button. On click of button I am calling this..

protected void btnLoad_Click(object sender, EventArgs e)
{
  using (SPLongOperation myOperation = new SPLongOperation(this.Page))
  {
    //main bold text when action is in progress
    myOperation.LeadingHTML = "Hey..! Connection established to the database server"; 
    //small text when action is in progress
    myOperation.TrailingHTML = "Please wait during the data fetch"; 
    //start the operation
    myOperation.Begin();             
    //our long running action here
    System.Threading.Thread.Sleep(120000);//2 mins 
   //end of the operation and it redirects to home page after end of the operation
    myOperation.End("/sitepages/home.aspx");             
           
  }
}

Here is the result of this..




Happy Reading..!