Archive

Posts Tagged ‘Sharepoint2010’

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: 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.

Setting ‘Show field’ for “Person or Group” type column using PowerShell

October 10, 2013 4 comments

Hi Friends,

While fixing one issue I needed to change the ‘Show field’ setting for “Person or Group” type of column like Modified By column, My first thought is to use ‘ShowField’ property of a column as I seen this property exist in <Field XML.

Bellow image shows the “show field” option on Edit column page.

Show_Field

I tried multiple option with ‘ShowField’ but no luck and the property was not changing, then after debugging the issue I found that we need to use column’s “LookupField” property to change the setting like following.


Add-PSSnapin Microsoft.SharePoint.PowerShell
$webURL = "<Your web url>";
$web = Get-SPWeb $webURL;
$mylistName = "<Your list name>";
$mylist = $web.Lists[$mylistName];
$mycolumn = $mylist.Fields["Modified By"];
$mycolumn.LookupField = "Title";
$mycolumn.Update();
$mylist.Update();

The other available options to set the ShowField are as following table-

Sr.No. Show Field drop down options Exact value need to pass LookupField property
1 Name Title
2 Account Name
3 Work email EMail
4 Mobile phone MobilePhone
5 SIP Address SipAddress
6 Department Department
7 Title JobTitle
8 First name FirstName
9 Last name LastName
10 Work phone WorkPhone
11 User name UserName
12 Office Office
13 ID ID
14 Modified Modified
15 Created Created
16 Name (with presence) ImnName
17 Picture Only (36×36) PictureOnly_Size_36px
18 Picture Only (48×48) PictureOnly_Size_48px
19 Picture Only (72×72) PictureOnly_Size_72px
20 Name (with picture and details) NameWithPictureAndDetails
21 Content Type ContentTypeDisp

Hope this will help someone from developer community.

SharePoint: issue with $top in ListData.svc

September 10, 2013 2 comments

Hi Friends,

While working on SharePoint REST API’s in SP 2013 I come across a scenario where I need to filter on date column, I found solution to use /_vti_bin/ListData.svc service to filter based on date column like following, we can’t use RESTful call in date filtering –

var date = new Date();

var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3";

When I tried this I was getting data in browser but not using JavaScript code which is using $.ajax call to get and read the response.

After analyzing I found that $top is the culprit in my case and found following workaround.

When we use $top we will get the result date in ‘data.d’ like following-

var resultsArray = data.d;

If you want old JS code ‘data.d.results’ to work as is with $top we need to use $inlinecount=allpages in URL call like following

var date = new Date();

var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3&$inlinecount=allpages";

Happy coding….

Easiest way to get SharePoint feature id from user interface

February 26, 2013 3 comments

Hi Friends,

After a long I got some time to write post.

While working with SharePoint many times we need to get the feature ID of custom or out of box feature.

Example if I want to activate or de-activate the feature or for other purpose.

Basically what we need  to complete this operation, we need ID of the feature to complete the activation or de-activation operation in PowerShell.

So what is the easiest way to get the feature ID.

We can use the same ManageFeatures.aspx page using which we can activate or de-activate the feature ID and developer tool of browser.

  1. Go to Manage Site Feature page
  2. Use F12 to enable developer tool of browser(either IE web developer or Firebug)
  3. Select the Activate button of the feature whose ID you wanted to know.
  4. Check immediate parent div in developer tool, it will have an id attribute which is nothing but ID of respective feature.

Image

Hope this will help you to save some of your time.

Identify the worker process (w3wp) associated with my application only

March 5, 2012 1 comment

Hi Friends,

I am here again to discuss a small problem which you may or may not faced previously, related to the worker process and SharePoint debugging.

While developing the custom SharePoint artefacts like custom web parts, event receivers, application pages etc. We need to debug to check what is going wrong with the code written by us.

What we normally do while attaching in IIS6 days was to use ‘iisapp.vbs’ file in System32 folder. But it is replaced with something other with IIS7.

Normally developers attach all the running worker process to debug the code. I said initially that you may or may not face this problem as if you are the only developer working on a server then you may not face this issue but if another developer is sharing a server with you for development and if he/she attaches all the running worker processes then you my wonder why your part of code is not working and looking like hanged stat. This may because some other developer attached all the w3wp’s running.

So what’s the solution to identify and attach to only specific worker process running for my application?

  1. Go to Run  ==> cmd ==> enter or if you are not administrator then run command prompt as administrator.
  2. Write following command
    cd Windows\System32\Inetsrv ==> enter
  3. Now run following command to get the list of worker processes associated with the app
    appcmd.exe list wp ==> enter

You will get the result as shown in bellow screen shot.

Form this you will get the worker process ID in double quotes, example WP with ID “4996” is associated with SharePoint central administration application. So you can choose that worker process with the same ID against your application in visual studio while debugging.

Happy Coding….

Visual web part error: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))

April 23, 2011 1 comment

Yesterday I was working with visual webpart , While development my visual webpart works as expected, but when i deployed the more then one instance of Visual webparts on a page, it gives me error “Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))”, while searching about this and reading on MSDN, i was wondering there is some thing wrong with my code and the related to SPSite or SPWeb object disposal.

In my web part I used followig code
I used to write the code like this

using (SPSite _site = SPContext.Current.Site)
{
  using (SPWeb _web = site.RootWeb)
  {
   // your code
  }
}

To correct this issue use code like following in my web part

SPSite currSite = SPContext.Current.Site;
SPWeb currWeb = currSite.RootWeb;
using (SPSite eSite = new SPSite(currSite.ID))
{
	using (SPWeb eWeb = eSite.OpenWeb(currWeb.ID))
	{
	   //Your code
	}
}

Happy coding…