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
}

Saturday, January 1, 2011

HTTP Request to get the data from the sharepoint list using jQuery.

HTTP Request to get the data from the sharepoint list using javascript/jQuery.

Create a aspx page and place under the layouts folder and name it getcommentsfromlist.aspx

Add following code on OnLoad Method
public void OnLoad()
{
SPSite site = new SPSite(Request.QueryString["URL"]); //Site URL
SPWeb web = site.OpenWeb();

SPList list = web.Lists["Comments"]; //List in which Comments will be stored
String qPageId = Request.QueryString["PageID"]; //Page ID

SPQuery query = new SPQuery();
query.Query = "" + qPageId.ToString() + "";
SPListItemCollection itemsReturnedFromQuery = list.GetItems(query);


int totalPages;

query = new SPQuery();
query.Query = "" + qPageId.ToString() + "";


foreach (SPListItem item in itemsReturnedFromQuery)
{

retData += "Author : " + item["Author"].ToString() + "Date : " + item["Created"].ToString() + "Author : " + item["Comment"].ToString()
}


RenderHtmlControls(retData);
}


protected void RenderHtmlControls(string html)
{
Response.Write(html.ToString());
Response.End();//can be removed if you want to get the other static data which sharepoint places on the page
}


We can call the above aspx page using following JQuery code to get the data

var htmlData = $.ajax({
url: "/_layouts/getcommentsfromlist.aspx?URL=" + sCommentsURL + "&PageID=" + hwPageID,
async: false
}).responseText;

Wednesday, December 29, 2010

Profile Image of user in Sharepoint

Function to get User profile image in Sharepoint.


public string userInfo(SPUser pUser, SPSite pSite)
{
ServerContext context = ServerContext.GetContext(pSite);
UserProfileManager profileManager = new UserProfileManager(context);

UserProfile profile_User = profileManager.GetUserProfile(pUser.LoginName);
UserProfileValueCollection values = profile_User[PropertyConstants.PictureUrl];
String urlImage = "";
if (values.Count > 0)
{
SPFieldUrlValue urlValue = new SPFieldUrlValue(values.Value.ToString());
urlImage = urlValue.Url;
}
return urlImage;
}