Wednesday, October 10, 2012

Object null reference Error when opening the Site / Document Library in the SharePoint

 

Server Error '/'  Application

Object reference not set to an instance of an object

Description: An unhandled exception was generated during the execution of the current web request. please review the stack trace for more information about the error and where it orginated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]

     Microsoft.office.server.Administration.UserProfileApplicationProxy.get_ApplicationProperties()  +134

Microsoft.office.server.Administration.UserProfileApplicationProxy.get_PartitionIDs() +44

Microsoft.office.server.Administration.UserProfileApplicationProxy.IsAvailable(SPServiceContext ServiceContext) +134

// -----------------------------------------------------------------------------------------------------------------------------

This error occurred in SharePoint installation on Windows Home Premium. But when I searched I found out this is happening because of the incorrect configuration of user profile service. Therefore I delete the user profile service application which help me to solve the issue.

Go to Manage Service Application in the Central Administration

image

Delete the User Profile Service Application

image

Friday, October 5, 2012

show headers when gridview is empty asp net

Here .NET 4.0 added a new property called ShowHeaderWhenEmpty in the grid view. So you can make it true in the gridview tag.

 <asp:GridView ID="gridAccounts" runat="server" ShowHeaderWhenEmpty="true" >

But in the other versions you need to add a blank row manually if no data found.

Tuesday, October 2, 2012

Create Client Context To Access SharePoint 2013 (Office 365 Preview) in AutoHosted SharePoint App Model using SharePoint client object model (CSOM)

If we are using SharePoint app model AutoHosted Environment we need to use Client Context model to access SharePoint.

Therefore First you need to get a Valid Access Token from SharePoint Server. For that you need to pass the SharePoint Site Url (This is available as SPHostUrl in the Query String) and Context Token that we can generate from passing the request Object.

TokenHelper Class provides methods that used can be used to access the SharePoint server and generate Access Tokens.

image

1. Get the Context Token by passing the HttpRequest

String context = TokenHelper.GetContextTokenFromRequest(Request);

2.Then get the Uri from the query string which provides the path to SharePoint server.

Uri SharePointUri = new Uri(Request.QueryString["SPHostUrl"]);

3. Then validate and generate access Token

SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(context, SharePointUri.Authority);
String AcessToken = TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;

4. Finally get a ClientContext By passing Url and AccessToken

ClientContext ClientC = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), AcessToken);