Pages

Wednesday, January 25, 2012

Document Library ItemUpdated event occurring twice

Hello

I have been working on Document Library ItemUpdated EventHandler and getting very frustration result, each time it runs twice, this is bad, as it calls back database requests and makes slow system.
Now what to do? Well, we do have one workaround; write this one in the ItemUpdated event of documentlibrary.
if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null &&
    properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)

Enjoy this Workaround!!!

Thanks
Disha Shah

Friday, January 13, 2012

How to get the SPUser Object from SPfield(Person or Group)

Hello Friends

Here is the code how to get the SPUser Object from SPfield(Person or Group) from a sharepoint list and get the email address, login name of that user.

Here is a snippest of code.

SPFieldUser userField = (SPFieldUser)SPContext.Current.Web.Lists["SiteName"].Fields.GetField("AdminName");
                SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(myitem["AdminName"].ToString());
SPUser user = fieldValue.User;
//user.LoginName;

Happy Coding
Disha Shah!!!

Thursday, January 12, 2012

How to create Custom 404 Error Page in SharePoint 2010

Hello Readers

It is very good practice to create Custom 404 Page  for SharePoint Web Application because users always love some custom and  meaningful text on pages rather than “this resource can not find please go back to site”.

So Let us see how to create custom 404 Page in SharePoint 2010.

Let us see step by step process for that
  1. Copy the original sps404.html located at Local Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033 and rename that file  and give some useful and meaningful name like spsCustom404.html in the same directory.  
     2. Write this code in spsCustom404.html  file

     <html>
     <head>
       <meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
       <meta HTTP-EQUIV="Expires" content="0" />
       <noscript>
              <meta http-equiv="refresh" content="0; url=/_layouts/CustomError.aspx" />
       </noscript>
       <script language="javascript" src="/_layouts/1033/init.js"></script>
       <script language="javascript" src="/_layouts/1033/core.js"></script>
       <script language="javascript">
              var requestedUrl = escapeProperly(window.location.href);
              STSNavigate("/_layouts/CustomError.aspx");
       </script>
     </head>
     <body>
     </body>
     </html>


3         3. Create an aspx file named as customerror.aspx under Local Drive:\Program Files\Common   Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\

   4. Write the content you want to write for users in the aspx page. 

   5.   Now It is time for deployment so easy in SharePoint 2010. Write these command lines in Poweshell   Script
          $webapp =Get-SPWebApplication http://www.webapplicaion.url
          $webapp.FileNotFoundPage = "spsCustom404.html"
          $webapp.update()

 Enjoy!!!

Disha Shah

System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.

Hello Friends
One of SharePoint WebApplication uses claims based web application. This web application has a custom membership provider that is registered at the web application, central administration and security token service level.
I try to login with valid credentials I found an error below.
Server Error in '/' Application.


Runtime Error Description: An application error occurred on the server. The current custom error
The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.]
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.ReadResponse(Message response) +1161205
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr) +73
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst) +36
   Microsoft.SharePoint.SPSecurityContext.SecurityTokenForContext(Uri context, Boolean bearerToken, SecurityToken onBehalfOf, SecurityToken actAs, SecurityToken delegateTo) +26405809
   Microsoft.SharePoint.SPSecurityContext.SecurityTokenForFormsAuthentication(Uri context, String membershipProviderName, String roleProviderName, String username, String password) +26406316
   Microsoft.SharePoint.IdentityModel.Pages.FormsSignInPage.GetSecurityToken(Login formsSignInControl) +188
   Microsoft.SharePoint.IdentityModel.Pages.FormsSignInPage.AuthenticateEventHandler(Object sender, AuthenticateEventArgs formAuthenticateEvent) +123
   System.Web.UI.WebControls.Login.AttemptLogin() +152
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +124
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

This is very annoying error because we do not have exact what is going wrong. To receive that error message that is occurring do the following:
1>     Open IIS (Internet Information Server) and navigate to “SharePoint Web Services”  subsection under “Sites” Section. Click the node open and select “SecurityTokenServiceApplication” , right click and click on “Explore

2>    You can see web.config file in the windows. Open this file and look for the following section:
<behaviors>
  <serviceBehaviors>
    <behavior name="SecurityTokenServiceBehavior">
      <!-- The serviceMetadata behavior allows one to enable metadata (endpoints, bindings, services) publishing.
           This configuration enables publishing of such data over HTTP GET.
           This does not include metadata about the STS itself such as Claim Types, Keys and other elements to establish a trust.
      -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- Default WCF throttling limits are too low -->
      <serviceThrottling maxConcurrentCalls="65536" maxConcurrentSessions="65536" maxConcurrentInstances="65536" />        
    </behavior>
  </serviceBehaviors>
</behaviors>
Add an extra debug tag in this section. The tag looks like this:
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
This tag needs to be placed in the behavior tag. After you place the tag in the section it will look like this:
<behaviors>
  <serviceBehaviors>
    <behavior name="SecurityTokenServiceBehavior">
      <!-- The serviceMetadata behavior allows one to enable metadata (endpoints, bindings, services) publishing.
           This configuration enables publishing of such data over HTTP GET.
           This does not include metadata about the STS itself such as Claim Types, Keys and other elements to establish a trust.
      -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- Default WCF throttling limits are too low -->
      <serviceThrottling maxConcurrentCalls="65536" maxConcurrentSessions="65536" maxConcurrentInstances="65536" />
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
After changing the “web.config” we received the detailed and correct message
Server Error in '/' Application.


Error was “FormsAuthUser” Password has been changed.
So you have the detail of the error and you have clue what is going on.
Enjoy Debugging!!!
Disha Shah