Display User field in search result

How to display custom user field in search result .

This includes two steps field definition and create a managed metadata property.

1. Field Definition

<Field ID=”{AE6EFA2E-DF0E-4EF5-8AB7-309FBC5465B9}”

Group=”My Columns”
Mult=”FALSE”
UserSelectionMode=”0″
Type=”UserMulti” List=”UserInfo”
Name=”helloauthor” DisplayName=”helloauthor”
SourceID=”http://schemas.microsoft.com/sharepoint/v3&#8243;
StaticName=”helloauthor”

/>

2. Before creating managed property add some data to the field may be in your
documents library or custom list etc… and then crawl the search , once
your property is propagated  then create managed property.

Now re crawl your search and the perform search based on user name.

How to revert library items to its previous working condition.

There are some scenarios in day to day development, where current changes need to revert to  its previous working condition.
This can be achieved by finding the correct Version from Version-History of the item
and restore it accordingly.
The below code snippet is just for information, for files in document library and has the same approach for List Item as well.

Sample code Snippet…..

using (SPSite mksSite = new SPSite(“http://devsp:9900/&#8221;))
{
using (SPWeb mksWeb = mksSite.OpenWeb())
{
mksWeb.AllowUnsafeUpdates = true;
SPList lst = mksWeb.Lists[“helloListName”];
IEnumerable<SPListItem> demoLib = lst.Items.OfType<SPListItem>();
SPListItemCollection demoFormCollection = lst.Items;
XmlDocument itemVersionDoc = new XmlDocument();
using (WebClient client = new WebClient())
{
for (int i = 0; i < demoFormCollection.Count; i++)
{
SPListItem item = demoFormCollection[i];
byte[] fileByte = item.File.OpenBinary(SPOpenBinaryOptions.None);

// Validate your output if this is the correct one. THEN no further action required//

if (THE OUTPUT AFTER VALIDATION IS INCORRECT THEN)
{

IEnumerable<SPFileVersion> listItems = item.File.Versions.OfType<SPFileVersion>();

var allResults = listItems.OrderByDescending(prod => prod.ID);

foreach (var vitem in allResults)
{

bool needToFindOtherVersion = true;
{
if (needToFindOtherVersion)
{
//<MOST IMPORTANT> “_vti_history” IS THE PLACE FOR ALL THE VERSIONS//

client.Credentials = CredentialCache.DefaultCredentials;
fileByte = client.DownloadData(mksWeb.Url.TrimEnd(‘/’)
+ “/_vti_history/” + vitem.ID.ToString() + “/helloListName/” + item.Title);

//NOTE: fileByte is the OUTPUT from  VERSION HISTORY//

//CHECK IF THE OUTPUT IS THE CORRECT ONE AS PER REQUIREMENT//
if (THE OUTPUT AFTER VALIDATION IS INCORRECT THEN)
{
needToFindOtherVersion = true;
}
else
{
needToFindOtherVersion = false;

item.File.Versions.RestoreByLabel(vitem.VersionLabel);
Console.WriteLine(“Correct Version Restored Successfully.“);
break;
}
}

}
}

}
mksWeb.AllowUnsafeUpdates = false;
}

Export Import Page

Export Page

One problem with STSADM tool is it cannot export List Item (like Publishing Pages…)  , It’s better to do export using object model and then import in production environment.

Options to export are :-
SPDeploymentObjectType.File              
SPDeploymentObjectType.Invalid
SPDeploymentObjectType.Folder
SPDeploymentObjectType.List
SPDeploymentObjectType.ListItem;
SPDeploymentObjectType.Site
SPDeploymentObjectType.Web

SPSite site = new SPSite(SiteName);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[“Pages”];
SPExportObject exportObject = new SPExportObject();
SPListItem listItem = null;
listItem = list.Items[i];
exportObject.Id = listItem.UniqueId;
exportObject.Type =SPDeploymentObjectType.ListItem;

SPExportSettings exportSettings = new SPExportSettings();
SPExportSettings settings = new SPExportSettings();
exportSettings.SiteUrl = SiteName;
exportSettings.FileLocation =@”E:\WorkArea\XML_XSL\“;
exportSettings.BaseFileName =”SITE1.cmp”;
exportSettings.ExportMethod =SPExportMethodType.ExportAll; 

exportSettings.AutoGenerateDataFileName =true;
exportSettings.ExportObjects.Add(exportObject)

exportSettings.IncludeSecurity =SPIncludeSecurity.All;
exportSettings.IncludeVersions =SPIncludeVersions.All;
SPExport export = new SPExport(exportSettings);
export.Run();
string exportFileLocation = exportSettings.FileLocation + “\\” + exportSettings.BaseFileName;
 
Import Page

string targetListURL = “http://devsp:5001/Pages/“;
SPImportSettings settings = new SPImportSettings();
settings.SiteUrl = targetListURL;
settings.BaseFileName = “SITE1.cmp”;
settings.FileLocation = Path;
settings.FileCompression = true;
settings.IgnoreWebParts = false;
settings.IncludeSecurity = SPIncludeSecurity.All;
settings.RetainObjectIdentity = false;
settings.UpdateVersions = SPUpdateVersions.Append;
settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
settings.WebUrl = targetListURL;
settings.CommandLineVerbose = true;
settings.LogFilePath = @”E:\WorkArea\XML_XSL\bkp\import.log”;settings.Validate();
SPImport import = new SPImport(settings);

import.Run();