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