Thursday, June 9, 2011

Failure trying to synch site for ContentDB WebApp

Problem:
Periodical errors in the event log of a SharePoint 2010 server with the following error event descriptions:
Failure trying to synch site for ContentDB WebApp . Exception message was Cannot insert duplicate key row in object 'dbo.UserMemberships' with unique index 'CX_UserMemberships_RecordId_MemberGroupId_SID'. The statement has been terminated.
Cause:

Old references to non existing content databases in the synchronization job list.

Fix:
List databases which are not synced for more than two days
stsadm -o sync -listolddatabases 2

Delete old database references from the config db
stsadm -o sync -deleteolddatabases 2

Tuesday, May 10, 2011

Upgrade SharePoint 2010

In this article I will put lessons I learned when try upgrade Share Point 2007 sites to Share Point 2010 I will update this article when find new item:
Consider Visual upgrade Mater Page:



  1. Check URL:http://msdn.microsoft.com/en-us/library/ee539981.aspx
Copy All Physical Files from old site:


  1. Features


  2. Site Templates


  3. Custom Lists,Custom Fields, Content types, and etc.
General Code:



  1. It is prefer all dlls are used with feature has strong name and in GAC.Converting SSP to separate services:


  2. When use custom code to search using API (This include third party code)


  3. When use custom code to access User Profile using API (This include third party
    code)


  4. When use custom code to access BDC using API (This include third party




Corrupted out of the box work flow:
When we try to start work flow for document library you will find out of the box workflow Approval and FeedBack. I didn't find it when upgrade to 2010.
To Solve this problem I assigned new workflow for Document Content Type of Site with name approval and FeedBack with default setting.

Report center feature is removed from SharePoint 2010:

If you used it you need to copy feature folder from sharepoint 2007 and install feature using command:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\ReportCenterCreation stsadm -o installfeature -filename ReportCenterCreation\feature.xml -force

Missing Web Parts:After upgrade found errors to find web parts information run query:
SELECT *
FROM dbo.AllWebParts
WHERE WPT.tp_WebPartTypeId = MissingID

Custom Site Definition Upgrade:when you upgrade and you have custom site definition. You need to consider items below:






  1. All Site created from this site definition will be upgraded, Only you need to copy all physical files of this site definition and all of its dependence (custom fields, Custom Lists, features,...etc).




  2. To use site definition in new environment need to consider some points:






  • ReportCenterCreation feature has been removed need to deploy this feature from old environment as above or replace by new template for BI.




  • UI Versions: SharePoint Site has property called UIVersion.
    When its value is 3 mean display interface as version SharePoint 2007. When its value is 4 need interface as SharePoint 2010 (Need some modifications in master-pages, style sheet, and etc). For upgraded created sites it will be kept 3 until you run Visual Upgrade.
    But when you create site from old site definition UI Version is 4. Which need to modify GUI to work fine with SharePoint 2010 UI or you need to keep the same interface you need to update UIVersion to 3 and update another property UIVersionUpgrade to true to give user option to upgrade site UI to SharePoint 2010 interface.
    To keep UIVersion 3 you need to create feature added to onet.xml updated when site is created:
    http://aanuwizard.wordpress.com/2010/06/30/sharepoint-2010-branding-changing-uiversion-of-sharepoint-site/uiversion-of-sharepoint-site/
    Also you can keep same UI work as SharePoint 2007 or SharePoint 2010 depend on on UIVersion value:
    http://www.khamis.net/blog/Lists/Posts/Post.aspx?ID=17

    Site templates:
    Any webs created from site templates based OOBT will upgrade perfectly fine so long as SharePoint 2010 knows the site template it's based on.
    But STP file itself as it sits in the site template gallery will not be upgraded to SharePoint 2010. Before upgrade you'll need to create a new site using each of your site templates, then save them back out after the upgrade. Site template go away in SharePoint 2010, they're now solution.

    Navigation:When you use navigation like below:
    <add name="MyCustomSiteMapProvider" siteMapFile="mycustom.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

    you will find url appear as http://domain/test.aspxhttp://domain.aspx.

    To solve this issue you need to replace site map provide



Microsoft.SharePoint.Navigation.SPXmlContentMapProvider by System.Web.XmlSiteMapProvider
This will appear as below:

<add name="MyCustomSiteMapProvider" siteMapFile="mycustom.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />


Related Artcles:
Missing Features after upgrade:
http://justgeeks.blogspot.com/2012/06/resolving-missing-references-when.html
http://blogs.technet.com/b/sushrao/archive/2011/12/02/sharepoint-2010-missing-server-file-or-server-configuration-issues.aspx

Sunday, January 23, 2011

Unable to modify navigation - Add heading/link

When I Try to modify Navigation in a site and add a heading, this is not working. When pushing OK, there is nor error messages appearing, but the heading is not showing up.
Problem missed navbar nodes of the onet.xml in custom site template.
  • Solution add NavBar nodes to onet.xml:<navbars>
    <navbar name="SharePoint Top Navbar" id="1002">
    </navbar>
    </navbars>
  • Wrote an SQL query to update the broken sites. T-Sql to execute in contentdbINSERT INTO [NavNodes] ([SiteId] ,[WebId] ,[Eid] ,[EidParent] ,[NumChildren] ,[RankChild] ,[ElementType] ,[Url] ,[DocId] ,[Name] ,[DateLastModified] ,[NodeMetainfo] , NonNavPage] ,[NavSequence] ,[ChildOfSequence])
    SELECT DISTINCT SiteId, WebId ,1002 ,0 ,0 ,1 ,1 ,'' ,NULL ,'SharePoint Top Navbar' ,getdate() ,NULL ,0 ,1 ,0
    FROM NavNodes
    WHERE WebId NOT IN (
    SELECT WebId
    FROM NavNodes
    WHERE Eid = 1002)
  • The query adds the SharePoint Top Navbar node to the NavNodes tables where a web does not already have one.

Wednesday, December 29, 2010

Anonymous user access CQWP

When trying to access Content Query Web Part with anonymous user, It failed to render. While it is working correctly with anonymous user.

I’ve found out that we can fix this issue by adding two fields to the CommonViewFields property of the CQWP:

DocumentIconImageUrl and OnClickForWebRendering, like this:


<property name="CommonViewFields" type="string">DocumentIconImageUrl, Text;OnClickForWebRendering,Text </property>

Other work around:

Create WebPart inherit the CQWP and add an extra column to the resulting table containing data:


public class AnonWorkingContentByQueryWebPart : ContentByQueryWebPart
{
protected override void OnInit(EventArgs e)
{
this.ProcessDataDelegate = ProcessItems;
}

protected virtual DataTable ProcessItems(DataTable data)
{
DataColumn column = new DataColumn("OnClickForWebRendering", typeof(string));
data.Columns.Add(column);

return data;
}
}

I prefer first solution

Webya give unauthorized error

When we added webya to our site it prompt with authentication. When we cancelled authentication page appear without any problem.

After investigation we found webya try to access /pages. To ignore this problem we added HTTPModule to escape this authetication. Sample Code as below:

public class BadRequestHandler : IHttpModule
{
///


/// Don't let the response be cached by the browser. Set up the status code
/// and return.
///

public void ProcessRequest(HttpApplication context)
{
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
if (context.Request.Url.AbsolutePath.ToLower().EndsWith("/pages/"))
ParseStatusCode(context, 200);
}

///


/// Actually set up the status code at this point, and return.
///

protected void ParseStatusCode(HttpContext context, int statusCode)
{
context.Response.StatusCode = 200;
context.Response.End();
}

public bool IsReusable
{
get { return true; }
}

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{
//System.Web.HttpContext.Current.Response.Write("handler started");
System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.MinValue);
if (System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToLower().EndsWith ("/pages/"))
{
ParseStatusCode(System.Web.HttpContext.Current, 200);
}
}
}

Opening HTML Files in Sharepoint 2010

By default, Sharepoint 2010 is blocking the ability to open HTML, Flash, ...some types files directly from a document library. It download it instead of displaying it.

This can be changed in the browser file handling option. To change this option go to:

1. Central Admin\Application Management\Manage Web Applications.
2. Select General Settings for the specified web application
3. For Browser file handling, select permissive. The default is strict.

If we need to keep this option for security.
SharePoint 2010 put these types static in code, You need to create HTTPModule to remove attachment from its header. Example in code below:


public class FixHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}

public void Dispose()
{

}

void OnPreSendRequestHeaders(object sender, EventArgs e)
{
// modify the "Server" Http Header
if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".htm")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".html")
HttpContext.Current.Request.Url.AbsolutePath.EndsWith(".swf"))
HttpContext.Current.Response.Headers.Remove("Content-Disposition");
}
}

Tuesday, December 28, 2010

Add Additional Column to SharePoint 2010 Programmatically

When worked in project I faced problem in adding additional lookup column to list programmatically and I didn't found any article to guide me of doing it. After investigation I found the solution.
Example I have Lookup 2 lists:

  1. Countries with 2 text columns Title as key and Code.
  2. Application have lookup with name CountryTitle

I want to add Code Column of Countries list as additional column of look CountryTitle. The Code below do this action:


string mainListName = "Countries"; //Name of Lookup List
string lookupListName = "Application"; //Name of Main List Needs to add additional field to lookup
string lookupColAdditionalFieldDisplayName = "CountryCode"; //Display name of additional field in main list
string pLookupKeyName = "CountryTitle"; //Name of parent lookup field in main List
string additionalLookupFieldName = "Code"; //Name of additional Field in lookup list
//Main List
SPList mainlst = w.Lists[lookupListName];

//Lookup List
SPList lookuplst = w.Lists[mainListName];

//Main List Fields
SPFieldCollection col = mainlst.Fields;

//Lookup Primary Key
SPFieldLookup spPrimaryField = ((SPFieldLookup)col[pLookupKeyName]);

//Create Additional Field its name in lookup Field1 with display name in list TestDisplayName
SPFieldLookup field = (SPFieldLookup)mainlst.Fields.CreateNewField(SPFieldType.Lookup.ToString(), lookupColAdditionalFieldDisplayName);
field.LookupList = spPrimaryField.LookupList;
field.LookupWebId = spPrimaryField.LookupWebId;
field.LookupField = additionalLookupFieldName;
field.PrimaryFieldId = spPrimaryField.Id.ToString();
field.ReadOnlyField = true;
field.AllowMultipleValues = spPrimaryField.AllowMultipleValues;
field.UnlimitedLengthInDocumentLibrary = spPrimaryField.UnlimitedLengthInDocumentLibrary;
field.Direction = spPrimaryField.Direction;
SPAddFieldOptions op = SPAddFieldOptions.Default;

//Add Additional Field to main list
mainlst.Fields.AddFieldAsXml(field.SchemaXml, true, op);