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;
}
Tuesday, January 25, 2011
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.
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
}
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;
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 = "
SPListItemCollection itemsReturnedFromQuery = list.GetItems(query);
int totalPages;
query = new SPQuery();
query.Query = "
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;
Subscribe to:
Posts (Atom)