Monday, June 16, 2014

Applying toggle type menu for Left Navigation

Introduction

I am going to share my idea about applying toggle for Left Navigation. 

Master Page Customization

We will find the Left Navigation using id sideNavBox in master page. Then, add one <span>  element to have header of toggle on above menu. For Example:

<span class="toggleMenu">Menu</span>
<div class="leftMenu">
        <div id="sideNavBox"></div> (SharePoint Left Navigation Tag)
</div>


Toggle will apply when we click the <span> tag. Paste the below jquery script at the bottom of master page.

<script type="text/javascript">
    $(document).ready(function () {

    $(".toggleMenu").click(function () {
        $(".leftMenu").slideToggle("slow");
    });
</script>

 That's all. Toggle type menu will appear on your page.

Applied screen will be like:


Friday, June 13, 2014

Enabling Quick launch menu based on Site Template ID

Introduction

I am going to share my thoughts about enable the quick launch for particular site template.

Master Page Customization

First, we needs to check the .sideNavBox class in master page. This class only enabling the quick launch (left) in all the pages. On my case i need to enable the left navigation for Community sites only. So i have disabled the .sideNavBox using style.

.sideNavBox{display:none;}

Now, we are going to enable the .sideNavBox using jquery

Java Script to enable left navigation

In SharePoint, we have a var called g_wsaSiteTemplateId to find the site template. I have take that variable to check site template and enable the sideNavBox. Here the jquery script to enable the menu.

<script type="text/javascript">
    $(document).ready(function () {
        if (g_wsaSiteTemplateId == 'COMMUNITY#0') {
            document.getElementById('sideNavBox').style.display = 'block';
        }
    });
</script>

Do this script in your master page. Then, Left navigation will come based on the site template.

Happy Coding..... !!!!!!

Thursday, June 5, 2014

SharePoint ribbon icons are disappeared

Introduction

 I am going to give a solution for  "ribbon icons are disappeared" in SharePoint Pages. 

Issue



Solution

Add below style in you css file,

.ms-cui-tabContainer img, #suiteBarButtons img, #welcomeMenuBox img {max-width:none !important;} 

This is it. Icon will appears in your page.

Monday, May 26, 2014

"object reference is not set to an instance" error on Feature Activation

Introduction

I am going to share some idea about resolving "object reference is not set to an instance" on Feature activate. On my case, I am having Feature event receiver with Some methods which is adding content to the pages. I was getting error with those method only. An "object reference is not set to an instance" has been cleared when i hidden those methods. Finally, I found the mistake where i did.

Solution

Just check the Feature scope and accessing Feature parent.

If your feature is having Site scope, 

 SPSite site = properties.Feature.Parent as SPSite

If your feature is having Web scope

 SPWeb web = properties.Feature.Parent as SPWeb;

At last, Check the AllowUnsafeUpdates before and after update.

In my case, I did the mistake in "AllowUnsafeUpdates" side. My issue has cleared once i set the UnsafeUpdates

Conclusion 

It is one of the solution to resolve the "object reference is not set to an instance" issue

Happy Coding.... !!!!

Wednesday, May 21, 2014

Connecting Two ListView Webpart Programmatically

Introduction

 I am going to share my knowledge about connecting two SharePoint webparts programmatically.

Lists

 First, we need to create a lists before going to connect them. We need to have an common field in both list to connect. We'll code the connection after creating lists.

Connection between WebParts

This is the code to connect the webparts,


private void ConnectWebpart()
        {
            var currentWeb = SPContext.Current.Web;
            var currentAllowUnsafeUpdatesValue = currentWeb.AllowUnsafeUpdates;
            
            try
            {
                currentWeb.AllowUnsafeUpdates = true;
                SPLimitedWebPartManager wpManager = SPContext.Current.Web.GetLimitedWebPartManager("PageURL", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                XsltListViewWebPart providerPart = null;
                XsltListViewWebPart consumerPart = null;


                foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpManager.WebParts)
                {
                    if (wp.Title.Equals("ProviderTitle", StringComparison.CurrentCultureIgnoreCase))
                    {

                        providerPart = wp as XsltListViewWebPart;
                        providerPart.TitleUrl = "TitleURL";
            

                    }
                    else if (wp.Title.Equals("ConsumerTitle", StringComparison.CurrentCultureIgnoreCase))
                    {
                        consumerPart = wp as XsltListViewWebPart;
                        consumerPart.TitleUrl = "TitleURL";
                       
                       
                    }

                // get connectionpoints 
                System.Web.UI.WebControls.WebParts.ProviderConnectionPointCollection providerConnections = wpManager.GetProviderConnectionPoints(providerPart);
                System.Web.UI.WebControls.WebParts.ProviderConnectionPoint pCP = null;

                if (providerConnections != null)
                {
                    pCP = providerConnections["DFWP Row Provider ID"];
                }
                // Consumer webpart
                System.Web.UI.WebControls.WebParts.ConsumerConnectionPointCollection consumerConnections = wpManager.GetConsumerConnectionPoints(consumerPart);
                System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint cCP = null;
                if (consumerConnections != null)
                {
                    cCP = consumerConnections["DFWP Filter Consumer ID"];
                }

                SPRowToParametersTransformer transformer = new SPRowToParametersTransformer();
                transformer.ProviderFieldNames = new string[] { "ProviderID" };
                transformer.ConsumerFieldNames = new string[] { "ConsumerID" };

                // connecting  Webpart
                SPWebPartConnection filterConn = wpManager.SPConnectWebParts(providerPart, pCP, consumerPart, cCP, transformer);
                if (!wpManager.SPWebPartConnections.Contains(filterConn))
                {
                    wpManager.SPWebPartConnections.Remove(filterConn);
                    wpManager.SPWebPartConnections.Add(filterConn);
                }

                
            }
            catch (Exception ex)
            {
                            }
            finally
            {
                currentWeb.AllowUnsafeUpdates = currentAllowUnsafeUpdatesValue;
            }
        }

Saturday, May 10, 2014

List View WebPart Filtering using Paramater Value

I am going to share about filtering list view webpart using querystring. We have an option to filter a list view using paramater. Here is the sample querystring for filter a list.

http://Server:Port/Sites/PageName.aspx?FilterField1=FieldName&FilterValue1=Value

The above code will work for if we have one list in the page. You need to mention the view GUID if you have more than one list. Here is the sample querystring to filter with view GUID

http://server:port/sites/Page.aspx#InplviewHashGUID=FilterField1%3DFieldName-FilterValue1%3DValue

Replace the italic text with your Values.

Happy Coding..... !!!!!!

Thursday, May 8, 2014

A field Update on drag and drop of Document Library using Event Receiver

A field Update on drag and drop of Document Library using Event Receiver


 Actually, i had a chance to update a field in document library using event receiver. I have used the synchronous method on event receiver to update an item in list. We need to write a code on ItemAdding method of event receiver. So we need to choose the "Item being added" in Event receiver type. Then do the code as below i mentioned.

 public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            if (properties.ListTitle == "Library Name")
            {
              

                    string strField = properties.List.Fields["FieldName"].InternalName;
                    properties.AfterProperties[strField] = "12346";
                    properties.Web.Update();
                   
            }
        }

That's all. Then deploy the solution and enjoy.

Happy Coding ... !!!!!