Archive

Posts Tagged ‘SharePoint’

SharePoint 2013: Newly created rendition not working

Recently I was facing an issue with newly created rendition, I created new rendition but the images are not showing the newly created rendition on my development server, also in image picker we not able to see the newly created rendition.

After waiting for some time as well my newly created rendition not worked. After some investigation we figured out that as renditions was previously working fine means blob cache working as expected but after adding new rendition we found that it was not working.

Solution:

We need to flush the blob cache using PowerShell.

$webApplication = Get-SPWebApplication "http://mytestdomain.com";
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApplication);

After flushing the blob cache we are now able to see newly added rendition. For more details please check https://technet.microsoft.com/en-us/library/gg277249.aspx

Flush action will not be immediate, it will be queued.

Hope this will help, happy learning.

SharePoint 2013: Identifying the variation source and target with PowerShell

While working with one reporting requirement I needed to eliminate the variation targets and only need to consider variation sources. I struggled to find out the property which will help me to identify the page is variation source or target.

Solution:

Publishing web and Publishing page have the property called as ‘PublishingPage.Label.IsSource’ which we can use to identify the source page and source web. The same way we can use the publishing web level property as well.

if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($childWeb)){
 $spPubWeb =
 [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($childWeb);

 $item = $spPubWeb.PagesList.GetItemById($row.ID);
 $pubPage =
 [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item);

 if($pubPage.VariationPageUrls.Count -eq 0)
 {
     #Page directly created in language sites and not Variated from source
 }
 else #Page Variated
 {
   if($pubPage.Label.IsSource) # then check if the web is Label IsSource
   {
     #this page is variation source
   }
 }
}

Hope this will help, happy learning.

SharePoint: Access denied error while calling web service from JavaScript

March 6, 2017 2 comments

Hi Friends,

I would like to share one very specific while calling web service from JavaScript, we were getting exception. Important point to note here is the code is working very fine if we access the page on server. But we are getting JavaScript ‘Error: Access is denied.’ Error while accessing the web page from client machine through browser.

error1

We are getting exception where we are calling the web service.

After some analysis the error came out as HTTP and HTTPS mixed content issue.

In our case HTTPS is configured on load balancer level and on ISS 7 level we have HTTP only hence web service call is working fine.

While accessing from outside URL is getting accessed only with HTTPS and non-secured request is also redirected with secured.

Problem fund that we have used ‘_spPageContextInfo.webAbsoluteUrl’ variable which is providing the HTTP path as SharePoint is unaware with existence of HTTPS as it is configured on load balancer level.

‘_spPageContextInfo.webAbsoluteUrl’ is supposed to give HTTPS path if HTTPS configured on ISS 7 level but as in our case SSL is configured on load balancer hence SharePoint is unaware about SSL.

Solution:

We have checked the protocol of the browser request using ‘document.location.protocol’ and if it is HTTPS then we replaced HTTP with HTTPS from the output of ‘_spPageContextInfo.webAbsoluteUrl’

change

This solution is working fine both in the case of HTTPS and HTTP.

Though this scenario is very specific but still this may help someone to understand the issue better.

SharePoint 2013: Modal Dialog position and scrolling issue with lengthy page

We have come across an issue with SharePoint modal dialog, while working with a lengthy page where due to some lengthy content vertical scroll bar were coming. We developed one web part form, which we have added at the center of the vertical screen. From that web part we can open a SharePoint Asset picker to select the image which opens a model dialog. The functionality was working as expected but we found an UI level issues.

Problem: When we try to launch SharePoint ‘Modal Dialog’ from the bottom of the huge scrolled page, we are not able to see the dialog and only see the bluer screen (overlay). The actual model dialog is getting opened at the top of the page and because of the current scroll position which is somewhere in between the screen or at the bottom, we are not able to see the popup.

Solution: The model dialog location is set by CSS class on the top of the screen, we need to override the css class to change the property. The name of the class is ms-dlgContent. We can add following css class in either master page or respective CSS.

.ms-dlgContent
{
position:fixed! important;
}

SharePoint 2013: Designer workflow error with ‘Call HTTP web service’ action

February 17, 2015 4 comments

While working on one of the workflow development task, it was required to have a web service call to fetch data from SharePoint. To achieve that I used ‘Call HTTP web service’ action but with that I was getting following exception “Unable to deserialize HTTP response content. Expected Content Type: ‘application/json’, ‘text/plain’ or ‘text/html’”.

Suspended

After struggling with this issue, the solution I used thought to share the solution with developer community.

Solution: The reason for the issue is, by default response from SharePoint REST is in XML and SharePoint designer workflow not able to parse the xml and needs JSON response. To resolve this issue we need to pass Accept and Content-Type as application/json;odata=verbose to request headers. This way we will get JSON response. To resolve this follow bellow steps.

  1. Go to SharePoint 2013 designer.
  2. Build a Dictionary variable named ‘WSHearder’WF1
  3. Add two values in newly created dictionary
Accept = application/json;odata=verbose
Content-Type = application/json;odata=verbose
WF2
  1. Now select ‘Call HTTP web service’ action and select Properties.              WF3
  2. Select newly created dictionary variable as value for ‘RequestHeaders’.WF4
  3. Press OK and publish the workflow.

SharePoint 2013: Querying SharePoint log files

December 31, 2014 Leave a comment

Hi Friends,

While working as a SharePoint developer every one of us need to go to SharePoint log files to check exact nature and cause of error. SharePoint logs provide us vital information to resolve the issue. SharePoint provides us correlation id to get the details about the issue, but it is difficult some times to go and check the log files and manually find the error in log and get the cause, as log files are huge sometimes.

To resolve this we have some PowerShell cmdlets which we can use to search in log files. Some of them are Get-SPLogEvent and Merge-SPLogFile. We can discuss about them in more detail below.

1. Get-SPLogEvent-

We can use Get-SPLogEvent to query log files when either single server farm in place or we have knowledge on which server the error gets logged.So Get-SPLogEvent will query the logs in the same server where PowerShell command gets executed.Some of the samples below –

get-splogevent | ?{$_.Message -like "*Monitored*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log1.log

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the requested fields (Area, Category, Level, EventID, Message) in file Log1.log

get-splogevent | ?{$_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log2.log

Above command will search with specified correlation id and dump the requested fields (Area, Category, Level, EventID, Message) in file Log2.log at specified path

You can use the above commands directly also on powershell to get the details directly instead of creating a file out of it, like

get-splogevent | ?{$_.Message -like "*user*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0" -and $_.Level -eq "Medium" -and $_.Category -eq "App Deployment"} | select Area, Category, Level, EventID, Message

Above command will search with specified correlation id and get the content where message contains ‘user’ word , Level is ‘Medium’ and Category equals ‘App Deployment’ and display the requested fields (Area, Category, Level, EventID, Message) on PowerShell window.

get-splogevent -StartTime "12/11/2014 10:00" -EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and display on PowerShell window.

2. Merge-SPLogFile-

We can use Merge-SPLogFile to query log files when we have a scenario where mult-server farm in place and we do not have idea where exactly the error get logged. i.e. timer service is running on four servers and the current timer request is served by Server1 then error get logged on server1. Some of the samples below –

Merge-SPLogFile -Path "C:\Log1.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the details in file Log1.log

Merge-SPLogFile -Path "C:\Log2.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and dump the details in file Log2.log

Merge-SPLogFile -Path "C:\Log3.log" -Overwrite -StartTime "12/11/2014 10:00" - EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and dump the details in file Log3.log.
Hope this will reduce some of the debugging efforts.

“As the year comes to an end, don’t look back at yesterday’s disappointment. Look ahead to God’s promises yet to unfold.” ― Buky Ojelabi, comtemporary blogger
Happy new year 2015.

SharePoint: Using Papercut for testing the email functionality in SharePoint.

October 31, 2014 Leave a comment

In many scenarios while working with SharePoint we may come across requirement to test emails. Like email alerts, emails from workflow, timer jobs or event receivers etc. In my case I need to test emails from Timer job.
While development phase it is not always possible to have a SMTP sever available to test those kind of functionality and in those scenarios Papercut is best utility available for our help. Papercut is a simplified SMTP server designed to only receive messages and serve the purpose of light weight SMTP.
You can use Papercut in .Net development or SharePoint development. You just need to download and install the Papercut on your SharePoint server.

Papercut-v3.1.0-S1
Some points to consider while using Papercut with SharePoint-
1. Papercut is only to receive emails.
2. In case of ASP.Net application provide host=”127.0.0.1″ port=”25″ in web.config file under mailsettings section.
3. For SharePoint, If you have single server farm then you don’t need to worry just install Papercut and set the ‘Outbound SMTP Server’ to localhost or 127.0.0.1 in ‘Configure outgoing e-mail settings’ under central admin, System settings.
4. You can now test by creating simple alert on any list.
5. If you have muti-server farm and testing email from timer job then need to find on which server timer service is running and on that sever you need to install Papercut also give this server IP in ‘Outbound SMTP Server’ in ‘Configure outgoing e-mail settings’ under central admin, System settings.
6. If timer service running on more than one server then make sure port 25 open between those servers to get emails from timer job.
Hope this will help.

Note: complete contribution, development and license rights are with the team who have developed this and as per the http://papercut.codeplex.com/license . This post is just to make readers aware that this kind of tool exists.