Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc

A requirement on a recent SharePoint 2010 intranet project that I worked on was to implement a mechanism for users to click on a Contact image on a page which would then create an e-mail addressed to a designated site administrator. This would enable the users to either submit feedback or a question related to a page in the site to the site administrator. This link needed to be available on all pages in the site. The SharePoint site where this needs to be implemented is based on the Publishing Site with Workflow template.

Given that the link needed to be available on all pages in the site, it was decided to add it to the master page. Also, I did not want to hard-code the e-mail address of the site administrator in the master page. This would make it difficult to maintain, if the e-mail address needed to be changed to that of another administrator in the future. So I chose to create a list that would contain the e-mail address. This way the e-mail address can be changed easily by simply updating the list item. ListData.svc provides a way of getting information from a SharePoint list using REST. If you are looking for a good resource on REST, check out this MSDN article. So the approach was to retrieve the e-mail address that is stored in the list using ListData.svc, and then use javascript to auto-populate the “To…” field in the e-mail with the e-mail address retrieved from the list.

Prerequisites

1. In order to use ListData.svc you need to install the ADO.NET Data Services Update for .NET Framework 3.5 SP1 for Windows 7 and Windows Server 2008 R2 which can be downloaded from this Microsoft site.

2. jQuery library which can be downloaded from this jQuery site. I used version 1.4.2 in my solution.

3. Starter Publishing master page (_starter_publishing.master) provided by Randy Drisgill which can be downloaded from this CodePlex site.

Nuts and Bolts

Here are the details on how I implemented the solution:

1. Created a SharePoint List (based on Contacts) in the top level site. The name of the list is Contact. When you create a List based on Contacts, it will include the columns as shown in Figure 1 below.

Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc Figure 1

In my case, I only needed the First Name, Last Name, and E-mail Address columns. So I deleted the other columns. Figure 2 below shows the 3 columns in my List. I also changed the First Name and E-mail Address columns to be required columns.

Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc Figure 2

A screenshot of the first item in the Contact list is shown in Figure 3 below:

Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc Figure 3

2. Within the <form></form> tags in the master page, added code as shown below to render the Contact image that users will click.
<img id="siteAdminEMail" src="/images/link_contact.gif" width="72" height="17" border="0" />
And this rendered the image shown in Figure 4 below:

Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc Figure 4

3. Within the <form></form> tags in the master page, added the following javascript code to handle the click event of the Contact image. It contains a function that retrieves the URL of the top level site and passes it as a parameter to the getContactEMailFromList() function as shown below:

<script type="text/javascript">

$('#siteAdminEMail').click(function()

{



//get top site Url and pass it to the getContactEMailFromList function

var topSiteUrl = "<asp:Literal id="litSiteUrl" runat='server' Text='<% $SPUrl:~SiteCollection/%>' />";

getContactEMailFromList(topSiteUrl);



});

</script>








4. Within the <head></head> tags of the master page, added the code shown below to reference the javascript files. The first line references the jQuery library which I got from the jQuery site. The second line references my custom javascript file, titled HelperFunctions.js. Details on HelperFunctions.js is provided in item 5 below. Both .js files were stored in a document library titled, JSLibrary, in the top level site.




<!-- jQuery and custom javascript references -->

<script type="text/javascript" src="/JSLibrary/jQuery.min.js"></script>

<script type="text/javascript" src="/JSLibrary/ HelperFunctions.js "></script>







5. The HelperFunctions.js file contains 2 functions:



a. getContactEMailFromList() – This function retrieves the value in the EMailAddress column in the first item in the Contact list using ListData.svc. This is done by building the url parameter using the siteURL supplied as input, and then appending the ListData.svc portion. The List contains one Item. So I used Contact(1) to get the first item. EMailAddress is the column in the Contact list which contains the value that we want to retrieve. The $.ajax() call is a jQuery method that performs an asynchronous HTTP request using the url supplied. If the call is successful, the e-mail address is returned in the data object, and another javascript function createEmailMessage is invoked. If it fails, an error message is displayed via the javascript alert() function.



b. createEMailMessage() – This function retrieves the e-mail address from the data object, and then creates a new e-mail with the “To…” field auto-populated with the e-mail address retrieved from the Contact list.




function getContactEMailFromList(siteURL) {



//Build the URL for ListData.svc

//Get the value in the EMailAddress column in the first item in the Contact List

var url = siteURL + "_vti_bin/ListData.svc/Contact(1)/EMailAddress";





$.ajax({

url: url,

dataType: "json",

success: function (data) {

createEMailMessage(data);

},

error: function (data) {

alert("Contact address unavailable.");

}

});

}



function createEMailMessage(data) {



//retrieve the e-mail address

var mailToRecipient = data.d['EMailAddress'];



//Construct mailto

var mailtoSiteAdmin = "mailto:%20" + mailToRecipient;



//Display a new e-mail with the recipient e-mail in the To field

window.location = mailtoSiteAdmin;



}







6. When the Contact image is clicked, a new e-mail message is created and the e-mail address of the Contact person is auto-populated in the To… field as shown in Figure 5 below:



Implement Contact/Feedback functionality using SharePoint 2010 ListData.svc

Destination Folder field in site upgraded from MOSS 2007 to SharePoint Server 2010

I am currently working on a project where we are upgrading our client’s MOSS 2007 based intranet site to SharePoint Server 2010 using the database attach upgrade method. While testing the upgraded 2010 site, we discovered that the Upload Document dialog in document libraries and Upload Picture dialog in picture libraries contained a “Destination Folder” field in addition to the “Upload Document” field. This field is only available in document libraries and picture libraries that were upgraded from the 2007 site. It is not available in document libraries or picture libraries that were newly created in the 2010 site. And this behavior was seen in the top level site and its sub-sites.

A Google search on this led me to this very informative and helpful blog by Brian McCullough. It looks like that this behavior is due to the different values that are assigned to the vti_foldersubfolderitemcount property in the Folder's property bag for an upgraded object versus a new object.

For upgraded objects, this property’s value is set to 1.

For new objects, this property’s value is set to 0.

Also, the upgrade process sets the SPWeb.CustomUploadPage property for upgraded sites to a custom upload page titled uploadex.aspx, as opposed to upload.aspx which is the default page for file uploads. And this custom upload page contains the “Destination Folder” field.

The client did not want this “Destination Folder” field in the upload dialog. Brian provided a PowerShell script in his blog that loops through all Web sites that are contained within the site collection, including the top-level site and its subsites, and checks to see if the SPWeb.CustomUploadPage property is not equal to blank. If true, then it sets the SPWeb.CustomUploadPage property to blank. Doing so, removes the custom upload page (uploadex.aspx) from SPWeb, and reverts back to the default upload page (upload.aspx), which does not contain the “Destination Folder” field.
Here is the PowerShell script to remove the custom upload page (containing the Destination Folder field):
foreach($webapp in get-spwebapplication)
{
foreach($site in $webapp.Sites)
{

foreach($web in $site.AllWebs)

{

if ($web.CustomUploadPage -ne "")

{

Out-File C:\Logs\WebsWithDestinationFolder_Log.txt -Append -InputObject $web.Url

$web.CustomUploadPage = ""

$web.Update()

}

}

}

}

How to Start a SharePoint 2010 / FS4SP Crawl Remotely

With SharePoint 2010 and FAST Search For SharePoint 2010 (FS4SP), it's easy to schedule crawls to run daily, hourly, or according to any other frequency. For most scenarios, scheduled crawls work perfectly.

Sometimes it makes more sense to kick off a crawl based on an event. For example, perhaps your organization runs an Extract/Transform/Load process to prepare data before being crawled. If that ETL job finishes at an inconsistent time, a scheduled crawl may either run too early and miss some updated data or run too late, making queries stale.

To fix that, we'd ideally kick off a new search crawl as soon as the ETL job is done running. With PowerShell, doing so is easy.

The PowerShell Script

$userName = "DOMAIN\serviceAccount"
$passWord = ConvertTo-SecureString "password" -Force -AsPlainText
$indexServerName = “serverName”

# Run the following commands on the remote computer
$credential = New-Object System.Management.Automation.PSCredential($userName, $passWord)
$session = New-PSSession $indexServerName -Authentication CredSSP -Credential $credential
Invoke-Command -Session $session -scriptBlock { `
Add-PSSnapin Microsoft.SharePoint.PowerShell; `
`
$indexServiceAppName = “Search Service Index Application”; `
`
$indexServiceApp = Get-SPServiceApplication -Name $indexServiceAppName; `
$contentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $indexServiceApp `
$contentSource.StartFullCrawl() `
}

How It Works

The above script uses PowerShell remoting to issue requests on a SharePoint indexing server.

The following variables need to filled in:

  • $userName: The full username of an account with permissions to kick off a new search.
  • $passWord: The account's password. Note that dollar signs need to be escaped with tick characters in PowerShell strings (e.g. "Pa`$`$word").
  • $indexServerName: The name of a server running the index role.

An example usage is to run this script as part of a SQL job or SSIS step. The executable to call is "PowerShell.exe" with the above script saved in a "PS1" file as the command's argument.

Because SharePoint 2010 and FAST Search for SharePoint use the same service application architecture, this approach works for either system.

Quickly custom Search Results web part in SharePoint 2010/SharePoint 2007

To create a search results web part that will dynamically create a search query and render the search results is pretty easy.

Create a new web part and inherit the CoreResultsWebPart.

public class MySearchWebPart: CoreResultsWebPart{
public MySearchWebPart(): base() {
// Initialize the search results web part here…
//e.g this.ResultsPerPage = 10; //Set the Fixed Query here.
this.FixedQuery = “Some Query”; // Build query based on some criteria. Either from Page Fields, keywords, etc.
}}







That’s it. This will give you fresh content based on the query that is built at runtime.

Unable to get any search results - FAST for SharePoint

Home > Bloggers > Teo Nedev > FAST for SharePoint - unable to get any search results

Quick Launch

View All Site Content

Documents

Pictures

Images

Lists

Other Blogs

Links

Posts

Comments

Categories

Discussions

Surveys

All Posts

Post

FAST for SharePoint - unable to get any search results

By: Teo Nedev | Posted: April 8, 2011 at 1:20 PM

Add Comment Add Comment | Share It Share It | Category: SharePoint Server

I recently encountered peculiar problem when configuring FAST for SharePoint server in my lab environment. I was using the MS technet document

http://technet.microsoft.com/en-us/library/ff381267.aspx

After configuring the two Search Service Apps (Content and Query) and starting full crawl, I was able to see items in the default search content collection "sp" by running

Get-FASTSearchContentCollection -name "sp"

The problem was, even though the items were supposedly in the index, I was unable to get any results while searching. This was true for both searching via SharePoint FAST search center site, and when trying to use the built-in QRServer on FAST (which can be accessed locally on the FAST server by browsing to http://localhost:13280 if you keep all defaults during configuration, or at http://localhost:base port+280 if you changed the base port)

To make things even more interesting, I was able to feed a document manually using:

Docpush -c sp <filename>

and this document was showing up on both QRServer and SharePoint FAST search center with no problems.

The problem turns out, is I had added the fast service account to the local administrators group on the FAST server, IN ADDITION to it being in the FastSearchAdministrators local group that's created by default after FAST configuration.

This I assume caused search results to be security-trimmed in very unexpected ways.

The fix was easy enough: remove the fast service account from local admins group on FAST server, reset the index on SharePoint, on the Content SSA, followed by cleaning up the sp content collection on FAST.

After re-indexing on the content SSA, documents started showing up in search results with no problem.

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

The InfoPath Form Web Part is pretty handy, but its options for behavior upon submitting are less than ideal. The only options available are leaving the form open, closing it, or opening a new one. Luckily, InfoPath Designer 2010 offers a fairly painless solution. Let’s start with a basic form.

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

This is going to be our default view, but we’ll need two more to handle the submit and cancel actions. Select the Page Design tab on the ribbon and click New View. Name the new view “Submit,” and add some kind of message to the blank page that has appeared.

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

Next, create another view named “Cancel” and add an appropriate message there.

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

Now we need to create a few rules to display these views when appropriate. Navigate back to your default view using the View dropdown menu on the Page Design tab and click your submit button. On the Home tab, click Manage Rules. Add a new action rule with the type Switch views. Select “Submit” from the view list and click OK. Add a similar rule for your cancel button.

Before you publish the form, you’ll need to take a look at the Submit Options from the File tab. Make sure that After submit is set to “Leave the form open.”

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

Finally, publish the form, add it to your InfoPath Form Web Part, and change the Submit Behavior setting for the web part to “Leave the form open.” Now, your form will display your custom message instead of something confusing like this:

InfoPath Designer 2010:Using Views to Add a Confirmation Screen on Form Submit

Of course, you could also use this for more complex scenarios, like creating multi-page forms. If you added conditions to your buttons’ rules, you could even display context-dependent views, displaying different forms based on data the user entered on the default page.

How to Use the List Web Service (ListData.svc) with Lookup Columns from Client Code in SharePoint 2010

Recently, I wanted to use the List web service in SharePoint 2010 to retrieve data from a SharePoint list that has lookup columns in it. There doesn't appear to be any documentation indicating that this would be a problem. The List web service is a new Windows Communication Foundation (WCF) service that provides strong-typing of list elements from client code. This helps make your code more readable and faster because nothing is being cast to and from Object for transport.


With strong typing comes Language Integrated Query (LINQ) access to the elements in the service. However, the List web service converts LINQ to CAML Queries internally and executes the request that way. CAML is a SharePoint specific language that used to be the preferred way to execute a query. The List web service is also lazy-loading, meaning that only what you request comes back from the service.


How Does This Work with Lookup Columns?


When it comes to Lookup columns, the List web service does not retrieve the values by default. So if you want that data, you have to explicitly tell the List web service to expand the requested rows to access any Lookup columns. Simply referencing the Lookup column will not work and instead generate a null reference exception. To request all lookup data, you use the "Expand" function. This extends the CAML query that runs on the back end to retrieve all data for the given column, and not just the unlinked data.


One thing to point out is that this call is not recursive. So if you have another Lookup column in your Lookup column, you'll have to explicitly Expand that data as well.


Why Does SharePoint Do This?


In my opinion, it's not just enough to know that something works a specific way, but why it works that way. The List web service doesn't provide lookup column data by default for several reasons, but they all boil down to performance. It's expensive to do what's essentially a join operation on a SharePoint list to retrieve a little more data. The CAML query gets more complicated and the amount of data returned is often much larger than what the developer needs because you get all columns from the looked-up column (except for other lookup columns). Thus you get a significant performance hit for what could be a little payoff and you're not really supposed to use SharePoint like a database to begin with.


Still, it's good to know that the List web service isn't hobbled by lookup columns, especially since they show up in IntelliSense.


Note: I jsut want to let more developer to know this knowledge. So I repost this blog from other web site, if you do not want this blog display on my blog, please send E-mail(jieiyan@gmail.com) to me.

How to Convert an Existing WCF Service to Run on SharePoint 2010

Scenario

You have this Windows Communication Foundation (WCF) service that runs on plain old vanilla Internet Information Services (IIS). Somewhere along the line, you want to convert this service to run on SharePoint. You'd like to achieve this conversion with a minimal amount of effort because you're basically inserting another layer into the stack which is essentially unneeded.

There's a lot of information out there about this topic, but most of it is about how to create a SharePoint version of the web.config and service. These all center on using some sort of Factory to spool up the service and such. While that's great and all, it's basically like rewriting your service from the ground up because you won't have a web.config and everything will have to conform to the factory framework.

There ought to be a better solution to this problem instead of writing the service again for SharePoint. Thankfully, there is.

SharePoint hosts its web services in the _vit_bin virtual directory, which maps to the ISAPI folder in the SharePoint hive (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI). Fortunately, you can map this folder in a SharePoint project and deploy your service there too! Plus, if your service is in .NET 3.5 or earlier, you don't need to change a single line of code. You just need a new .svc file and a web.config in your subdirectory within the ISAPI folder.

Note: You shouldn't be deploying directly to the ISAPI folder because you could overwrite important SharePoint services and configuration files. Instead, do like you would for a Feature and create a subdirectory.

Deploying to a subdirectory allows you to deploy your own custom web.config that won't affect anything else within SharePoint except your service and anything else hosted from the directory. It's exactly like creating a Web Application in a SharePoint deployment package.

In a future post, I'll show you how to take advantage of web.config transforms to mimic in a SharePoint project what you can do in an ASP.NET Web Application project.

Solution

There are several manual steps, but the only thing from your existing service that you need are its requisite DLLs. For my example, I'm going to have my SharePoint project be in the same solution as my WCF service, but that's not necessary. I also assume that you already have a SharePoint project set up and that your service and all of its dependent assemblies are strongly named. If they aren't, you need to do that before starting, because SharePoint won't deploy an assembly that isn't strongly named.

Mapping to the ISAPI folder:

In your SharePoint project, right click the project file and navigate to Add > SharePoint Mapped Folder…. From here, select the ISAPI folder, not any subdirectories, and click OK. This will add the ISAPI folder to your project as a mapped folder.

How to Convert an Existing WCF Service to Run on SharePoint 2010

How to Convert an Existing WCF Service to Run on SharePoint 2010

Adding Your Custom Folder:

Now that you have the ISAPI folder added, right click it and select Add > New Folder. Give the folder a name and hit <Enter>.

How to Convert an Existing WCF Service to Run on SharePoint 2010

Copy Your Web.config and .svc Files:

Now that you have the folder you need, you simply need to copy over the web.config and .svc files that you need. This should be a simple copy-paste. If you have any code behind for the .svc file, you can delete it. We'll modify the .svc file later.

How to Convert an Existing WCF Service to Run on SharePoint 2010

Add the WCF Assemblies to the SharePoint Package:

Now you need to add modify the SharePoint Package to make sure that your WCF service and its dependent assemblies are deployed to the GAC so SharePoint can see them when it tries to load your service.

To do that, double click on the Package in the SharePoint Project and select the Advanced tab at the bottom of the Package Explorer. This is where you add additional assemblies to be deployed to the GAC and marked as Safe.

How to Convert an Existing WCF Service to Run on SharePoint 2010

Once here, click the Add button and choose either Add Existing Assembly… for an assembly that isn't in the current solution or Add Assembly from Project Output… to grab an assembly from another project in the solution. Since I'm working in the same solution as my service, I'm going to choose Add Assembly from Project Output….

How to Convert an Existing WCF Service to Run on SharePoint 2010

Here you can choose the Source Project or assembly from the drop down or browse box. Once you've located your assembly, it will appear in the Location box. The next step, however, is the most important and the most often overlooked.

Adding the Assembly to the Safe Controls List:

It's one thing to have the target assembly included in the SharePoint WSP, it's another thing entirely to have it deployed as a safe control. So you'll want to click Click here to add a new item to add the Safe Control. You'll need to provide the Namespace and the strong name of the assembly, including the PublicKeyToken. Be sure to mark the control as Safe!

How to Convert an Existing WCF Service to Run on SharePoint 2010

Modify the .svc File to Reference Your Service Indirectly:

Now that your service's assemblies are in the Global Assembly Cache (GAC), you need your .svc file to reference it correctly. Open the .svc file and change the Service attribute to the concrete service class and the strong name of the assembly:

How to Convert an Existing WCF Service to Run on SharePoint 2010

Deploy and Test Your Solution:

Now you should be able to deploy and test your solution and it should function exactly like it did when it was running outside of SharePoint.

One thing to keep in mind: the authentication schemes need to match between SharePoint and your service, so if your service allows anonymous authentication, SharePoint must to or you'll get an error. SharePoint defaults to NTLM authentication only.

How to Update My Site status with Lync Personal Note in SharePoint

If you have noticed, Lync’s personal note does not sync with your “My Site” status. It would’ve been great if there was a way to set the My Site link in the Lync client and it would automatically set the status.

How to Update My Site status with Lync Personal Note in SharePoint

How to Update My Site status with Lync Personal Note in SharePoint

To accomplish the above we have to use the Lync client SDK which can be downloaded from here.

The Lync Client SDK provides a rich set of API to communicate with the Lync server. The API actually uses the Lync client’s endpoints to communicate with the Lync server. Hence, for the API to work, the Lync client needs to be running on the machine.The SDK also provides all the controls that you can see in the Lync client. E.g: Contact List, Contact search, Contact card, etc. In theory it should let you build the entire client using the SDK. (But you would need Lync client running ) The general idea here is to build a Win Forms application that just minimizes to the notification area and listens to any changes made to the Personal Note in the Lync client. Once we capture that information, it is as simple as calling a web service to update the My Site status.

Here is a rough guideline.

Step 1: Create a Win Forms application and add the following references.

  • Microsoft.Lync.Model
  • Microsoft.Lync.Utilities

How to Update My Site status with Lync Personal Note in SharePoint

Step 2: Hook into the Lync client using the SDK.

In the Load event of the form, get an instance of the Lync client and tap into the ContactInformation changed event

LyncClient lyncClient = LyncClient.GetClient();
lyncClient.Self.Contact.ContactInformationChanged += new EventHandler<ContactInformationChangedEventArgs>(Contact_ContactInformationChanged);







Step 3: In the event handler, get the value of the Personal Note and update your MySite




1:  if (lyncClient != null && lyncClient.State == ClientState.SignedIn)
2: {
3: if (e.ChangedContactInformation.Contains(ContactInformationType.PersonalNote))
4: {
5: try
6: {
7:
8: usrStatus = lyncClient.Self.Contact.GetContactInformation(ContactInformationType.PersonalNote)
9: as string;
10: //Update your My Site using web service.
11:
12: }
13: catch (LyncClientException se)
14: {
15: //Handle Exception
16: }
17: catch (SystemException systemException)
18: {
19: // Handle other exceptions.
20: }
21:
22: }
23: }








UserProfileService.UserProfileServiceSoapClient mySiteClient = new UserProfileService.UserProfileServiceSoapClient();
mySiteClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
mySiteClient.ClientCredentials.Windows.AllowNtlm = true;
var data = mySiteClient.GetUserProfileByName(Environment.UserDomainName + "\\" + Environment.UserName);
var myStatusProperty = (from d in data
where d.Name == "
SPS-StatusNotes"
select d).FirstOrDefault();
if (myStatusProperty != null && myStatusProperty.Values != null && myStatusProperty.Values.Length > 0)
{
//Check if the My Site status is different from the Lync Client
if (string.Compare(myStatusProperty.Values[0].Value.ToString(), usrStatus, true) != 0)
{
myStatusProperty.Values[0].Value = usrStatus;
isChanged = true;
}

}
else
{
myStatusProperty.Values = new UserProfileService.ValueData[1];
myStatusProperty.Values[0] = new UserProfileService.ValueData();
myStatusProperty.Values[0].Value = usrStatus;
isChanged = true;
}
if (isChanged)
{
//Update the My Site status only if the status is different from the Lync Client
myStatusProperty.IsValueChanged = true;
mySiteClient.ModifyUserPropertyByAccountName(Environment.UserDomainName + "
\\" + Environment.UserName, new UserProfileService.PropertyData[] { myStatusProperty });
}







If you are well versed with Win Forms applications, you can minimize the application to the notification so that the application is not visible to the user but the application can still display status and progress information to the user.

How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010

PowerShell is a powerful tool when combined with FAST. When dealing with a large site collection with multitudes of taxonomies and sites underneath it, promoting sites and keeping user contexts from environment to environment can be a long and taxing job, especially when you are working with the SharePoint/FAST UI. Luckily, this is where PowerShell comes in and saves your day.

User Context Properties

In SharePoint, you can create and edit user contexts through the UI. Under Site Settings –> FAST Search User Context, you will find all of your user contexts. The page to create a User Context looks like this out of the box:

How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010

Useful page, but not really right? If you want some more depth, you will have to do some digging into User Profiles. Go to Central Administration –> Service Applications –> <Your User Profile Service Application> –> Manage User Properties. Here you will find a list of user properties that are used in SharePoint, and these will be the key to making User Contexts and Site Promotions valuable and create a rich user experience for searches.

So first, let’s add a new property to the User Context. Let’s say that the User’s “Department” is an important factor in search relevancy. Therefore we want items relevant to the User’s Department to show up first in search results. To do this, we need to execute a couple PowerShell scripts.

View Current User Context Properties

First, let’s see what User Context properties are already available. If we haven’t touched them before, then we should see two of them, “SPS-Location,SPS-Responsibility”. We will be using the SharePoint PowerShell.

$properties = Get-SPEnterpriseSearchExtendedQueryProperty -SearchApplication "FASTQuery" -Identity "FASTSearchContextProperties"
$properties.Value







Where “FASTQuery” is the <Name of your FAST Query SSA>.



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010



Add User Context Property



We need to make sure that we use the Name of the User Profile Property rather than the Display Name. This is especially important if we are using custom user profile properties. Also, we will need to include the old user context properties in this script, otherwise, they will be overwritten.




Set-SPEnterpriseSearchExtendedQueryProperty -SearchApplication "FASTQuery" -Identity "FASTSearchContextProperties" -Value "SPS-Location,SPS-Responsibility,Department"







Troubleshooting: Now if you go to your UI, often you won’t see any changes (the changes will be reflected in PowerShell however)! The fastest way that I’ve seen to get these changes to show is an IIS Reset. If there is a way around this, please let us know. Therefore, type in iisreset into your PowerShell, then check the UI after it has completed. It should now look like this:



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010



Add User Contexts Using PowerShell



Now that we have some new properties to play around with, let’s add some User Contexts! In the FAST PowerShell, run the command Get-FASTSearchSearchSettingGroup. This will return the FAST Search Setting Group(s) that are on the machine. There should only be one straight out of the box. We will need the Name for the next step.



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010




$searchSettingGroup = Get-FASTSearchSearchSettingGroup -Name "69d025ce-96a7-4131-adc0-7da1603e8d24"

$context = $searchSettingGroup.Contexts.AddContext("USA Marketing")

$andExpression = $context.AddAndExpression()

$orExpression = $andExpression.AddOrExpression()

$orExpression.AddMatchExpression('SPS-Location','USA')

$orExpression.AddMatchExpression('Department','Marketing')

# Optional not Expression (remove #)
# $not = andExpression.AddNotExpression()
# $not.AddMatchExpression('SPS-Location','Japan')
# $not.AddMatchExpression('SPS-Location','Canada')







This next script will add a new User Context. The true usefulness of doing this in PowerShell is the added ability to use the “not” expression to truly filter your User Context. Besides that, why is this even useful over the UI? Mainly because it’s easily portable, and you can quickly execute your PowerShell script when it’s time to move from development to production. This is handy, especially if you have multiple User Contexts, but even more so when we begin adding Site Promotions.



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010



Add Site Promotions Using PowerShell



Handling site promotions and demotions can be a real hassle, especially when we begin dealing with an environment with many sites and sub-sites. Having PowerShell will make this process quick and portable from a development environment to a production environment.



Here, we begin talking about the use of “boosting” relevance and using Site Promotions. Here, we will be working with a promotion without using Keywords. This could be considered something closer to “scoping”, however the search will still extend beyond the scope of the sites included in the search. PowerShell allows you to choose your boost value automatically, assign multiple websites to your boost, and select the User Context(s) to include.



 




1:  # This PowerShell Script Adds Site Promotions for USA Marketing
3:
4: # Register the FASTSearch Powershell Snapin (if needed)
5: Add-PSSnapin Microsoft.FASTSearch.Powershell
6:
7: # Current Search Setting Group
8: $searchSettingGroup = Get-FASTSearchSearchSettingGroup -Name "69d025ce-96a7-4131-adc0-7da1603e8d24"
9:
0: # Type of Promotion
1: $globalPromotions = $searchSettingGroup.PromotionsWithoutKeyword
2:
3: # Promotion Name
4: $globalPromotion = $globalPromotions.AddPromotion("USA Marketing Sites")
5:
6: # Boost Value
7: $globalPromotion.BoostValue = 12000
8:
9:
0: ######### Begin Site Promotions Section #########
1:
2: $sitePromotionsToBeAdded = @(
3:
4: "http://intranet/USA/",
5: "http://intranet/marketing/",
6: "http://intranet/marketing/USA/",
7: "http://intranet/HR/Marketing",
8: "http://intranet/USA/Research/Marketing/",
9: "http://intranet/USA/Support/Marketing/"
0:
1: )
2:
3: # loop through site collection
4: foreach ($site in $sitePromotionsToBeAdded)
5: {
6: $uri = New-Object -Typename System.Uri -ArgumentList $site
7: $globalPromotion.PromotedItems.AddPromotedLocation($uri)
8: }
9:
0: # Add Site Promotion Individually (if needed)
1: # $uri = New-Object -TypeName System.Uri –ArgumentList http://intranet/USA
2: # $globalPromotion.PromotedItems.AddPromotedLocation($uri)
3:
4:
5: ########### End Site Promotions Section ##########
6:
7: # Added User Context
8: $userContexts = ({USA Marketing})
9: $globalPromotion.Contexts.AddContext($userContexts)







PowerShell is a clean method of adding Site Promotions to specific User Contexts in FAST Search. If you check under Site Settings –> FAST Search site promotion and demotion, you should see your new site promotion with its User Context(s) attached.



How to Create User Contexts, Custom User Context Properties and Site Promotions from PowerShell for SharePoint 2010



References:



 http://technet.microsoft.com/en-us/library/ff191225.aspx



http://blogs.technet.com/b/speschka/archive/2009/12/09/using-custom-properties-to-create-a-fast-search-for-sharepoint-2010-user-context.aspx

SharePoint 2010/2007 skills - to enable the document library to receive e-mail function

Business Reqirements:

The storage is one of the main features of SharePoint Document Library, you can upload many files, let the document library as a file storage. but you need to manually upload files, is there a more simple way to store files to the document library it ? This is to share the contents of this article.

Solution: Enable the function of the document to receive e-mail.

Steps:

1. Before enable the SharePoint document library to receive in the mail function, you must ensure that the current SharePoint site is already configured a mail receiving function. Open the SharePoint central manager, refer to the figure set

SharePoint 2010 skills - to enable the document library to receive e-mail function

SharePoint 2010 skills - to enable the document library to receive e-mail function

2. Enable document library to receive e-mail function. This setting is also relatively simple.

1. Select Enable Receive e-mail

2. Enter the e-mail address (can be any address)

SharePoint 2010 skills - to enable the document library to receive e-mail function

3. Select a document view, and edit, you will see more mail-related columns, you can choose whether to display the columns in the document library.

SharePoint 2010 skills - to enable the document library to receive e-mail function

4. Open Outlook, send a mail to the email address you just set (testmail@a.com)

SharePoint document libraries to receive e-mail feature is enabled, the following knowledge point document library to receive e-mail features are the advantages and disadvantages.

Advantages:

1. Described above is the most important advantage, you can store the document by e-mail.
2. Partners, external user can upload files not need accounts .

Disadvantages:

1. Because the message is basically through the firewall, so you may be to be spam.
2. Some ill-intentioned people, can upload the virus (which can prevent the type of content to stop.)
3. No permission control, anyone can upload.

You can use the EventHandler to add a unique email address for each document library

SharePoint 2010 column Validation

Abstract:

Many friends have been written many relevant aspects of the article, but I still want to record inside myselt blog.

SharePoint2010 introduct many new functions in the list level, there are managed metadata services, field uniqueness and field value Validation.

FieldUnique is very useful , but do not need too much introduction, managed meta data services will also open other article to describe, this article will focus on validation of the related content field values​​. (Now add just a few simple examples, the follow-up and a reference to new and more complex will further improve the article)

First of all be noted that there are two levels field value validation  in the SharePoint2010 , one is the field level, one is the list level, field-level validation is usually used in field inspection of the contents of their input, and a list of levels The check can be used in the comparison example, the value of two fields in such a scenario.

Field-level validation settings:

When you create a new field  and click on "Validation", note the name of Region for the field.

SharePoint 2010 column Validation

Saved if we input the value of non-China, there will be the following error message:

SharePoint 2010 column Validation

Can also have a bit more complicated scenes, such as the length of the input text to do check:

Set in the Formula = LEN ([REGION]) <8, the following results

SharePoint 2010 column Validation

Check the list of level settings:
Check the list of level set in the list settings page, check the Settings link:

SharePoint 2010 column Validation

There are two types of date fields Date1 and Date2, set the following requirements must be Date2 after Date1.

SharePoint 2010 column Validation

Interestingly, however, this error has to add a new record in the top of the screen not next to the field and (of course, next to the field if you want to put it on the field which field next to it?)

SharePoint 2010 column Validation

SharePoint 2010 column Validation

The types of supporting field validation:

Single line of text
Multiple lines of text
Digital
Currency
Date

Field Types

In this simple example we used a "Single Line of Text" field type. The following field types can be validated with the "Column Validation" feature:

  • Single Line of Text
  • Choice (single only)
  • Number
  • Currency
  • Date & Time

Formulas

  1. You can only compare column values to one another in a list level validation.
  2. A validation formula at the column level cannot include any other columns besides itself. For example, [Column1]>[Column2] is an invalid formula and SharePoint will not allow it to be used at the column level. In this case, you want to use list-level validation.
  3. There is only one formula available at the list level.
  4. The formula syntax is similar to that used in Calculated Columns

There are a few dozen functions available - I have not tried every one. One interesting thing to note is that SharePoint 2010 would not allow me to use the TODAY function, even when validating a Date field. [DateColumn]>TODAY is not a valid validation formula.

Conflicts

  1. What if you have both column level validation and list level validation?
    1. The column level formulas will be evaluated first, then the list formulas
  1. What if the column and list level validations are in conflict?
    1. Example - at the list level, you require that [Text1] = [Text2], but each column has it's own validation; [Text1]="AAA", and [Text2]="BBB". In this case, it will be impossible to actually submit a list item. The column validations are evaluated first, but if the values validate here, they will of course fail the list validation.
  1. What if the list level validation includes columns not included in a particular content type?
    1. If a column used in the list formula isn't available in the current content type, validation will always fail. This means that if you have multiple content types in your list, you should not validate at the list level for a column that is not included in all content types on the list. These columns can only be validated at the column level.

Site Columns

  1. You can set validation on custom columns of the field types listed above
  2. You can override the validation of a site column at the list level

Items To Investigate

  1. How does validation behave with page fields in a Pages library on a publishing site?
  2. How does validation behave in Office client applications?
  3. Is validation available in the Site Directory? Does it work at site creation time?
  4. Can we use regular expressions in a validation formula?

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

Abstract:

SharePoint2010 introduced a new document library feature "Unique Document ID" (This feature is only available in the Standard Edition and Enterprise Edition provides), in the context of the site can be set according to certain rules consistent unified management of the document ID, and provides independent Document is a document storage location of the unified access interface. This feature is good, but in the actual configuration of the process will encounter some minor problems.

To use this feature, first set of features on the site and activate the "Document ID service " functions:

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

After the set of active management into the page in the site will be one more link "Document ID Settings ", click enter:

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

On this page you can specify the document unique number in the starting number, click "OK" button, and noticed the top right corner there is a reminder: "Configuration of the Document ID feature is scheduled to be completed by an automated process", the prompt The meaning is very clear, this setting is to have an effect through the Timer Job, so the change will not take effect immediately.

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

Unfortunately, the service associated with the two Timer Job default is set to run once a day, if configured, is likely to have to wait until after the next day to see results, but we can go to the management center to manually run the two Job. Into SharePont management center -> Monitoring-> Review Job definitions, see the following two Job.

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

In accordance with the "Document ID enable / disable job", "Document ID assignment job" in order to manually run the two Jobs, just click inside the SharePoint2010 enter the relevant Job Title into the page, click on the "immediate execution"button:

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

After ensure the two Job are executed then returned to the appropriate site collection, into a document library, upload documents in the default view will find more of the DocumentID column, which is stored in the rules specified in the document consistent with our ID.

How to configuration the Unique Document ID Service to make it Immediatly effect in Sharepoint 2010

The mouse into the document ID, we can find click on the ID will open the file in a new window (which opens in IE or in the client program to open under IE there are different settings and different SharePoint), indicating that URL is http://localhost /_layouts/DocIdRedir.aspx? ID = 3HVABCD-1-2, provides a unified method of access ID.