Within a SharePoint farm, one will typically have a server that performs the index function of the farm in order to manage crawling of searchable content and create an index file. I was always under the impression that this Index server performs all of the crawling for the crawlable entities, but recently discovered this is not the case. The Index server manages the crawl of all content, performs the crawls for items external to the SharePoint farm, but makes requests to the available Query or Search servers in order to crawl the internal content of the SharePoint farm. The Query servers in turn, return the results to the Index server to add to the index file itself which is then passed along to the Query servers again.
Since crawl operations can potentially cause performance impacts to your SharePoint environment, Microsoft has recommended as a best practice, having a dedicated query server available to crawl data. This query server should not be part of the potentially load-balanced front-end servers that actually serve up the web pages to end-users and should only be responsible for crawling the SharePoint content internal to the SharePoint farm.
Now, some of you probably are thinking this seems like overkill to add another server to your farm merely for crawling, and in many scenarios it probably is. Microsoft has recommended that crawling of content less than 500 GB (keep in mind this is data internal to your SharePoint farm) of data will not result in any performance-related issues without having a dedicated Query server to perform crawls. Once your site has approached this level however, you may want to look into the potential for creating a dedicated Query server to crawl your content. Including the Indexing capabilities onto this dedicated Query server to perform crawls will help alleviate some potential performance issues as well by not having to pass the crawled data across your network. Your index server will still have to pass the index file and incremental files to all of the Query / Search servers, but you'll at least eliminate some network chattiness by throwing the Index server on the same box as the crawl-dedicated Query server.
2011/02/20
Understanding the sharepoint index server and crawling of data
2010/01/02
To hide unApproved content in query
as the following.
query.ViewAttributes = "Scope='Recursive' ModerationType='HideUnapproved'";
2009/12/30
Problem of postBack in sharepoint
Try to add this code to onClienClick event of the button to enable sharepoint post back event as the following
ButtonName.OnClientClick = "_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;";
my post on the following URL
2009/11/04
Changing machine name Problem in sharepoint
So, you can do it as the following.
1- change the machine name from computer settings to the name you want.
2- open RUN
3- goto the destination of stsadm (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN)
4- Now you can run the following command line
stsadm -o renameserver -oldservername
5- The last step is to open centeral administration and change the servername from the URL to (localhost). goto to Operation Tab, choose alternative mapping access and change the machine name at all mapping URLs to your new one.
2009/09/24
CAML Query that filters on the current user
CAML Queries are troublesome at the best of times. I find it best to use a tool or a tried and tested method like the one I use here Tip - Creating CAML Queries - Thinking out aloud - Dave Hunter's.
When you create a view and you want to show only items that have been created by the current user you use the [Me] keyword.
For example: filter by "Author" equals [Me].
How can I do this using a CAML query?
The [Me] keyword is represented in CAML by the following <Value Type="Integer"><UserID Type="Integer"/></Value>.
In the CAML query for returning items that the current user has created becomes ...
<Where><Eq><FieldRef Name='Author' /><Value Type="Integer"><UserID Type="Integer"/></Value></Eq></Where>
Mirjam has done a good job of writing this up http://www.sharepointblogs.com/mirjam/archive/2009/07/16/creating-a-custom-view-that-filters-on-the-current-user-or-me.aspx. Glad I could help.
2009/08/18
SharePoint - using the rich text box in a custom user control
but no, it's not (as i found out)...so how do you use that shiny nice Rich Text Box control in a custom web part or user control.
![]()
simple - so simple i'm sad to say it took me 1 1/2hrs discussing it with some like-minded fellows before we found out what it was (sad i know, but we got there in the end).
Add this to your ascx (if you're using a web user control):
1: <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
and here comes the simple bit..
1:
That's it...not that impressive but that's what you have to do..simple eh :)
Note: this is only available in MOSS 2007.
2009/08/11
OutOfMemory Exception
But when I used EventHandler it gives me exception "OutOfMemory exception" while my code was as the following:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb web = SPControl.GetContextWeb(Context);
web.AllowUnsafeUpdates =true;
SPListItem item = web.Lists["MyList"].Items.Add();
item["RequestedName"] = textBoxName.Text;
item["DateRequestRecievd"] = DateTime.Now;
item["RequestedPhoneNo"] = textBoxMobileNo.Text;
item["RequestType"] = dropDownListRequestType.SelectedItem.Value;
item["RequestSubject"] = textBoxRequestSubject.Text;
item["state"] = textBoxState.Text;
item["IdentityNo"] = textBoxIdentityNo.Text;
item.Update();
web.AllowUnsafeUpdates =false;
});
I used that code because I know that "SPSecurity.RunWithElevatedPrivileges" imporsenates the current user permissions with "system Account" Permissions. But it doesn't work with Anonymouse users.
There the solution of this Issue Anonymouse doesn't have permission to access assembly. So, you need to Authonticate as an authonticated user. I created a user that will be used for imporsenation, "Domain\Visitors". I wrote the following code
1 SPSecurity.RunWithElevatedPrivileges(delegate()
2 {
3 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
4 {
5
6 using (SPWeb parentWeb = site.OpenWeb())
7 {
8 string userName = ConfigurationManager.AppSettings["contactUsUser"];
9 SPUser user = parentWeb.AllUsers[userName];
10 ////YOU CAN ALSO HARD CODE THE USER AS BELOW
11 //SPUser user = parentWeb.AllUsers["DOMAIN\\Vistors"];
12 SPUserToken token = user.UserToken;
13
14 using (SPSite s = new SPSite(SPContext.Current.Site.Url, token))
15 {
16 using (SPWeb web = s.RootWeb)
17 {
18 //MY LOGIC HERE
19 }
20 }
21
22 }
23
24 }
25 });
you can see my post on MSDN Forum
2009/06/23
Using Javascript to access a List Form Field in SharePoint Designer
An article was posted showing how to access and manipulate a List Form Field within SharePoint Designer using Javascript over at Microsoft SharePoint Designer Team Blog. The code in the article supported the following types of SharePoint 2007 form fields, but not the Radio Buttons Choice field:
Single Line of Text
Multiple Lines of Text
Number
Currency
Choice (dropdown)
Lookup (single)
Lookup (multiple)
Yes/No
So I’ve modified the function getTagFromIdentifierAndTitle and added onto it the code to allow accessing Radio Buttons Choice fields. The following is the modified function:
/*******
SharePoint Field Type identifier tagName Option
--------------------- -------------- --------- ---------
Single Line of Text TextField input
Multiple Lines of Text TextArea input
Number TextField input
Currency TextField input
Choice (radio buttons) RadioButtons input
Choice (radio buttons) RadioButtons input value
Choice (dropdown) DropDownChoice select
Lookup (single)* Lookup select
Lookup (multiple) SelectCandidate;
SelectResult select
Yes/No BooleanField input
******/
function getTagFromIdentifierAndTitle(tagName, identifier, title, option) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var idString = tags[i].id;
var nameString = tags[i].name;
// get selected radio button value only
if (option == "value" && tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
var radioButtons = document.getElementsByName(nameString);
var radioValue = "";
for (var x=0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
radioValue = radioButtons[x].parentElement.title;
break;
}
}
var o = document.createElement("INPUT");
o.type = "hidden";
o.value = radioValue;
return o;
}
}
// get radio buttons group
if (tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
return document.getElementsByName(nameString);
}
}
// all other input or select type
else if (tags[i].title == title && (identifier == "" idString.indexOf(identifier) == idString.length - len)) {
return tags[i];
}
}
return null;
}
Here is how you would use the function above for Radio Buttons:
// to get the selected radio button and its value
var myRadioButtonsSelected = getTagFromIdentifierAndTitle("input","RadioButtons","MyFieldName","value");
var myRadioButtonsValue = myRadioButtonsSelected.value;
// to get the array for radio buttons
var myRadioButtonsArray = getTagFromIdentifierAndTitle("input","RadioButtons","MyFieldName");
for (var x=0; x < myRadioButtonsArray.length; x++) {
// do whatever you like here...
// for example:
myRadioButtonsArray[x].parentElement.onclick = function(){alert(myRadioButtonsArray[x].value);};
}
The original post can be found here: Using Javascript to Manipulate a List Form Field
For a basic function, you could also check out Boris Gomiunik’s Blog for another post about referencing SharePoint form fields using Javascript.
compare dates in sharepoint using JavaScript
you can use the current code to check the differance between dates before saving data using JavaScript code.
The following code I used to use it in case of check dates I hope it will be useful.
function PreSaveAction()
{
var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Letter Date");
var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Decision Date");
var date3 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Request Date");
var arrDate1 = date1.value.split("/");
var useDate1 = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0]);
var arrDate2 = date2.value.split("/");
var useDate2 = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0]);
var arrDate3 = date3.value.split("/");
var useDate3 = new Date(arrDate3[2], arrDate3[1]-1, arrDate3[0]);
if(useDate1 >= useDate2)
{
alert("Letter date must be before Decision Date");
return false; // Cancel the item save process
}
else if(useDate2 >= useDate3)
{
alert("Decision Date must be before Request Date");
return false; // Cancel the item save process
}
else
{
return true; // OK to proceed with the save item
}
}
//getTagFromIdentifierAndTitle function
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++ )
{var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
{
return tags[i];
}
}
return null;
}
2009/06/03
WPSC undefined JavaScript error.
While using Forms Authontication I met the following JS error "WPSC" object isnot defiend, and I added the following code then this error disappeared.
<script type="text/javascript">
if(typeof(WPSC) == "undefined"){
WPSC = new Object();
WPSC.Init = function(){
//do nothing
}
WPSC.WebPartPage = new Object();
WPSC.WebPartPage.Parts = new Object();
WPSC.WebPartPage.Parts.Register = function()
{
//do nothing
}
}
</script>
2009/04/27
CAML query with Person or People and Groups column in Sharepoint 2007 (using in Event Handlers)
I was facing an issue with my simple CAML query where I was trying to filter the Field inside Sharepoint List and supplying value from the properties.AfterProperties of List Item event handler. This field was of Person or to say People and Groups kind of field. Internally inside sharepoint this value is stored as USERID and not as the display name. So I was using a simple CAML builder to build my query and it looked like:
oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' />" +
"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" + "</Eq>" +
"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" + properties.AfterProperties["Year"].ToString() +
"</Value> </Eq></And></Where>";
And this never worked for me, then one of my colleagues Madhur Ahuja helped me crack this it was a simple Lookup attribute that was missing, so basically the query should have been:
oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' LookupId= 'TRUE' />" +
"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" +
"</Eq>" +
"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" +
properties.AfterProperties["Year"].ToString() +
"</Value> </Eq></And></Where>";
And this never worked for me, so bottom line if you use People and Groups kind of column in Filters always make sure that you use LookupId ='TRUE' attribute in Filters
2009/04/15
SharePoint Security Access Check Codeplex
A colleague of mine just pointed me to this interesting tool ...
http://www.codeplex.com/AccessChecker
Quickly check what objects within a Sharepoint site hierarchy a user has access to. The Access Checker Web Part is a Windows Sharepoint Services Web Part, for use within Windows Sharepoint Services v3 and Microsoft Office Sharepoint Server 2007, that displays a tree view showing permissions on objects for a user scoped to a Site hierarchy. It also has a second mode which will show the permission inheritance of objects within a Site hierarchy.
2009/03/20
How to Uninstall Microsoft SQL Server 2005 Embedded Edition (SSEE Instance)
you need to uninstall Microsoft SQL Server 2005 Embedded Edition (SSEE Instance) while uninstalling windows sharepoint services.
Simply execute the following command in a windows console :
(on 32-bit platforms)
msiexec /x {CEB5780F-1A70-44A9-850F-DE6C4F6AA8FB} callerid=ocsetup.exe
(on 64-bit platforms)
msiexec /x {BDD79957-5801-4A2D-B09E-852E7FA64D01} callerid=ocsetup.exe
2009/03/10
Add previlages to user to do some actions in WSS 3.0 / MOSS 2007
We can use this method for dealing with users that has low previlages over specific List.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPListItem NewUser = NewUsersList.Items.Add();
NewUser["Username"] = _userNameTextBox.Text.Trim();
NewUser["Password"] = _passwordTextBox.Text.Trim();
NewUser["First Name"] = _firstNameTextBox.Text.Trim();
NewUser["Last Name"] = _lastNameTextBox.Text.Trim();
NewUser["Phone"] = _phoneTextBox.Text.Trim();
Site.AllowUnsafeUpdates = true;
NewUser.Update();
}
);
WSS 3.0 Allow Unsafe Updates
you can use the following property in custom WebPart:
Web.AllowUnsafeUpdates = true;
{ Your Code here }
Web.AllowUnsafeUpdates = false;
this property can be used with anonymous or user with low permissions.
2009/03/03
Map of Reusable SharePoint JavaScript
version: WSS 3.0
source file: init.js (ln 1621)
mapped by: Itay Shakury
purpose: provides method to parse query string, filename, and pathname from URL
example:
JSRequest.EnsureSetup();
var qs = JSRequest.QueryString[value];
var fn = JSRequest.FileName;
var pt = JSRequest.PathName;
PreSaveAction()
version: WSS 3.0
source file: n/a (ref: form.js ln 5909)
mapped by: Edin Kapic
purpose: provides hook for creating custom function interrupting submit action
example:
function PreSaveAction(){
var input = getTagFromIdentifierAndTitle("textarea","","Test");
if(input && input.value == "") {
alert("You must complete Test");
return false; // Cancel the item save process
}
return true; // OK to proceed with the save item
}
_spBodyOnLoadFunctionNames
version: WSS 3.0
source file: n/a
mapped by: Sanjay Arora
purpose: Allows you to register additional JavaScript methods that should run in the PageLoad event
example:
_spBodyOnLoadFunctionNames.Push('MyCustomFunctionName');
GetFirstChildElement(e)
version: WSS 3.0
source file: core.js
mapped by: Christophe
purpose: get the first "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetLastChildElement(e)
version: WSS 3.0
source file: core.js
mapped by: Christophe
purpose: get the last "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.
GetCBSelectedValues(frm)
version: WSS 3.0
source file: core.js (ln 972)
mapped by: Paul Grenier
purpose: Accepts a form object, loops through all check box elements and returns the values of the checked boxes or false if none are checked.
example:
html
<input id="spUserSelCb_1131" type="checkbox" title="Paul Grenier" onclick="UserSelectionOnClick(this,'1');" value="131" name="spUserSelectionCheckBox_1"/>
JavaScript
var elm = document.getElementsByTagName("form")[0];
GetCBSelectedValues(elm)
Object returned: strList = "131,144,143,7,254,22..."
GetSelectedValue (frmElem)
version: WSS 3.0
source file: init.js (ln 1516)
mapped by: Paul Grenier
purpose: takes a form element with a selectedIndex and returns the selected value or an empty string.
GetSelectedText(frmElem)
version: WSS 3.0
source file: init.js (ln 1523)
mapped by: Paul Grenier
purpose: takes a form element with a selectedIndex and returns the selected text or an empty string.
escapeProperly(str)
version: WSS 3.0
source file: init.js (ln 168)
mapped by: Paul Grenier
purpose: takes any string and returns a URL-encoded string.
example:
escapeProperly("this is a test")
"this%20is%20a%20test"
unescapeProperly(str)
version: WSS 3.0
source file: init.js (ln 855)
mapped by: Paul Grenier
purpose: takes any URL-encoded string and returns a string.
example:
unescapeProperly("this%20is%20a%20test")
"this is a test"
refrance : http://sharepointdevwiki.com/display/public/SharePoint+JavaScript+Functions+Overview
2009/03/02
Hide fields in NewForm.aspx without customization
You can use the following techniqe to hide flags that you add in custom list or document library without customization you can add the following code after the ContentPlaceHolder tage
<asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>
The script as the following:
<script language="javascript" type="text/javascript">
// set the function that will load in the page call.
_spBodyOnLoadFunctionNames.push("hideFields");
//the function that will search for control
function findacontrol(FieldName) {
var arr = document.getElementsByTagName("!");
// get all comments
for (var i=0;i < arr.length; i++ )
{
// now match the field name
if (arr[i].innerHTML.indexOf(FieldName) > 0)
{ return arr[i]; }
}
}
// this function wil hide the controls by field Name
function hideFields()
{
var control = findacontrol("Hired");
control.parentNode.parentNode.style.display="none";
control = findacontrol("inServe");
control.parentNode.parentNode.style.display="none";
control = findacontrol("Title");
control.parentNode.parentNode.style.display="none";
}
</script>
you can change the Green text with your controls name that you need to hide
2009/02/14
Get SelectedValue from sharepoint lookup Field
<SharePoint:FormField runat="server" id="ff30{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0628__x0646__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff30',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0628__x0646__x06')}" />
<SharePoint:FieldDescription runat="server" id="ff30description{$Pos}" FieldName="_x0627__x0644__x0628__x0646__x06" ControlMode="New"/>
To get the selectedvalue from sharepoint lookup field you follow these steps.first you need to assign event onchange to this field.
<script type="text/javascript" language="javascript">
//Select the method that will run at the sharepoint page body load_spBodyOnLoadFunctionNames.push('setEvent');
//set event function
function setEvent()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');//eventName and method that will call
selectBank.setAttribute('onchange',checkBank);
}//function will call when event is fired
function checkBank()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');
var selectedValue=selectBank.options[selectBank.selectedIndex].value;
alert(selectedValue)}
</script>
2009/02/08
Getting Vlaue of UserField In Sharepoint using JavaScript
If you need to get the value of userFiled control using javascript.<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0631__x0642__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0631__x0642__x06')}"/>
<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="_x0627__x0644__x0631__x0642__x06" ControlMode="New"/>
you can search for this ID in viewsource you can find many controls one of these controls is Span it's ID will be in my case
"ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField"
you can use the following code to preview the value of the control
<script type="text/javascript" language="javascript">
function CheckUser()
{
var selectedUser= document.getElementById('ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField').innerText; alert(selectedUser); return false;
}
</script>
This control contains the value of this field
It will breview the following value
then you can use this value in filteration or any other Issue
2009/02/07
SharePoint Built-in JS Functions
//Get Current User ID
_spUserIdex:
alert(_spUserId);
//Run JS Function on Page Load
_spBodyOnLoadFunctionNames.push(' FunctionName ');
//First we must call the EnsureSetup method
JSRequest.EnsureSetup();
//Get a query string parameter called ItemId. i.e - "page.aspx?ItemId=11" will return 11
itemId = JSRequest.QueryString["ItemId"];
//Get the current page name. i.e - "default.aspx"
itemId = JSRequest.FileName;
//Get the current path name. i.e - "/doclib/default.aspx"
itemId = JSRequest.PathName;

