Saturday, 28 October 2017

How to get Site details in SharePoint Online?

These days, Microsoft is obsoleting code based solution from Office 365.  And these leads us to use JavaScript Object Model / Client Side Object Model to get data and add them in to content editor / script editor webpart to display data.

In this blog we will try to get current site title, web tile and any intermediate web title using CSOM. You can go deep down if you have further requirement for these objects.

Here is the basic function to get site details:

Sample code:

var currSiteTitle; // site collection details
var currWebTitle; // get sub site details
var parentWebTitle; // get any intermediate site details

$(document).ready(function() {
 
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
            getWebTitle();
     });
});

function getWebTitle() {

        var context = new SP.ClientContext.get_current();
        var site = context.get_site();
        var web = context.get_web();
        context.load(site);
        context.load(web);
        var parentInfo = web.get_parentWeb();  
context.load(parentInfo);
        context.executeQueryAsync(function() {

                console.log(site.get_title());
                console.log(site.get_url());
                console.log(web.get_title());
                console.log(web.get_url());
                console.log("Intermediate site value: " + parentInfo.get_title());

                currSiteTitle = site.get_title();
                currWebTitle = web.get_title();
                parentWebTitle = parentInfo.get_title();
            },
            function(sender, args) {
                console.log(args.get_message());
            }
        );
     }


Original Source:
  1. https://msdn.microsoft.com/en-us/library/office/jj246780.aspx
  2. https://msdn.microsoft.com/en-us/library/office/jj246877.aspx
  3. https://sharepoint.stackexchange.com/questions/175217/get-parent-web-of-a-subsite-using-jsom-in-sharepoint-2013

Tuesday, 3 October 2017

QueryString-error-The name request does not exist in the current context

After a long time, I was working on .net project. Basically I forget all basic things and on of them was how to use Query String. So here is blog for those who face issue same as me when user querystring and get error :

The name request does not exist in the current context

Below was code I was using:

if (!String.IsNullOrWhiteSpace(Convert.ToString(Request.QueryString["Source"])))
                {
                    Context.Response.Redirect(Convert.ToString(Request.QueryString["Source"]));
                }


Solution:

Solution is very easy. First, you need to add below reference in your code:

using System.Web;

This will allow you to use "HttpContext.Current" in your code. So your final solution should look like below:

if (HttpContext.Current != null && !String.IsNullOrWhiteSpace(Convert.ToString(HttpContext.Current.Request.QueryString["Source"])))
                {
                    Context.Response.Redirect(Convert.ToString(HttpContext.Current.Request.QueryString["Source"]));
                }

Monday, 11 September 2017

Cannot Read Property 'Showmodaldialog' of undefined

While working with SharePoint / JavaScript modal pop up you might encounter error "cannot read property 'showmodaldialog' of undefined". Here is simple solution for that.

Code Sample:

function OpenDocsDialog(url1) {
    var options = {
        url: url1,
        dialogReturnValueCallback: myDialogCallback
    };
        SP.UI.ModalDialog.showModalDialog(options);  // this line gives error.
}


Solution :  We need to load "sp.js" file before calling above code. You can load "sp.js" file with below code sample:

ExecuteOrDelayUntilScriptLoaded(function () { //code }, "sp.js")

Full solutionExample :

function OpenDocsDialog(url1) {
    var options = {
        url: url1,
        dialogReturnValueCallback: myDialogCallback
    };

    ExecuteOrDelayUntilScriptLoaded(function () {
        SP.UI.ModalDialog.showModalDialog(options);
    }, "sp.js")
}

Wednesday, 12 July 2017

Activate Dynamics 365 in Office 365

Recently I have a POC task in Dynamics 365. And I spent some time as I din't know how to activate it. Follow below steps to activate dynamics 365:


  • Create Office 365 account (It must be E5 instance. E3 instance do not provide this functionality).
  • Once set up you will be able to see dynamics 365 installed.



  • But you can't start diging it out directly. There is bit configuration you need to add for activating it.
  • First click on admin icon to open admin center.



  • Now click on users.




  • In this you will see our user. select it.



  • In panel, click edit button on "Product licence".




  • Enable the Dynamics 365. Click save.



 


  • Now you will be able to see dynamics 365 in admin center. Click on it to open Dynamics365.




  • Select your required template. Click on complete set up.



  • Once setup, you will see Dynamics 365 Administration center.




Monday, 19 June 2017

0x8007000d the data is invalid when chaging a file name.

Recently I have downloaded a file which was a song. I was trying to update few property of it when I encountered below error:

0x8007000d the data is invalid



Resolution:

I googled this issus and found below blog:

https://answers.microsoft.com/en-us/windows/forum/windows_7-performance/0x8007000d-the-data-is-invalid-when-chaging-a-file/23301e0b-40c8-459d-975e-1abfc9a14758

It contains the solution. so why i need to write this blog? Because it is microsoft blog which may be not understandable to all or you need to do some extra steps your self in google to achieve it.

Below are the steps:

  • First we need to download a free software. You ca download it from below URL:
    URL: http://www.mp3tag.de/en/download.html
  • Once download, install it in your machine.
  • Open the tool. And click on file menu. and then click on change directory.
  • Select your source location.
  • It will show all files in right side pane.
  • Now as per the blog, we need to update ID3 version 2.4 to version 2.3. But when you select your file and check property pane in left side, you can see that tag property is not there.
  • Don't worry. Just click save and you will see the version is changed to 2.3.
  • Once this is done, you can update your settings in the tool as well as outside of the tool.
Hope this helps.



Thursday, 17 November 2016

3rd Level SharePoint SharePoint Navigation in Global Navigation

SharePoint 2013 only supports one level deep on drop downs. If you require the navigation to show 2nd level or 3rd level item under the 2nd level, global navigation will not allow it directly. The other approaches are you do managed navigation. But it has its own limitations listed here.

Resolution:

If you require the navigation to show 2nd level menu, you need to make a very minor tweak to the master page that the site is using.

  1. Using SharePoint Designer (SPD), open the master page being used by the site. In SPD, navigate to _catalogs/masterpage/yourmasterpage.html
  2.  In the master page file, search for SharePoint:AspMenu.
    1. You will more than likely have more than one instance of a menu control.  Look at the IDs to find the right navigation control for what you want to edit.  They are intelligently named, you will be able to sort out which one you need.   For default.master, look for ID=”TopNavigationMenu”.
  3. In the properties for the tag, find MaximumDynamicDisplayLevels=”1″.  Change the number from 1 to 2. (You need to level till you need navigation)
  4. Save the file and publish the master page (do this from SPD, Manage Content and Structure, or the Master Page Gallery).
  5. Refresh your browser.  Now when you mouse over menu, you should see another level of navigation pop up.
  6. If you have more than 2nd level of navigation, you have to first add them separately in global navigation first. Once you save your changes, edit top navigation, drag 2nd level navigation under 1st level navigation.
  7. If you have more than 2 level navigation, you won't be able to drag 3rd level navigation in 2nd level. For that you need to create your custom master page and do that process.

Limitations of Managed Navigation in SharePoint 2013

When SharePoint 2013 came out, one of the most promising features was the Managed Navigation. Configuring Managed Navigation in SharePoint 2013 is straightforward and provides great no-code solution. In this blog, I will walk through some of the major limitations and why you must avoid this solution.
 
1) For each site collection you need separate Term Set.
It is important to note that each term set can be associated with only one site collection at given time. In other words, it requires dedicated copy of term set for each site collection navigation. E.g. If you have 5 site collections, you must have 5 copies of same term set to use for 5 site collections navigation data.

If term set is already configured to use for Site Collection navigation and if you try to reuse same term set in another site collection, SharePoint will throw following warning “The selected term set is already used by another site” 

2) Managed Navigation can’t be secured or targeted to specific group.
 One of the great abilities of Structured Navigation was you can configure audience targeting or secure each menu item for specific audiences or SharePoint security groups. Unfortunately Managed Navigation can’t be secured or targeted to specific security group.

3) Manual Maintenance is still required to update global navigation menu items.
 As we discussed earlier, you must have 1 term set for each site collection. If you have more than 1 site collection, you must have more than 1 term set dedicated to each site collection. To ensure, all the site collection uses same navigation menu items, there are two options available in SharePoint 2013 for replicating term sets. Regardless of which approach you may take, it will require manual maintenance of reconfiguring term sets when you have changes in term set.

4) Managed Navigation doesn’t apply to Sub Sites automatically.
 This is another one of those mind-boggling limitations of Managed Navigation. If you have enabled Managed Navigation at the site collection and while creating sub sites, if you are planning to inherit parent navigation, Managed Navigation doesn’t apply to sub sites automatically. To resolve this peculiar issue, you must open Navigation page from sub site settings page and click “OK” for to take in effect.
   
5) Managed Navigation doesn’t provide open link in new tab.
Structural navigation provide you check box option to open link in new tab. This functionality is not provided in Managed navigation. Though you can overcome this issue with JavaScript patch, you need to put this patch in master page of each site collection to work.

6) Managed Navigation conflict with SharePoint js.
Managed navigation stops working if you explicitly load sp.core.js in your page. The sub level navigation stops populating. I don’t know the strange behavior of it as sp.core.js is SharePoint own js file. 

7) Managed Navigation displays additional home tab. 
This is not though limitation but its annoying for sure. Managed navigation displays first tab with site name additionally. You can't directly change it or hide it. The thing we need to do with it is mostly hide it with javascript and the bad thing is we need to put that in each and every masterpage.

Thursday, 4 August 2016

SharePoint Exceptions : Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Issue: 

I was trying to delete a task when I was encounter with below error:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Code Sample:

SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPWeb web = SPContext.Current.Site.AllWebs[new Guid(web guid)]) // this line throws error
                            {
                                SPList taskList = web.Lists[new Guid(list id)];
                                SPListItem _lstItem = taskList.GetItemById(Convert.ToInt32(item id));
                                if (_lstItem != null)
                                {
                                    _lstItem.Delete();
                                }
                                taskList.Update();
                            }                      
                    });

Reason:

From this site I was able to get reason for this error:
When running inside RunWithElevatedPrivileges, if use SPContext.Current.Site object directly, you will not able to get site object.

Solution:

Instead create a new SPSite object, passing in SPContext.Current.Site.Url.

Code Sample:

SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(SPContext.Current.Site.Url)) //add this line
                        {
                            using (SPWeb web = site.AllWebs[new Guid(web guid)])
                            {
                                SPList taskList = web.Lists[new Guid(list id)];
                                SPListItem _lstItem = taskList.GetItemById(Convert.ToInt32(item id));
                                if (_lstItem != null)
                                {
                                    _lstItem.Delete();
                                }
                                taskList.Update();
                            }
                        }
                    });

Reference: 
  1. http://sharepoint.stackexchange.com/questions/27462/unable-to-evaluate-expression-because-the-code-is-optimized-or-a-native-frame-is
  2. http://frazzleddad.blogspot.in/2011/03/getting-past-sharepoint-exceptions-with.html

Wednesday, 6 July 2016

IIS/SMTP - emails are stuck in mailroot/Queue

Recently I was working on sending mail using smtp server where I stuck on below error:

IIS/SMTP - emails are stuck in mailroot/Queue

Here are few solution that were tried and might help you:

  • Check password and username in SMTP server
  • Check Pop3 mail setting (require enable) in receiver/ sender mail settings. 
  • SMTP Virtual Server > Properties > Delievery > Outbound Connections. The option for Limit number of connections to was checked and the value was 20. So it was configured to never make any outbound connections, causing the emails to never leave the server. I unchecked the option and restarted the SMTP server and all was well.
  • 'Simple Mail Transfer Protocol (SMTP)' service might be stuck. Try restarting service.
  • If you are using SharePoint, check running jobs (Microsoft incoming mail). If its is stuck, run it manually.
  • Open IIS 6.0. Right click on SMTP Server Properties. Go to delivery tab on Outbound Connections, fill in TCP Port to 25( if its 587).




How to enable pop-ups in Chrome, Firefox, Safari and Internet Explorer

Here are the steps to allow pop up in Chrome, Firefox, Safari and Internet Explorer.

Internet Explorer


To turn Pop-up Blockers on or off, follow these steps:

  • Click Start, click Run, type inetcpl.cpl, and then click OK to open the Internet Properties dialog box. Alternatively, open Internet Explorer, and then click Internet Options on the Toolsmenu to open the Internet Properties dialog box.
  • Click the Privacy tab, and then do either of the following:
    • Click to select Block pop-ups to turn Pop-up Blocker on.
    • Click to clear Block pop-ups to turn Pop-up Blocker off.

Google Chrome


Manage pop-ups


Google Chrome prevents pop-ups from automatically appearing and cluttering your screen. Whenever the browser blocks pop-ups for a site, an icon appears on the top-right in the address bar. Click the icon to see the pop-ups that have been blocked or to manage pop-up settings for the site.

See pop-ups for a specific site

To see blocked pop-ups for a site, follow the steps listed below:
  • If pop-ups have been blocked, you'll see the icon in the address bar. Click the icon to see a list of the blocked pop-ups.
  • Click the link for the pop-up window that you'd like to see.
  • To always see pop-ups for the site, select "Always show pop-ups from [site]." The site will be added to the exceptions list, which you can manage in the Content Settings dialog.

To manually allow pop-ups from a site, follow the steps below:

  • Click the Chrome menu on the browser toolbar.
  • Select Settings.
  • Click Show advanced settings.
  • in the "Privacy" section, click the Content settings button.
  • In the "Pop-ups" section, click Manage exceptions.
Allow all pop-ups

You can allow all pop-ups by disabling the pop-up blocker. Follow these steps:
  • Click the Chrome menu on the browser toolbar.
  • Select Settings.
  • Click Show advanced settings.
  • in the "Privacy" section, click the Content settings button.
  • In the "Pop-ups" section, select "Allow all sites to show pop-ups." Customize permissions for specific websites by clicking Manage exceptions.


Firefox 


Pop-up blocker settings
To access the pop-up blocker settings:
  • At the top of the Firefox window, click on the Tools menu then click Options . If you don’t see Tools menu press Alt key on your key board then you will see menu bar across the top of the browser select Tools menu.
  • Select the Content panel.
In the content panel:
  • Block pop-up windows: Uncheck this to disable the pop-up blocker altogether.
  • Exceptions: List sites that you want to allow to display pop-ups. 
The dialog has the following choices:
  • Allow: Click this to add a website to the exceptions list.
  • Remove Site: Click this to remove a website from the exceptions list.
  • Remove All Sites: Click this to remove all of the websites in the exceptions list.
Note: Blocking pop-ups may not always work and may interfere with some websites

Safari


  • Open up your Safari Web browser.
  • Go to the Safari menu and choose 'Preferences' from the list of choices
  • Click on the Security heading.
  • Check the box marked 'Block pop-up windows' if you would like Safari to block all popups. Safari will then ask if you would really like to change the setting.
  • Click on the 'OK' button in order to change the setting.
  • Click on the box again, so it does not have a check mark, if you want Safari to allow popup windows.
  • Close the Preferences windows after you are done changing settings.
  • Shut down and restart Safari.