Pages

Monday, May 19, 2014

Verify SPUtility.SendMail is working or not

Generally once we configure the Incoming/Outgoing Mail settings in Central Admin, we assume that now from SharePoint Object Model we can send an mail. For this we use the SPUtility.SendMail Method, but in some cases it fails and mail will not be send. In order to verify as a quick step, you can do send an email from Powershell using the same Namespace and Method. If this works fine, then it is 99% sure that it works from our Code.


$email = "test@sharepoint.com"
$subject = "Verify Send Mail"
$body = "Hello..Welcome to SharePoint"

$site = New-Object Microsoft.SharePoint.SPSite "http://sharepoint"
$web = $site.OpenWeb()
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,0,0,$email,$subject,$body)

// A True or False will confirm the message has been sent or not

SharePoint 2013 Client People Picker Control

The SharePoint Client People Picker control looks very good and gives end user easy of selecting the targeted user with its dynamic drop down list of keyed characters.

To use this in normal way, it looks pretty easy too. Paste the below code and it works fine as expected.

<SharePoint:ClientPeoplePicker
Required="true"
ValidationEnabled="true"
ID="pplPickerSiteRequestor"
UseLocalSuggestionCache="true"
PrincipalAccountType="User"
runat="server"
VisibleSuggestions="3"
Rows="1"
AllowMultipleEntities="false"
CssClass="ms-long ms-spellcheck-true user-block"
ErrorMessage="*" 
/>

I am not sure whether its a bug or desgined as per client side for OOB forms. Here I faced a challenge where I require in this control user need to allow for Only One User.

The problem is if user enters second user it should restrict and should not submit the form. Basically if you observe the attribute AllowMultipleEntities="false" as developer we think it will takecare of. But this happens the half way, like it submits the form but in the server side you will get only one user. In order to avoid this, I embedded a custom validator and controlling the form to not to submit if more than one user is there. 

Below is the snippet code for it.

<asp:CustomValidator ID="cvpplSiteRequestor" runat="server" ControlToValidate="pplPickerSiteRequestor" ForeColor="Red" 
ClientValidationFunction="CheckSiteRequestor" 
ErrorMessage="User is a required field" ValidationGroup="SiteAccessForm" Text="*"></asp:CustomValidator>

Javascript Code:-

function CheckSiteRequestor(sender, args) {
args.IsValid = false;
var userCount = $("span.ms-entity-resolved").length; //Returns the Resolved User Name 's Count

if (userCount === 1) {
args.IsValid = true;
}
}


Here I do have another requirement where having Clear Button, which should clear all input form elements. For this Client People Picker, we dont have any default attribute or function. Below is the code snippet which will make sure the OOB feature is residing.

Javascript Code:-

function ClearFields() {

$("#<%= pplPickerSiteRequestor.ClientID %>_TopSpan_EditorInput").attr('placeholder', 'Enter a name or email address...');

$("#<%= pplPickerSiteRequestor.ClientID %>_TopSpan_InitialHelpText").css("display", "none");

var processedUserListCount = $(".sp-peoplepicker-userSpan").length;

for (var i = 0; i < processedUserListCount; i++)
SPClientPeoplePickerProcessedUser.DeleteProcessedUser($(".sp-peoplepicker-userSpan")[0]);
}

Friday, May 9, 2014

Configure Custom Access Denied Page - BUG in SharePoint 2013

There are many reasons that lead to the need to have your own Custom Access Denied Page, such as changing the text of the message or adding a more dynamic page / form to collect information from the user or perform some other function. Once you build your page and get it deployed to Layouts Folder and use below Powershell Commands


We can use the following PowerShell command for it

$web = Get-SPWebApplication http://WebApplicationURL/
Set-SPCustomLayoutsPage -Identity AccessDenied –RelativePath "/_layouts/15/Folder/CustomAccessDeniedPage.html" -WebApplication $web

Or

$web = Get-SPWebApplication http://WebApplicationURL/
$web.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::AccessDenied, "/_layouts/15/Folder/CustomAccessDeniedPage.html ")
$web.Update()

Check the set property with below PowerShell command

$web = Get-SPWebApplication http://WebApplicationURL/
Get-SPCustomLayoutsPage -Identity AccessDenied -WebApplication $web | Format-List

You will observe the updated Value but when you try browsing you will get the default AccessDenied Page but not the custom access denied page. This is a known bug in SharePoint 2013 product. Till now with the current release of CU1 in Feb 2014, this issue is not been fixed.


Inorder to accomplish this, you can go with HttpHandler or HttpModule. Here we preferred to go with HttpModule and below is the code snippet for it.


public class CustomAccessDenied : IHttpModule
{
public void Init(HttpApplication app)
{
app.PreRequestHandlerExecute += new EventHandler(app_PreRequestHandlerExecute);
}
void app_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string str = Path.GetFileName(new Uri(context.Request.Url.AbsoluteUri).LocalPath);

if (str.ToLower().Equals("accessdenied.aspx"))
{
context.Response.Redirect("/_layouts/15/customaccessdenied.aspx",true);
}
}

public void Dispose()
{
}
}


Note:- The custom access denied page [aspx] should has to Inherit from "Microsoft.SharePoint.ApplicationPages.AccessDeniedPage" class.
e.g. <%@PageLanguage="C#"Inherits="Microsoft.SharePoint.ApplicationPages.AccessDeniedPage"MasterPageFile="~/_layouts/simple.master"%>

Now write your c# code inline in PlaceHolderMain in the .aspx page. (This is the drawback).

Sunday, November 17, 2013

Setting up Welcome Page for a SharePoint Site

Some SharePoint objects needs an instance to work perfectly, and below line of code will not work:-
 SPSite site = new SPSite("http://a2zdinesh:1010/sites/InternetSite/");
SPWeb web = site.OpenWeb();
web.RootFolder.WelcomePage=”SitePages/Dashboard.aspx”;
web.RootFolder.Update(); 

After trying hard came to know that with above way we cannot set the Welcome page for a non-publishing site. Exact reason is not well kept in any MSDN and to set we need to use the SPFolder Object. Below is the sample code of it,

SPSite site = new SPSite("http://a2zdinesh:1010/sites/InternetSite/");
SPWeb web = site.OpenWeb();
SPFolder folder = web.RootFolder;
folder.WelcomePage = "SitePages/Dashboard.aspx";
folder.Update();

Will post you if I get any..:-) 
 

Sunday, November 3, 2013

KPI's in WSS/SharePoint Foundation using Dataview Webpart

Business Problem:-
A Small or Medium Scale industries who can't afford to buy the MOSS 2007 or SP 2010/2013, and having the environment of WSS [Any version] or SharePoint Foundation [Which is very low Cost] requires the Key Performance Indicators or the better Look and feel or the specified functionality.

Technical Issue:-

If the users use the MOSS 2007 or SP 2010/2013, the above problem is solved with OOB features. If he wants on WSS [Any Version] or on SharePoint foundation, we will be not having the Content Query webpart or KPI Webparts. Then we can solve the issue by introducing the Data view Webpart. [With Workaround on this OOB Webpart]

Steps to follow:-
1. Create a New Page in the SharePoint Designer.

2. Click on Insert -> SharePoint Controls -> Data View as shown below.
3. After placing it, you will observe as below, where the Webpart Zone will be placed in Page and in the right section you can see the Data Source Library

 

4. Now select the required Data Source like list or library etc., Let us suppose select One List like below screen.
                                           

5. After selecting List you will get the Data Source Details as below. Select the required fields to view and click on the Insert Selected Fields -> Mulitple Item View
                     

6. You will observe the below screen, where in the code you can see the XSL Stylesheet. Hope now you all got my next steps if you are aware of devleoping Content Query Webpart with XSL Styling.


Create KPIs
7. Now it’s time to create some fancy indicators to show if goal is reached. To do so you will need to open your page in SharePoint designer code view.

8. Add an additional th tag. It will create one additional column to display our KPI status icon.

9. Now we will need to add actual code to display the image. Look for the following code:


10. The code above displays the value of the Value column of our list. Paste the following code below it.
<td class="ms-vb">
<img alt="KPI Status Icon">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="number(@Forecast_x0020_Cost) &lt; number(@Cost)">/_layouts/images/statusAmber.png</xsl:when>
<xsl:otherwise>/_layouts/images/statusRed.png</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
</td>
Here in the above code place required logic.

11. You will observe as below. [Don’t get confused as below is one which I added two Columns as Indicators]
 

12. Now browse the Page.

SPMetal - SharePoint 2010 & 2013

As we know SP 2010 has introduced a way where we will now be able to implement OOPS principles for SharePoint Code. In other words we can now have an easier way to understand and implement object oriented principles in SharePoint. The short answer on how to do this is - LINQ + SPMetal tool.
I recently started using SPMetal and was amazed how easily I abstracted the logic and got design time checking of web, list schemas, content types, etc.

Overview :- http://msdn.microsoft.com/en-us/library/ee538255.aspx

How to use of SPMetal:- http://msdn.microsoft.com/en-us/library/ee538587.aspx

With Screenshots of SPMetal with External List:- http://fabiangwilliams.wordpress.com/2010/01/03/how-to-using-spmetal-utility-in-sharepoint-2010-to-presumably-manipulate-data-on-a-bcs-external-list/

Sample from Codeplex:-  http://linqtosharepoint.codeplex.com/wikipage?title=SpMetal&referringTitle=Home

Saturday, November 2, 2013

Research Work on Existing Mobile Banking Products

My Professor used to think about me as A VERY GOOD BOY because I used to take books to the class when none attended his class. But he never knew the fact that in the book I used to have a photo of my girlfriend and the reason to attend the class was to have a chance to flirt with her.

I wouldn't blame my Dad for spoiling me by buying me a Mobile. With the arrival of a mobile, my attendance started to decline and thanks for the Providers who given attractive offers. Then my love started towards Mobile too where it went lot of sleepless nights of what it is doing and what it can be done. As I entered my career into Banking Sector Company added more brainstorms and clear picture of Mobile Banking Area.  

Even though my lovely things are filled into my Mobile, I am still having hard time with filling up my Pockets with Money Purse & Cards Pouch. Even some place it made already replacing Money Purse with only Card Pouch but I say that its not TOTALLY. Then the way of thinking went in finding the thing which replaces all into One or else even nothing should be.

Of course as of now I got an idea of replacing the Three Money purse, Cards Pouch & Mobile into One. That is Mobile itself. Let me tell clearly how it will be and What it all can do.

Already in the Market there are many Cellphone Banking Products and Money Transfer Services, where initially I thought no such exists in the market.
  • M-PESA                     
  • SharPay -
                    http://www.youtube.com/watch?v=wV7fd6ioG7M
  • WIZZIT
  • YUCASH
  • ZAP
Hope you all got many doubts right from Security ,Speed etc., I too accept with you but to be say once more in Simple words NOTHING IS IMPOSSIBLE. Especially the Aggressive TEAM works..I tried best to take some info through Web and Personal Interaction with Leaders in the Market and framed a few roles and respective Queries...!!

CIO's Clarifications
What would be the RoI? What about confidentiality of data? These are obvious questions management would ask a CIO trying to implement mobile applications. Adopting any mobile application is an expense, with no assurance of direct returns. E.g., customers may use a bank's short code toll free but the bank has to pay the application providers and the operators.

Of course, returns are in the shape of better customer focus. If customers get better service they remains loyal and brings in more business. It becomes a great tool in acquiring new customers and retaining old ones.

In the B2B space it gives employees flexibility in business execution and makes the whole process efficient and reduces the turnaround time. Employees have everything on the mobile and don't have to rush to the office for data or consultations before closing deals. Such application gives obvious competitive advantages.

Overall, workforce and IT infrastructure is optimally utilized, which in the long run reflects in the company's balance sheet.