Thursday, May 15, 2014

Modal Popup- close sharepoint page and sharepoint popup page in code behind

Below is the code to close a SharePoint popup window on button click or any event from code behind

// Close if dialog

HttpContext context = HttpContext.Current;

if (HttpContext.Current.Request.QueryString["IsDlg"] != null)



{
 
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");




}
 
else

SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.UseSource, HttpContext.Current);




Source attribute is a Query string which holds the url of the source page from where the page is usually called .This is default behavior of SharePoint. We can use this to navigate when the popup is closed and redirect to same source page as shown above

Eg: http://webpalication:1111?Source=http:wwww.google.com


 

Friday, May 9, 2014

Add Sharepoint Navigation links with audience targeting through powershell

Below is the powershell command to add Navigation links in SharePoint.This was tested in SharePoint 2013 environment.This script will check if the link is present in the site if not it will add the links along with audience targeting



$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }

if ($snapin -eq $null) {

Write-Host "[INIT] Loading SharePoint Powershell Snapin"

Add-PSSnapin "Microsoft.SharePoint.Powershell"


}

 
 
$Web = Get-SPWeb http://testWebapplication:7777

$TopNav = $Web.Navigation.TopNavigationBar

Write-Host -ForegroundColor Green "Creating Navigation links ......................."



$Heading = $TopNav | where { $_.Title -eq "Link1" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Link1", "/Lists/CreateNewPublication/DocProjects.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()





}

 
 
$Heading = $TopNav | where { $_.Title -eq "Search" }

if($Heading -eq $null)


{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Search", "/SitePages/Search.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
$Heading = $TopNav | where { $_.Title -eq "Google" }

if($Heading -eq $null)


{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Google", http://www.google.com);

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
$Heading = $TopNav | where { $_.Title -eq "Yahoo" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Yahoo", http://yahoo.co.in);

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Heading.Properties["Audience"] = ";;;;" + "IK,IL,R,C"

$Heading.update()

$Web.Update()





}
 
$Heading = $TopNav | where { $_.Title -eq "Reports" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Reports", "/SitePages/Reports.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Heading.Properties["Audience"] = ";;;;" + "PM,TL,IL,C"

$Heading.update()

$Web.Update() 



}
 
  $Heading = $TopNav | where { $_.Title -eq " Help" }

if($Heading -eq $null)

{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @(" Help", "/Lists/HelpLibrary ");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
Write-Host -ForegroundColor Green "Navigation link creation completed"

Pause

Friday, March 21, 2014

Visual Studio 2012 error + An exception has encountered .This may be caused by an extension



This  error came up in our server ,by which I was not able to open the ascx or aspx files in visual studio 2012.This error caused the intellisense to not work in design pages, also the Tools box was not showing up with any controls only the HTML controls was available.

Analysing the Log I found that there was the below exception


System.NullReferenceException:Object referencenot set to instance of an object.at Microsoft.VisualStudio.Web.Exports.HTMLClassifierProvider.Microsoft.VisualStudio.Text.Classification.
IClassificationProvider.GetClassifier(ITextBuffer textBuffer) at Microsoft.VisualStudio.Text.Classification.Implemention.ClassifierTaggerProvider

Logs can be found at  "C:\User\UserName\AppData\Roaming\Microsoft\VisualStudio\11.0\ActivityLog.xml"

You can try below steps to resolve this issue

  1. Open visual studio click Tools  then Import and Export setting  reset all.This will reset all your custom changes
  2. Choose Tool -->Tools Box item run it once
  3. Tools-->Extension and updates-->If you have installed any vulnarebale packages uninstall them
  4. Run the Visual Studio Repair
  5. Uninstall and Install the VS 2012 again
  6. In my case none of the above worked
So what I did was to give a try to reinstall the .netFrameWork 4.5 .This did the magic for me.
I guess some of the system update corrupted the framework hence the issue was caused.VS2012 installer also installs the framework but since it was already installed, it dint try to install again I believe. Downloading a new package of .net FrameWork 4.5 and installing it solved my issue with Visual Studio 2012

 

Wednesday, February 19, 2014

Workflow Manager 1.0 for Sharepoint 2013 - forbidden error (error 403)

This Workflow forbidden error (error 403) came up from no where. I had this SharePoint farm configured with the workflow farm which was running fine for about 2 months, but from no where the error popped up.

This may occur when you try to activate the workflow feature which you deployed through Visual Studio 2012 or when you try to start a designer WF you may get "Something went wrong". You check the log then it says "Workflow Manager forbidden error :403"

Below are the few steps you can follow to solve this error

1) Go to central Admin click on "Workflow Service Application" and check in properties you find on ribbon if you have assigned the Administrator .If not provide the service account as Administrator

2)It is always good to have the Administrator  assigned to "User Profile Service Application "
in the same way

3)Try opening the url in IE http://localhost:12291 for http based web service where the Workflow Manager is installed
               It might give you the forbidden error again
4)Open the IE as Admin and try opening the same url http://localhost:12291 if u dont get the XML schema then there is problem with the credentials the services are running
      You don't get the run as Admin option for IE if your server OS is windows server 2012
to open IE with run as Admin privileges you need to navigate to folder where the IE is installed
C:\Program Files\Internet Explorer then open iexplorer.exe  as Admin

5)Go to the data base and check for service bus databases , if the service account with which the services are running has the required privileges
6) Open event viewer and check for the error and I found that the service bus message broker service was not in running state from this.

7)Last but not least this the reason where you may get forbidden error for workflow service most of the time

  • Go to services and check if the below service are running

  1. Service Bus Gateway
  2. Service Bus Message broker service
  3. Windows Fabric host service

I had this situation of  Service Bus Message broker service in  Starting state

you can stop the Windows Fabric host service and restart again. This should trigger the service bus services to start again. If not check the service account and password with which the services are running.

Open the Workflow Management Shell  and Get-SbFarm , Get-SbFarmStatus you should be able to see all the services are running in it ..If not it is a problem.


In my case the above happened and all I wanted is to start these service !! so I performed below items


  • I planned to re configure the Service Bus farm unlike SharePoint you don't have the option to run the config wizard again
  • So I opened Service Bus Configuration wizard  and chose the option to Leave Farm
  • Went to services and saw neither service bus gateway nor Service Bus Message broker service was present
  • Next step was to open the Service Bus Configuration wizard  again and instead of creating new farm I chose  "Join the old Farm " option and gave the server and db name as old config since I had this SbManagementDB and SBMessageContainerDB were already present with data


This created Service bus gateway and Service Bus Message broker newly and in running state !!


Problem solved :)











 

Wednesday, January 22, 2014

MSOCAF error- Remove inline code present in the aspx pages


Remove inline code present in the aspx pages. Inline code is not recommended within a site definition due to the issues involved with the code no longer rendering as soon as the page is customized. Inline code is supportable if included on a page in the _layouts directory. Inline code should not be allowed through the PageParserPath exclusion, except in extremely rare circumstances, because it can be modified without going through any review process. As a result, it represents a danger to the environment’s performance and security. Adding PageParserPath element to the web.config files is not allowed. Modifying these files may ‘break’ SharePoint in some way if you change the wrong part of the file
 
 
Found this error while running the MSOCAF on my project having aspx file been deployed to Layouts folder.
 
This error is mainly due to using the <script> tag in your ascx file as below to refere your "js" files in different location like site assests,layouts or any other location
 
 
<script src="myscripts.js"></script>
 
This tag throws the above error
 
This can be resolved by using the tags as mentioned below
 
<SharePoint:ScriptLink ID="ScriptLink1" Name="~sitecollection/siteassests/myscripts.js" runat="server" />