Monday, July 25, 2011

FullTextSqlQuery Search Queries with URL

Recently I was working with Full Text SQL Search Queries and found a strange issue while filtering with the URL in the query. If the URL contains special characters its giving me the exception improper query.

My Old Query was
SELECT ArticleDate, URL FROM SCOPE()
WHERE CONTAINS(URL, 'http://mritunjay.com/sites/the site/docs/URLTest @/')

after few encoding I tried to embed the URL in the " I was able to get the correct output

SELECT ArticleDate, URLFROM SCOPE()
WHERE CONTAINS(URL, '"http://mritunjay.com/sites/the site/docs/URLTest !@$/"')

Wednesday, June 29, 2011

Windows Process Activation Service(WAS) stopped

Application pools cannot be started unless the windows Process Activation Service(WAS) is running

this error happens because of following reasons
1. Drive is out of space.
2. Folders deleted from the Inetpub : there is a great article by Scott which explains in details how to resolve. click here

Wednesday, June 22, 2011

List Throttling

List Throttling is a new feature in SharePoint 2010, it allows us to set the limit of how many rows of data can be retrieved from a list at a time. By default the list throttles to 5000 items. Let’s consider we have a list with 50000 entries and a user comes and creates a view with all the entries, then the SharePoint will return either error or the first set of results up to the number put in the list throttle.
The throttle can be set on the lookups in a list, and we can limit the lookup columns. If we have too many lookups the performance will suffer. As we limit maximum throttle for the user, we can override the same on the Object Model if we have the sufficient privilege.

using (SPSite site = new SPSite("http://mysite"))
{
using (SPWeb web = site.RootWeb)
{
try
{
SPList list = web.Lists["Shared Documents"];

SPQuery qry = new SPQuery();
qry.QueryThrottleMode = SPQueryThrottleOption.Override;

SPListItemCollection coll = list.GetItems(qry);
}
catch(SPQueryThrottledException)
{
// Throttle exception
}
}
}

Wednesday, April 6, 2011

Passing filter to View from Querystring

To pass the filter to the share point list view we can use FilterField1 and FilterValue1

FieldFilter : Column Name
FilterValue : Value of the Field

Sample
URL?FilterField1=Title&FilterValue1=Mritunjay

we can add more than one filters by just adding the FilterField2 and FilterValue3 in the querystring.

Tuesday, January 25, 2011

Adding Dropdown to Sharepoint Webpart Properties

Adding Dropdown to Sharepoint Webpart Properties

Create a Webpart and add custopm property
[WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]
public string SearchPath
{
get { return _searchPath; }
set { _searchPath = value; }
}


Create a class and extend it from ToolPart

protected override void CreateChildControls()
{
webpart = this.WebPartToEdit as WebpartClass;
toolPanel = new Panel();
toolPanel.CssClass = "ms-ToolPartSpacing";
toolPanel.Controls.Add(GetToolPanel());
this.Controls.Add(toolPanel);
base.CreateChildControls();
}

public override void ApplyChanges()
{
webpart = this.WebPartToEdit as WebpartClass;
webpart.SearchPath = ddl.SelectedValue;
base.ApplyChanges();
}


Other functions in the extended class of ToolPart
private Control GetToolPanel()
{
toolPanelTable = new Table();
toolPanelTable.CellPadding = 0;
toolPanelTable.CellSpacing = 0;
toolPanelTable.Style["border-collapse"] = "collapse";
toolPanelTable.Attributes.Add("width", "100%");
toolPanelTable.Rows.Add(GetUseDropDown());
toolPanelTable.Rows.Add(GetSeperatorRow());
return toolPanelTable;
}
private TableRow GetUseDropDown()
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl("<div ><b>DropDownName</b></div>"));
cell.Controls.Add(new LiteralControl("<div ><div <nobr>"));
ddl = RecursiveParse(); //return the Dropdown List
cell.Controls.Add(ddl);
cell.Controls.Add(new LiteralControl("</nobr></div></div>"));
row.Cells.Add(cell);
return row;
}

private TableRow GetSeperatorRow()
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl("<div style='width:100%' ></div>"));
row.Cells.Add(cell);
return row;
}

Friday, January 21, 2011

Create a Custom View for Survey List

Work around to create Views for survey


1. Go to Settings of the Survey. And copy the List ID from URL
Example : ListID=%7BF2141E9F%2D8EA2%2D42EE%2DA965%2D52F1D7362066%7D
2. Open the View creation Page of sameSite
Example : http://SiteURL/_layouts/ViewType.aspx?List=ListID&Source=SurveyListURL
3. Then choose a view as we choose for other lists
4. Type Custom View Name.
5. Expand style tab, choose a style Basic Table
6. press OK and view is ready.

Friday, January 14, 2011

Sharepoint Search using Metadata Properties

Sharepoint Search using Metadata Properties

Creation of Metadata Property
1. Go to Shareod Services
2. Open Metadata Property mapping
3. Click on the New Managed Property
4. Fill in the details and add to Crawled Properties
5. Make sure to wait till the next crawl completes

Search Component

FullTextSqlQuery kwQuery = new FullTextSqlQuery(siteObject);
StringBuilder queryText = new StringBuilder();
queryText.Append("SELECT Title, ArticleDetails, URL "); //ArticleDetails is managed Property
queryText.Append("FROM SCOPE() WHERE ");
queryText.Append(" CONTAINS(URL , 'NEWS') AND NOT CONTAINS(URL , 'Forms') AND ");
queryText.Append(" \"scope\" = 'IntranetRelatedArticle' AND ");
queryText.Append("( FREETEXT(DEFAULTPROPERTIES, 'Mritunjay Chourasia')");
queryText.Append(" ORDER BY Rank Desc");

kwQuery.RowLimit = 5;
kwQuery.QueryText = queryText.ToString();
kwQuery.ResultTypes = ResultType.RelevantResults;
ResultTableCollection results = kwQuery.Execute();
ResultTable relevantResults = results[ResultType.RelevantResults];
while (relevantResults.Read())
{
//Search Data computation
}