Archive

Archive for the ‘Microsoft SharePoint 2010’ Category

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

Programmatically get the server roles in SharePoint farm

Hi Friends,

While working with Microsoft SharePoint farm we may need to get different server roles it is playing in farm.

Like Application server, Database server, Web Front End server etc.

Following code will show you how we can get the server role using SharePoint object model-

For an example I have created a console application and added reference of ‘Microsoft.SharePoint.dll’ and using

‘Microsoft.SharePoint.Administration’

SPFarm spFarm = SPFarm.Local;
SPServerCollection allServers = spFarm.Servers;
if (allServers != null && allServers.Count > 0)
{
   foreach (SPServer eachServer in allServers)
   {
      switch (eachServer.Role)
      {
	case SPServerRole.WebFrontEnd: Console.WriteLine("WFE:: "+eachServer.Address); break;
	case SPServerRole.Application: Console.WriteLine("APP:: " + eachServer.Address); break;
	case SPServerRole.SingleServer: Console.WriteLine("Single:: " + eachServer.Address); break;
	case SPServerRole.Invalid: Console.WriteLine("Invalid:: " + eachServer.Address); break;
      }
   }
}

Happy coding…

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

Get all picture libraries in a web

February 14, 2012 Leave a comment

Hi Friends,

While working in MOSS2007 or in SharePoint 2010 we may come across a situation where we need to get all the picture libraries, all task lists or all KPI list and so on.

This is required in many scenarios like in tool part we want a picture library to be displayed in drop down to be given for selection of one picture library.

In following code I am showing two ways using which you can get all picture libraries from a web.

 using (SPSite site = new SPSite(""))
 {
  using (SPWeb web = site.OpenWeb())
  {
     //we will get all lists in this web
     SPListCollection listCollection = web.Lists;

     // first way is to use the GUID for TemplateFeatureId of picture library
     foreach (SPList eachList in listCollection)
     {
         if (eachList.TemplateFeatureId == new Guid
                                        ("00bfea71-52d4-45b3-b544-1c71b620109"))
         {
             ddl.Items.Add(eachList.Title);//here you will get picture libraries
         }
     }

     //second solution will be using the template name
     SPListTemplate Templatetype = SPContext.Current.Web.
                                        ListTemplates["Picture Library"];
     foreach (SPList list in listCollection)
     {
         if (list.BaseTemplate == Templatetype.Type)
         {
             ddl.Items.Add(list.Title);//here you will get picture libraries
         }
     }
  }
 }

Similarly you can use this post http://blogs.technet.com/b/vinitt/archive/2009/11/04/list-of-feature-id-listtemplate.aspx to get the other TemplateFeatureId’s and template name. Using this you can similarly get other types lists also.

How to write programmatically into ULS log?

October 14, 2011 Leave a comment

Hi Friends,

SharePoint uses ULS log to add the activities like error logging, notifications and other. ULS log is available at 14hive/Logs folder.

So, why can’t we use the same to log our exceptions and information.

We can use following code to log the entry in ULS log.Remember to add the reference to the Microsoft.Office.Server dll in your project.

Microsoft.Office.Server.Diagnostic.PortalLog.LogString("Error – {0} – {1} – {2}",
"Message:",exception.Message+"\n Trace : ",exception.StackTrace);

Happy coding….