So for that one found two perspectives.
1) Compare the view fields only.
2) Compare the view fields with order also.
For that we found one good article from Adam Buenz
But I found the other ways.
For second approach we have a smart and easy way
Compare the view fields with order.
For that we just need to compare SchemaXml of ViewFields property.
Here is the snippet
private bool CompareViewWithOrder(SPView FirstView, SPView SecondView)
{
if (FirstView.ViewFields.SchemaXml == SecondView.ViewFields.SchemaXml)
return true;
else
return false;
}
Compare the view fields without Order.
If order doesn’t mean and you just want to compare the fields of the views then here is the snippet.
private bool CompareViewWithoutOrder(SPView FirstView, SPView SecondView)
{
string[] strarrFirstViewFields = new string[FirstView.ViewFields.Count];
string[] strarrSecondViewFields = new string[SecondView.ViewFields.Count];
FirstView.ViewFields.ToStringCollection().CopyTo(strarrFirstViewFields, 0);
SecondView.ViewFields.ToStringCollection().CopyTo(strarrSecondViewFields, 0);
if (strarrFirstViewFields.Length == strarrSecondViewFields.Length)
{
for (int i = 0; i < strarrFirstViewFields.Length; i++)
{
bool bFieldFound = false;
for (int j = 0; j < strarrSecondViewFields.Length; j++)
{
if (strarrFirstViewFields[i] == strarrSecondViewFields[j])
{
bFieldFound = true;
break;
}
}
if (!bFieldFound)
{
return false;
}
}
return true;
}
else
return false;
}
So these are the way for comparing the SharePoint views with fields and order of the fields.
No comments:
Post a Comment