Sunday, February 26, 2012

Register new managed account local user

When tried to register local account user I faced the following error:
The specified user 'accountname' is a local account. Local accounts should only be used in stand alone mode.
I found solution using powershell:
type $cred = Get-Credential
When prompted enter an account and password (here you can type in a local account)
type New-SPManagedAccount -Credential $cred
After finished the account is added.

Wednesday, February 8, 2012

Creating a FAST Search Scope

When you try to create scope in Fast Search Search 2010. This will not work only way to create scope in SharePoint Search using PowerShell. Command Below is sample of command for creating scope:

New-SPEnterpriseSearchQueryScope -SearchApplication "FAST Query Application" -Name "NewScope" -Description "This is my new scope" -DisplayInAdminUI 1 -ExtendedSearchFilter 'path:starts-with("http://myserver/mysitecoll")'

The ExtendedSearchFilter parameter specifies a FAST Query Language (FQL) expression that will filter the content for that scope.

There is 2 good blogs talk about Fast Search scope:
http://blogs.msdn.com/b/jorgeni/archive/2010/02/26/search-scopes-in-fast-search-for-sharepoint-part-1.aspx

http://blogs.msdn.com/b/jorgeni/archive/2010/03/11/search-scopes-in-fast-search-for-sharepoint-part-2.aspx

Sunday, January 29, 2012

Sharepoint Designer “checked out” problem

Sometimes in Sharepoint Designer showing “checked out” even though they were not!

To solve this problem, You need to clear a local web cache. This Works in SharePoint Designer 2007 and SharePoint Designer 2010.

Areas to clear:
  • %APPDATA%\Microsoft\Web Server Extensions\Cache
  • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\
In WInXP
  • %USERPROFILE%\Local Settings\Application Data\Microsoft\WebsiteCache

Capatcha using Javascript

Most of the websites use the technique of captcha for validation / verification purpose whenever someone tries accomplish membership or want to submit a piece of information. The generation of captcha can be done in various ways. We can use server side scripting or even we can use client side scripting.
I am need to host SharePoint 2010 in shared environment and does not allow me to deploy server side control. Then tha best way to use captcha is javascript.

Here is a sample code of capatcha using javascript:

<html>
<head>
<title>Captcha</title>

<script type="text/javascript">

//Created / Generates the captcha function
function DrawCaptcha()
{
var a = Math.ceil(Math.random() * 10)+ '';
var b = Math.ceil(Math.random() * 10)+ '';
var c = Math.ceil(Math.random() * 10)+ '';
var d = Math.ceil(Math.random() * 10)+ '';
var e = Math.ceil(Math.random() * 10)+ '';
var f = Math.ceil(Math.random() * 10)+ '';
var g = Math.ceil(Math.random() * 10)+ '';
var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
document.getElementById("txtCaptcha").value = code
}

// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2) return true;
return false;

}

// Remove the spaces from the entered and generated code
function removeSpaces(string)
{
return string.split(' ').join('');
}


</script>



</head>
<body onload="DrawCaptcha();">
<table>
<tr>
<td>
Welcome To Captcha<br />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtCaptcha"
style="background-image:url(1.jpg); text-align:center; border:none;
font-weight:bold; font-family:Modern" />
<input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtInput"/>
</td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/>
</td>
</tr>
</table>
</body>
</html>

This is simple but you can complicate it to eliminate cracking.

SharePoint Designer 2010 Workflow does not Start Automatically, when an item is created or modified

I Create a new "List Workflow" through Sharepoint Designer 2010 and set the workflow setting with Start workflow automatically when an item is create or modified.




Then save and publish the workflow. Now goto the list and create or edit the items, the attached workflow not invoke.

I found my problem . I need to login into another non system account user.


Saturday, January 28, 2012

How to Remove {generate-id()} from a Customized Form in SharePoint

If you wrote xslt in SharePoint Designer html tag with id it automatically adds {generate-id()}

example


when it saved in SharePoint designer it will be:


There is many articles take about solution for this:
http://sympmarc.com/2007/10/12/how-to-remove-generate-id-from-a-customized-form-in-sharepoint/

But I see it is very useful to make id of any element unique prevent conflict of elements between different webparts.


Thursday, January 26, 2012

Use email in SharePoint 2010 Sandbox

In SharePoint 2010 Sandbox. In Sandbox Microsoft.SharePoint.Utilitiesis not avaliable. When tried to use System.Net.Mail methods available to us. SmtpClient constructor give me error.
I found another way using SharePoint Designer workflow. You can trigger a workflow to run programmatically and also supply information to the workflow and set the initiation values. Here's the code to start a workflow:


///
/// Method to handle starting the appropriate Workflow as specified by the Site Collection Workflow Name property
///

private void StartWorkflow()
{
SPWorkflowAssociation wfa = SPContext.Current.Web.WorkflowAssociations.GetAssociationByName(this.SiteCollectionWorkflowName, CultureInfo.InvariantCulture);
wfa.AssociationData = this.GetWorkflowInitiationData();
SPContext.Current.Site.WorkflowManager.StartWorkflow(null, wfa, this.GetWorkflowInitiationData(), SPWorkflowRunOptions.Asynchronous);
}


///
/// Method to construct the Workflow Initiation/Association Data
///

/// A string containing the XML schema and values necessary for the Association Data
private String GetWorkflowInitiationData()
{
String schema = "http://www.w3.org/2001/XMLSchema\" " +
"xmlns:dms=\"http://schemas.microsoft.com/office/2009/documentManagement/types\" " +
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" " +
"xmlns:q=\"http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields\" " +
"xmlns:d=\"http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields\" " +
"xmlns:ma=\"http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes\" " +
"xmlns:pc=\"http://schemas.microsoft.com/office/infopath/2007/PartnerControls\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"{0}" +
"
";



StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}", this.SendToEmailAddress);
sb.AppendFormat("{0}", this._subject.Text);
sb.AppendFormat("{0}", this._comments.Text);
sb.AppendFormat("{0}", this._email.Text);
sb.AppendFormat("{0}", this.AutoResponseSubject);
sb.AppendFormat("{0}", this.AutoResponseText);
return String.Format(schema, sb.ToString());
}