Showing posts from November, 2011

Add Safe control entry in web.coinfig using SPWebConfigModification Class

SPWebConfigModification Class : Holds modifications that are made to the web.config. Following example helps you to add the safe control entry on feature activation.
publicoverridevoid FeatureActivated(SPFeatureReceiverProperties properties)         { try             { SPWebService contentService = SPWebService.ContentService;                 contentService.WebConfigModifications.Add(GetConfigModification()); // Serialize the web application state and propagate changes across the farm.                 contentService.Update(); // Save web.config changes.                 contentService.ApplyWebConfigModifications();             } catch (Exception e)             { Console.WriteLine(e.ToString()); throw;             }         }
publicoverridevoid FeatureDeactivating(SPFeatureReceiverProperties properties)         { try             { SPWebService contentService = SPWebService.ContentService;                 contentService.WebConfigModifications.Remove(GetConfigModification()); // Serialize the web application s…

Why we need a AllowUnsafeUpdates.

AllowUnsafeUpdates is a property of
SPSiteSPWeb If user do't have any permission to update the data. So we run the code with special permission for that we use RunWithElevatedPrivileges block, by using this code user update the item on the behalf of system account, for that we need to Set AllowUnsafeUpdates   to true to disable security validation on Update().This is request if persisting anything within RunWithElevatedPrivileges.Any exception, handled or otherwise, sets AllowUnsafeUpdates to False.

SharePoint2010 Replace AccessDenied.aspx, Confirmation.aspx and other page with our own custom page

In sharePoint2010, we can replace the list of the following page with our own custom page. AccessDenied.aspxConfirmation.aspxError.aspxLogin.aspxReqAcc.aspxSignOut.aspxWebDeleted.aspx

For replace the default list of pages as mentioned in above. We have a classSPWebApplication Undernamespace Microsoft.SharePoint.Administration. SPWebApplication class have a SPCustomPage enum which has a following values.
publicenumSPCustomPage         { // Summary: //     Specifies that no page will be replaced with a custom page.             None = 0, // // Summary: //     Specifies that the AccessDenied.aspx page will be replaced with a custom //     page.             AccessDenied = 1, // // Summary: //     Specifies that the Confirmation.aspx page will be replaced with a custom //     page.             Confirmation = 2, // // Summary: //     Specifies that the Error.aspx page will be replaced with a custom page.             Error = 3, // // Summary: //     Specifies that the Login.aspx page will be replaced with a custom …

SharePoint2010 : The root of the certificate chain is not a trusted root authority

Problem : The root of the certificate chain is not a trusted root authority.

Event Log Error

An operation failed because the following certificate has validation errors:\n\nSubject Name: CN=<Certificate URL>, OU=Domain Control Validated, O=<Certificate URL>\nIssuer Name: SERIALNUMBER=07969287, CN=Go Daddy Secure Certification Authority, OU=, O=", Inc.", L=Scottsdale, S=Arizona, C=US\nThumbprint: xxxxxxxxxxxxxxxxxxxxxx\n\nErrors:\n\n The root of the certificate chain is not a trusted root authority.

Main problem is your SSO Application unable to make a trust with SharePoint 2010 Site.

Common mistake:Most of developer while implementing the SSL on SharePoint Site they only include the main Certificate to SharePoint Security "Manage Trust"  i.e. (<Site URL>). SharePoint Site unable to make the trust between the SSO Site.

Solution : You need to first see the hierarchy of the certificate. How to check th…

SharePoint 2010 Update Default List View By Code

SharePoint 2010 Create List view using Code. Open visual studio Create a console Application give it name and Add “Microsoft.SharePoint” Ref. to your project.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using Microsoft.SharePoint;
namespace SharepointForDeveloper_AddView { classProgram     { staticvoid Main(string[] args)         { if (args.Length < 2)             { Console.WriteLine("Missing Parameters 1. <ListUrl> 2. <XmlFile Path>"); return;             } string paramListUrl = args[0]; string paramViewXml = args[1];
using (SPSite site = newSPSite(paramListUrl))             { using (SPWeb web = site.OpenWeb())                 { string serverRelativePath = GetRelativeUrl(paramListUrl); SPList list = web.GetList(serverRelativePath);
XmlDocument doc = newXmlDocument();                     doc.Load(paramViewXml); SPView loadedView = newSPView(list, doc); SPView newView = list.Views.Add(loadedView.Title, loadedView.ViewFields.ToStri…