Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Sharepoint 2010 Serach video tutorial

Posting here some tutorial Videos for better understanding of SharePoint 2010 Enterprise Search.

Introduction to Enterprise and Fast Search in SharePoint 2010 - This is basic tutorial about Enterprise and Fast Search in SharePoint 2010. In this video you will learn basics of enterprise search, how search management fits within their organizations and lot more. See the Video at the below link
Basics of Enterprise Search

Configuring UI for Search in SharePoint Server 2010 and FAST Search Server 2010 for SharePoint - This is video you will be introduced to basic search components like search page,advanced search page, search results page, Search webparts. See the video below
Introduction to Search UI

Create\Configure Search Pages - I this video you will learn how to create a search site, configure a basic and advanced search page. See the video at the below link :
Basic and advanced Search Pages

Configure Search Results Pages\webpart -
In this video you will learn about layout of the search results page, search core result webpart, statistics webpart, paging webpart etc. See the video @ Configure search Webparts

Advanced Search Security for SharePoint Server 2010 and FAST Search Server 2010 - In this tutorial you will learn about security for both Microsoft SharePoint Server 2010 and Microsoft FAST Search Server 2010 for SharePoint. Item-level security and the authorization process in FAST Search Server 2010 for SharePoint are also discussed in detail. See the videos below
Learn how to set search security

Configure authentication for FBA and claim based search site

Item-level and Fast authorization process


People Search Administration and Management -
In this video you will learn the process of configuring people search in Microsoft SharePoint Server 2010, adding user profiles, configuring My Site settings, and crawling the profile store. See the video at the below link:
People Search Administration

Disable\Hide social Tags, Notes for a group in Sharepoint 2010

Enable or disable social tagging permissions for users or groups -

After you perform this procedure, the users or groups you selected will not be able to use the social tagging features.

Enable or disable social tagging permissions for users or groups

After you perform this procedure, the users or groups you selected will not be able to use the social tagging features.
To enable or disable social tagging permissions for users or groups

1. Verify that you have the following administrative credentials:
* You must have the Manage Social Data permission.
* You must be a member of the Farm Administrators group.

2. On the Central Administration Web site, in the Application Management section, click Manage service applications.

3. In the list of service applications, click the User Profile Service Application link.

4. On the Manage Profile Service: User Profile Service Application page, in the People section, click Manage User Permissions.

5. In the Permissions for User Profile Service Application dialog box, type or select a user or group account, and then click Add.

6. Do one of the following:

1. To enable the permission, in the Permissions for box, select the Use Social Features check box, and then click OK.

2. To disable the permission, in the Permissions for box, clear the Use Social Features check box, and then click OK.

Retrieve Tags and Notes for Current User programmatically Sharepoint 2010

Here is a code for a webpart that will display current user's Tags and Notes.

using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.ApplicationPages;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using UP = Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.SocialData;
using Microsoft.SharePoint.Taxonomy;
using System.Web.UI;
using System.Reflection;
using System.Security.Principal;
using System.Text;
using System.IO;


namespace ILikeItPart
{
public partial class ILikeItUserControl : UserControl
{
#region Members
SPSite m_site;
SPWeb m_web;
UP.UserProfile m_up;
#endregion

protected void Page_Load(object sender, EventArgs e)
{
m_site = SPContext.Current.Site;
m_web = m_site.OpenWeb();

//Get profile manager
SPServiceContext m_context = SPServiceContext.GetContext(m_site);
UP.UserProfileManager m_upm = new UP.UserProfileManager(m_context);
//Get user profile for currently logged in user
m_up = null;

try
{
m_up = m_upm.GetUserProfile(HttpContext.Current.User.Identity.Name);
}
catch (Exception ex)
{
debug.InnerHtml += ex.ToString();
return;
}

SocialTagManager stm = new SocialTagManager(m_context);
List<SocialTag> mytags = new List<SocialTag>();
mytags.AddRange(stm.GetTags(m_up));

rpt_ILikeIt.DataSource = mytags;
rpt_ILikeIt.DataBind();
}

protected void rpt_ILikeIt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{

if (e.Item.DataItem != null)
{
SocialTag tag = (SocialTag)e.Item.DataItem;
if (tag.Term.Name == "I like it")
{
SPSite tagSite = new SPSite(tag.Url.ToString());
SPWeb tagWeb = tagSite.OpenWeb();

((HtmlGenericControl)e.Item.FindControl("p_ILikeIt")).InnerHtml = tagWeb.Url;
}}}}}

add a custom aspx page in sharepoint 2010 using SharePoint designer

In this post i show you an example of how to quickly create a custom aspx page or site page for sharePoint 2010 using SharePoint 2010 designer. We will add some javascript to it for testing.

To do this lets look at the steps :

1. Open SharePoint Designer 2010. Open a specific SharePoint site and click Site Pages.

2. Click Web Part Page on the ribbon to create a new page. Right-click the default site that is created for you and click Rename. Provide a name for the Site page "OurcustomPage", and then click the link to open the Properties page for the new page. To edit the new Web part page,click Edit File.

3. You can toggle between different views, which include a code view, design view, and a split view.Open the Toolbox to see the different controls that are available for use.

4. Open the page in code view. You’ll notice that there are some shaded and unshaded portions of the page. The unshaded portions of the page are where you can edit. The page content should look something like below

<WebPartPages:WikiContentWebpart runat="server" AllowEdit="True" AllowConnect=”True” ConnectionID="00000000-0000-0000-0000-000000000000" Title="" IsIncluded="True" Dir="Default"
IsVisible="True" AllowMinimize="True".....>
<Content>
<div><asp:Label runat="server" Text="Developer Book Info" id="Label1" Font-Bold="True" Font-Size="Medium"></asp:Label></div>
<!--... add other controls here ... -->

//Add javascript here

<script language="javascript" type="text/javascript">
function ShowAlert()
{
alert("This is my Custom Page");
}
</script>
</Content>
</WebPartPages:WikiContentWebpart>

5. Click Preview in Browser to ensure that the custom Web part loads as you’ve designed it.

Related Post : Add Custom aspx page in SharePoint 2010 using Visual Studio

Converting .stp files to .wsp file for sharepoint 2010

As you might know that the Site templates or .stp files are deprecated in SharePoint Server 2010 and cannot be used to create new sites. Well, then how to migrate them? The answer is converting them to .wsp files or Solution packages. Solution packages(.wsp files) are the supported method for creating sites that are based on a template in SharePoint Server 2010. You can convert an .stp file to a .wsp file to continue to use the template after upgrade.

To convert an .stp file to a .wsp file follow the steps below :

1. In Office SharePoint Server 2007, create a site that is based on the template, and then upgrade the site to SharePoint Server 2010.

2. In SharePoint Server 2010, on the Site Actions menu in the upgraded site, click Site Settings.

3. On the Site Settings page, under Site Actions, click Save site as template.

4. On the Save as Template page, enter a File name and Template name, and then click OK.

The site template is saved as a .wsp file to the Solutions Gallery for that site collection and you can create new sites that are based on that solution.

BCS object model in Sharepoint 2010

As you might know that in comparison to a custom webpart, BCS has become a preferred method to bring in and display data from external sources for fairly obvious benefits.. such as BCS entities become searchable, you have the ability to use these entities like SharePoint lists, and you can use certain WebParts and other facilities such as associations and actions on these BCS entities,and the ability to represent any back-end system, in a consistent object model that can be programmed against. Well, nothing to hide that object model is the BCS object model.

This BCS object model has a big advantage. As you know that the back-end systems change and upgrade over time, as long as their equivalent BCS external content types are kept up to date, all existing systems can continue to leverage the same object model, and existing systems will continue to work with changing newer versions of back-end systems without even the need of a recompile. This is because, as long as you update the BCS external content types, the actual BCS object model won’t change, and will continue to work and will simply reflect the updated external content types.

The BCS object model provides you with functionality to both query and maintain the catalog, or to execute methods on individual external content types.

Lets look at an example of using BCS object model Browsing through the catalog on your Sharepoint installation.

Start Visual Studio 2010 and create a .net 3.5 console application. Make sure the target platform is AnyCPU, and you add the following references.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Sharepoint.dll

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.BusinessData.dll

Microsoft.Sharepoint.BusinessData.Administration.Client.dll from the GAC

In your console application add a static variable pointing to your SharePoint site as shown below:
privatestaticstringsiteUrl = "http://SP2010Site";

The you can browse through the existing catalog by using the AdministrationMetaDataCatalog
object in the Microsoft.Sharepoint.BusinssData.Administration.Client namespace.

private static void BrowseCatalogDetails()
{

Console.WriteLine("Now Browsing the details of the catalog:");
AdministrationMetadataCatalog catalog =
AdministrationMetadataCatalog.GetCatalog(siteUrl);
EntityCollection entities = catalog.GetEntities("*", "*", true);

Console.WriteLine("\nEntities in the system:");

foreach (Entity entity in entities)
{
Console.WriteLine(entity.Name);
}
// Lets pick the first entity
var entityEnum = entities.GetEnumerator();
entityEnum.MoveNext();
Entity firstEntity = entityEnum.Current;
Console.WriteLine("\nMethods on the first Entity:");
foreach (var method in firstEntity.Methods)
{
Console.WriteLine(method.Name);
}
}

As you can see in the above code you have access to all the entities and all the details of all the entities in the catalog. In fact if you poke around the object model, you will be able to find that purely through the object model you can create the new entities in the catalog as well.

Next let us look at an example of actually executing a method on an entity, and writing the results out.

private static void ExecuteMethod()
{
Console.WriteLine("\nNow Executing methods");

using (SPSite site = newSPSite(siteUrl))
{
using (newSPServiceContextScope(SPServiceContext.GetContext(site)))
{
BdcService service = SPFarm.Local.Services.GetValue();
IMetadataCatalog catalog =
service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);
IEntity entity = catalog.GetEntity(siteUrl, "Northwind Customer");
ILobSystemInstance LobSysteminstance =
entity.GetLobSystem().GetLobSystemInstances()[0].Value;
IMethodInstance method =
entity.GetMethodInstance("Read List", MethodInstanceType.Finder);
IEntityInstanceEnumerator ieie =
entity.FindFiltered(method.GetFilters(), LobSysteminstance);
Console.WriteLine("\nCustomers in Northwind:");
while (ieie.MoveNext())
{
Console.WriteLine(ieie.Current["ContactName"].ToString());
}}}}

As you can see in the above code, I’m able to use a consistent object model, irrespective of the details of the external content type, or the back-end system, and be able to execute methods on the back-end system. Thus as the back-end system changes, and the external content type is maintained.

Access i like items for a user in sharePoint 2010 Programmatically

Here is a short example on how to retrie "i like" items for a given user in SharePoint 2010

public static List GetMyILikeIts()
{

SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,SPSiteSubscriptionIdentifier.Default);

UserProfileManager upm = new UserProfileManager(context, true);
UserProfile up = upm.GetUserProfile("Domain\\IAttlee");

SocialTagManager stm = new SocialTagManager(context);
SocialTag[] tags = stm.GetTags(up);

if (tags != null)
return tags.Where(t => t.Term.Name == "I like it").ToList();
else
return null;
}

related post : Programmatically retrieve social ratings in sharepoint 2010

SPquery, Join and Projected fields in Client object model - sharepoint 2010

An example of how to use Joins and Projected fields in a Spquery in Client Object model. The code example is in ECMAScript


<span style="font-weight:bold;">Country </span>Lookup list - Title, CountryName, CountryContinent

<span style="font-weight:bold;">Test1 </span>Destination list - Title,City (Title being a lookup column)


<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(getProducts, "sp.js");

var productcollection;
function getProducts() {

try {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Test1');
var query = '<View>' +
'<Joins>' +
'<Join Type=\'INNER\' ListAlias=\'Country\'>' +
'<Eq><FieldRef Name=\'City\' RefType=\'Id\' /><FieldRef List=\'Country\' Name=\'ID\'/></Eq>' +
'</Join>' +
'</Joins>'+
'<ProjectedFields>' +
'<Field Name=\'CountryName\' Type=\'Lookup\' List=\'Country\' ShowField=\'CountryName\' />' +
'<Field Name=\'CountryContinent\' Type=\'Lookup\' List=\'Country\' ShowField=\'Country_x0020_Continent\' />' +
'</ProjectedFields>' +
'</View>';
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
camlQuery
this.productcollection = list.getItems(camlQuery);
context.load(this.productcollection, 'Include(Title,City,CountryName,CountryContinent)');
context.executeQueryAsync(Function.createDelegate(this, this.productsReceived), Function.createDelegate(this, this.failed));
}
catch (e) {
alert(e);
}
}
function productsReceived() {
alert('Success');
var item = this.productcollection.itemAt(0);
var itemValues = this.productcollection.itemAt(0).get_fieldValues();
alert(itemValues.City.$b_1);
alert(itemValues.CountryName.$b_1);
alert(itemValues.CountryContinent.$b_1);
}

function failed(sender, args) {
alert('failed. Message:' + args.get_message());
}
</script>

Programmatically access audit for sharepoint 2010 site

In this example we will retrieve audits recorded for a particular listitem in a list, created in SharePoint 2010 site. The audit results i.e. User,Event,Occurred,Version for that item is stored in a datatable for further use. Also, I am passing ListId and ItemId to a function called GetAudithistory and using ParseVersionNumber and GetUserNameById functions to get the user name and Version number of the item.

public void GetAudithistory(string ListId,string ItemId)
{

SPSite siteColl = SPContext.Current.Site;

SPWeb site = SPContext.Current.Web;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite ElevatedSiteCollection = new SPSite(siteColl.ID))
{
using (SPWeb ElevatedSite = ElevatedSiteCollection.OpenWeb(site.ID))
{
SPList list = ElevatedSite.Lists[new Guid(ListId)];

txtListTitle.Text = list.Title;

SPListItem item = list.Items.GetItemById(Convert.ToInt32(ItemId));

txtItemTitle.Text = item.Name;

SPAuditQuery wssQuery;

SPAuditEntryCollection auditCol;

wssQuery = new SPAuditQuery(ElevatedSiteCollection);

wssQuery.RestrictToListItem(item);

auditCol = ElevatedSite.Audit.GetEntries(wssQuery);

DataTable table = new DataTable();
table.Columns.Add("User", typeof(string));
table.Columns.Add("Event", typeof(string));
table.Columns.Add("Occurred", typeof(DateTime));
table.Columns.Add("Version", typeof(string));

DataRow newRow;
foreach (SPAuditEntry entry in auditCol)
{
newRow = table.Rows.Add();

newRow["User"] = GetUserNameById(entry.UserId, site); -> Calling GetUserNameById

if (entry.SourceName == "CustomViewAuditEvent")
{
newRow["Event"] = "View Audit Log";
}
else
{
newRow["Event"] = entry.Event;
}

newRow["Occurred"] = entry.Occurred.ToLocalTime();

newRow["Version"] = ParseVersionNumber(entry.EventData); -> Calling ParseVersionNumber
}
}

string GetUserNameById(int UserId, SPWeb site)
{
try
{
return site.SiteUsers.GetByID(UserId).Name;
}
catch
{
return UserId.ToString();
}
}


protected string ParseVersionNumber(string versionString)
{
try
{
int startMajor = versionString.IndexOf("") + 7;
int endMajor = versionString.IndexOf("
");
int lengthMajor = endMajor - startMajor;
int startMinor = versionString.IndexOf("") + 7;
int endMinor = versionString.IndexOf("
");
int lengthMinor = endMinor - startMinor;

string majorNumber = versionString.Substring(startMajor, lengthMajor);
string minorNumber = versionString.Substring(startMinor, lengthMinor);

if (majorNumber == "0" && minorNumber == "-1")
return "N/A";

return majorNumber + "." + minorNumber;
}
catch
{
return "N/A";
}
}

Using REST to get data form SharePoint 2010 lists

Since REST uses a standard URL - addressable format and uses standard HTTP methods, such as GET , POST , PUT , and DELETE , you get a predictable way to retrieve or write items in your SharePoint deployment. Here is a quick reference to how you would retrieve data with REST url

List of Lists - ../_vti_bin/listdata.svc

List - listdata.svc/Listname

Item - listdata.svc/Listname(ItemID)

Single Column - listdata.svc/Listname(ItemID)/Column

Lookup Traversal - listdata.svc/Listname(ItemID)/LookupColumn

Raw Value Access (no markup) - listdata.svc/Listname(ItemID)/Column/$value

Sorting - listdata.svc/Listname?$orderby=Column

Filtering - listdata.svc/Listname?$filter=Title eq ‘Value’

Projection - listdata.svc/Listname?$select=Title,Created

Paging - listdata.svc/Listname?$top=10&$skip=30

Inline Expansion (Lookups) - listdata.svc/Listname?$expand=Item

Get list items with Silverlight in Sharepoint 2010

In SharePoint 2010 we use three types of Client Object model extenstions. To get all items using .Net managed client Object model see -
.Net managed client Object model -

To get all items using ECMASCRIPT\Javascript object model see -
Using ECMAScript

In this post however, we will see an example of retrieving list items using Silverlight Client object model in SharePoint 2010.

using SP = Microsoft.SharePoint.Client;

namespace SPSilverlight
{
public partial class MainPage : UserControl
{
IEnumerable < SP.List > listItems = null;
public MainPage()
{
InitializeComponent();
}
private void getItemsSucceeded(object sender,
Microsoft.SharePoint.Client.ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
listBox1.ItemsSource = listItems;
listBox1.DisplayMemberPath = "Title";
});
}

private void getItemsRequestFailed(object sender,
Microsoft.SharePoint.Client.ClientRequestFailedEventArgs e)
{
Dispatcher.BeginInvoke(() = >
{
MessageBox.Show("Error: " + e.ErrorCode + " " + e.ErrorDetails + "
" + e.Message + " " + e.StackTrace.ToString());
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClientContext context = null;
if (App.Current.IsRunningOutOfBrowser)
{
context = new ClientContext(
"http://SP2010Site");
}
else
{
context = ClientContext.Current;
}
var query = from listCollection
in context.Web.Lists
where listCollection.Title != null
select listCollection;
listItems = context.LoadQuery(query);
ClientRequestSucceededEventHandler success = new
ClientRequestSucceededEventHandler(getItemsSucceeded);
ClientRequestFailedEventHandler failure = new
ClientRequestFailedEventHandler(getItemsRequestFailed);
context.ExecuteQueryAsync(success, failure);
}
}
}

Edit user profile using webservice Sharepoint 2010 webservice

This example will show you how to edit a user profile in SharePoint 2010 via UserProfileService webservice

public static localhost.UserProfileService myService = new localhost.UserProfileService();

UserProfileWebService.localhost.PropertyData[] newdata = new UserProfileWebService.localhost.PropertyData[1];

newdata[0] = new UserProfileWebService.localhost.PropertyData();

newdata[0].Name = "Isha";

myService.ModifyUserPropertyByAccountName("domainname\\Isha", newdata);

Permitted File Names in SharePoint 2010

Many times you might have a need to deploy files of various sorts to subfolders under the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE directory. Well, here are the rules to name them in SharePoint 2010.

For security reasons, SharePoint 2010 will allow you to deploy files in the 14\TEMPLATE directory tree only if their names are composed of ASCII letters, numbers, periods, underscores, or dashes. In addition, file names cannot contain two or more consecutive periods. For example, the following are permitted file names:

AllItems.aspx

Dept_1234.doc

Long.Name.With.Dots.txt


The following are not permitted file names:

Cæsar.wav

File Name With Spaces.avi

Wow...ThisIsBad.rtf

揵.htm

So watch it before you go crazy with your deployment

Programmatically Create Site Column, Site Content Type in Sharepoint

Here is a Code snippet for creating a new Site column and adding it the site collection Site column gallery and int0 a newly created content type.

public void CreateSiteColum()
{

string columnGroup = "Custom Columns";

// Adding Custom Column Amount
string amountFieldName = site.Fields.Add("Amount", SPFieldType.Currency, false);

SPFieldCurrency amountField = (SPFieldCurrency)site.Fields.GetFieldByInternalName(amountFieldName);

amountField.Group = columnGroup;
amountField.DisplayFormat = SPNumberFormatTypes.TwoDecimals;
amountField.MinimumValue = 0;
amountField.Update();

See detailed Post @ Create site column in Sharepoint 2010

/* CREATE SITE CONTENT TYPES */

string contentTypeGroup = "Custom Content Types";

// Get a Document content type to be the parent of our new custom content type.
SPContentType documentCType = site.AvailableContentTypes[SPBuiltInContentTypeId.Document];

// Create the Custom Financial Document content type.
SPContentType financialDocumentCType = new SPContentType(documentCType, site.ContentTypes, "Financial Document");
site.ContentTypes.Add(financialDocumentCType);

// Note: A content type is not initialized until after it is added.
financialDocumentCType = site.ContentTypes[financialDocumentCType.Id];
financialDocumentCType.Group = contentTypeGroup;


// Add the Amount column. Child content types inherit the column.
SPFieldLink amountFieldRef = new SPFieldLink(amountField);
financialDocumentCType.FieldLinks.Add(amountFieldRef);

// Commit changes.
financialDocumentCType.Update();

}

site in the above code is SPSite (or SiteCollection) Object.

Custom Search WebPart for Sharepoint 2010

In SharePoint 2010, you can use the query object model to build custom search
Web Parts and search applications. This object model allows you to query against SharePoint Server search as well as to FAST Search Server 2010 for SharePoint.

The FullTextSqlQuery class available in the object model allows you to build complex search queries based on SQL syntax however, the KeywordQuery class can be used to issue search queries based on simple query syntax. With Fast Search Server 2010, this class can also be used to run queries based on the Fast Query Language (FQL), which supports advanced queries in enterprise environments.

See the complete code example at the below link

Custom Search WebPart for Sharepoint 2010

Get user Profile in SharePoint 2010

In this Post I will show you an example of how to access User Profile using SharePoint 2010's Object model

The basic class for working with user profiles is the UserProfileManager which is a part of Microsoft.Office.Server namespace. With the UserProfileManager class, you can basically create, get, and remove user profiles. If you want to maintain the user profile metadata such as properties, you should use the UserProfileConfigManager class because the UserProfileManager class’s metadata access is meant to be read-only.

Now, Lets see how to access a User Profile

* Create a User Profile (if not exist)

// Get the current site context
strUrl = "http://localhost";

SPSite site = new SPSite(strUrl);
SPServiceContext serviceContext = SPServiceContext.GetContext(site);

// Initialize the user profile manager
UserProfileManager upm = new UserProfileManager(serviceContext);

// Create a user profile
string sAccount = "domain\\isha";

if (!upm.UserExists(sAccount))
upm.CreateUserProfile(sAccount);


* Get colleagues from user profile

foreach (var colleague in u.Colleagues.GetCommonColleagues())
{
lbColleagues.Items.Add(colleague.DisplayName);
}


* Latest changes of the current user’s profile

string sAccount = "domain\\isha";

UserProfile u = upm.GetUserProfile(sAccount);

foreach (var change in u.GetChanges())
{
lblOutput.Text += "
" + change.ChangeType + " " + change.ChangedProfile + " "
+ change.EventTime.ToShortDateString();
}

* Get User Profile Picture

See my example with ECMAScript at my new website Get user profile picture using Client Object model

and like this you can access a lot of other User profile properties available using Client OM.

Managed code vs JavaScript client object model sharepoint 2010

When using the various client object models, be aware that there are some small differences, especially between the managed code and JavaScript implementations.

Absolute and Relative URLs

JavaScript you have to provide a server-relative URL:

[JavaScript or ECMAScript]
var clientContext = new SP.ClientContext("/mySiteCollection/mySite");

When working with the managed object models for Windows or Silverlight applications, you need to use either an absolute URL or an object of type System.Uri:

[.NET]
ClientContext clientContext = new ClientContext("http://SPservername");

[Silverlight]
ClientContext clientContext = new ClientContext("http://SPservername)


Different Data Types

Keep in mind that between the managed object model and the JavaScript object model, there are some differences regarding the data types. Most of the data types behave similarly to each other, but there are some language-specific particularities, like the NaN (Not a Number) value in JavaScript, which has no equivalent in managed code. On the other hand, complex list objects like StringCollection in managed code do not exist on the JavaScript side and therefore are implemented as normal arrays—in our example, as string[]


Authentication Mode

When using JavaScript you do not need to worry about authentication because the page that runs your JavaScript is already authenticated either by Windows Authentication or Forms Authentication. If you are using the managed object models and you want to use Forms Authentication instead of Windows Authentication, use code like this:

[.NET]
clientContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("user","password");


Using the Digest Web Control

Before you can use the JavaScript object model on a page, you have to ensure that the page contains the FormDigest web control. This web control inserts a security validation token within the form of an ASPX page. When making a call to the server—for example, to retrieve data—this token will also be included and validated by the server. A security token is specific to a user, site, and time period—thus, it expires after a configurable time interval.


Using the FormDigest to validate requests prevents attacks wherein a user is tricked into posting data to the server.

Tip : Debug Sandbox Solution packages in Sharepoint 2010

During development, Visual Studio 2010 automatically builds the solution package, deploys it, and activates it in the Solution Gallery when you start debugging by pressing F5 but if you want to debug an already deployed sandboxed solution, you need to attach the SPUCWorkerProcess.exe proccess manually and hit F5 to debug. See the image below

CamlQuery examples SharePoint 2010

Some examples how can use SPquery or caml query in SharePoint 2010 Client Object model.

var site;
var context;
var list;
var collListItem;

context = new SP.ClientContext.get_current();
site = context.get_web();
context.load(site);

list = site.get_lists().getByTitle('MyList');
context.load(list);

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('');
collListItem = list.getItems(camlQuery);
context.load(collListItem);

context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

alert("Request succeeded. " + args.Message + "\n" + args.StackTrace);
}

function onQueryFailed(sender, args) {

alert("Request failed. " + args.Message + "\n" + args.StackTrace);

}

Restrict Certain file types in Sharepoint 2010

In SharePoint 2010, by default, many file types are blocked, including file types that are treated as executable by Internet Explorer 7.

However, if you want to block some other extensions follow the Steps below:

1. Goto Central Administration and click Security.

2. On the Security page, in the General Security section, click Define blocked file types.

3. On the Blocked File Types page, Select the desired Web Application.

4. To block a file type, scroll to the bottom of the Type each file extension on a separate line text box and type the file extension you want to block and then click OK.

To Unblock :

just Select the File type and Delete it.

To this Programmatically see my post @ Programmatically restrict file types in sharepoint 2010

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com