Translate
Friday, September 21, 2012
Wednesday, September 19, 2012
Using SPUser in SharePoint
Using SPUser in SharePoint
SharePoint Object Model using SPUser Class
SPUser is actually derived from SPPrinciple, SPUser is main
base class which allows in extending its functionality by exposing its member
and different properties.SharePoint object model has provided the provision to
add the user programatically to sharepoint group or permissions to user to a list,and it is possible to update the user information or fetch the user information.
The following sample code shows about how to display user
permission is he in admin group or normal user
also it has the code to update the user information or giving the permission to a list
WebPart
using System;
using System.ComponentModel;
using System.Web;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SPUserDemo
{
[ToolboxItemAttribute(false)]
public class SPUserDemoWebPart:
WebPart
{
protected override void CreateChildControls()
{
}
protected override void RenderContents(HtmlTextWriter
writer)
{
//Get the user
information
GetUser(writer)
}
private void GetUser(HtmlTextWriter writer)
{
SPUser SPuser = SPContext.Current.Web.CurrentUser;
if(SPuser.IsSiteAdmin)
writer.Write("<p>Ohh you are Super admin user'</p>");
else
writer.Write("<p>No you are a normal user </p>");
}
}
}
Private void AddNewUser()
{
const string listUsers = @"Users ";
SPList Users= null;
SPSecurity.RunWithElevatedPrivileges(
delegate {
using (SPSite spSsite= new SPSite(“http://sitedemo”)) {
using (SPWeb spWeb= spSsite.OpenWeb)
{
spWeb.AllowUnsafeUpdates = true;
Guid listGuidID = spWeb.Lists.Add listUsers,
"Members", SPListTemplateType.GenericList);
Users = spWeb.Lists[listGuidID];
Users.Fields.Add("User", SPFieldType.User, true);
Users.WriteSecurity = 4;
Users.Update();
spWeb.Update();
}
}
});
}
//update user email information
using (SPSite spSsite=new SPSite(“http://sitedemo”)) {
using (SPWeb spWeb= spSsite.OpenWeb)
{
SPUser spUser = spWeb.AllUsers["ABCUser"];
spUser.Email =
" E-mail_Address";
spUser.Update();
}
}
Using SPQuery with ContentIterator.MaxItemsPerQuery in SharePoint
Using SPQuery with ContentIterator.MaxItemsPerQuery
1.
Using SPQuery with RowLimit or with ContentIterator.MaxItemsPerQuery
When we query the
SharePoint list and libraries we use SPQuery
and some situations because of threshold value limit in sharepoint does
not allow the user to query more than or equal to 5000 items,If we use SPQuery
with RowLimit still it is not
sure to get the items, but there is
still SharePoint has provide one more way can do it through using ContentIterator.MaxItemsPerQuery.
We also need to use different keywords using depends upon
the requirement ContentIterator.ItemEnumerationOrderByID,
ContentIterator.ItemEnumerationOrderByPath,
or ContentIterator.ItemEnumerationOrderByNVPField.
Sample Code
SPQuery
myQuery = new SPQuery();
myQuery.Query
=
"<Where><Eq><FieldRef
Name=\"Name\"/><Value
Type=\"Text\">FieldValue</Value></Eq></Where>"
+
ContentIterator.
ItemEnumerationOrderByID;
ContentIterator
citerator = new ContentIterator();
citerator.ProcessItemsInList(query,
delegate(SPListItem item)
{
// Code for update or move the list
item from one list to another or //any
operation
},
// Return true so that ContentIterator
rethrows the exception.
delegate(SPListItem item, Exception e)
{
// Handle an exception that was thrown
while iterating.
return true;
}
);
SharePoint 2013 preview in Cloud Share
SharePoint 2013 preview in the Cloud Share
Using SharePoint in the Cloud Computing
http://www.cloudshare.com/products/proplus/getstarted
http://www.cloudshare.com/products/proplus/getstarted site is really a good to start using SharePoint 2013 in Cloud Share ,there is a free 14 days trail version Cloud SharePoint 2013 preview.
This is really amazing site,this cloud system has got everything
Server has the following software's got installed
1.SharePoint 2013 preview
2.Visual Studio 2012
3.SharePoint Designer 2012
4.SQL Server.
other softwares like PDF and other office tools.
Sunday, September 16, 2012
Creating Site Collection in SharePoint 2013 Preview
Creating Site Collection in SharePoint 2013 Preview
What is new features in SharePoint 2013 Preview
This is my first post on SharePoint 2013 preview,the following are the steps to create new site collection in SharePoint 2013,Microsoft has provided more features and enhancements in SharePoint 2013 than the SharePoint 2010.
Please follow the steps to create a new site collection in SharePoint 2013
1.Go to Central Admin and click on create site collection.
2.Screen will appear to create a new site collection,it is found that now it has a provision to create new web application on site collection creation screen as shown in the screen shot.
2. There is new option to select the template type based on
SharePoint 2010 and SharePoint 2013 also provided with more number of templates
like one is “Developer Site” and other
as shown in the following picture.3.Select the template which is required to create the site
4. Add the Site Collection Administrator account in primary
site collection Administrator and secondary Site Collection Administrator
There is new feature in People picker, more advanced can be
able to search people by Active directory,NT Account or even Claim Based User
as shown in the following screens shots
Now
Microsoft has provided one more feature by displaying the “Sorry to keep you waiting”
as shown in the screen shot
SPList.GetItemById and SPList.GetItemByIdSelectedFields
Using SPList.GetItemById and SPList.GetItemByIdSelectedFields
Difference between SPList.GetItemById and SPList.GetItemByIdSelectedFields
It is very important to
consider about the performance when we are query the SPList using SharePoint
Object Model, it is not recommended to fetch all items when you are using only
one column SharePoint has provided the GetItemByIdSelectedFields which takes the arguments as ID and Field Names
which is required.
SPList.GetItemByIdSelectedFields(ID,"Field 1","Field 2","Field3"... so on)
GetItemById method fetches
the full item from SPListItemCollection, with all its columns of metadata,even
though it may be not required for the any purpose of extra columns still
SPListItem hold that values too. So it is required to use in more better way of
both GetItemByIdSelectedFields and GetItemById based on the
requirements
The following example shows the Employee List which is being query by
using GetItemByIdSelectedFields
Let us say the Employee List has three columns
Employee List
Column Name
|
Type
|
Employee Number
|
Number
|
Employee Salary
|
Number
|
Employee Designation
|
Single Line Of Text
|
ID
|
Employee Number
|
Employee Salary
|
Employee Designation
|
1
|
1123
|
24000
|
Senior Software Engineer
|
2
|
1124
|
12000
|
Trainee
|
3
|
1125
|
50000
|
Project Manager
|
The following code fetches
using (SPSite site = new SPSite("http://sampledemo
/"))
{
using (SPWeb web = site.OpenWeb()) {
SPList employeeList = web.Lists["Employee List"];
SPListItem employeeItem= employeeList.GetItemByIdSelectedFields (2,” Employee Salary”);
}
}
Using ReadSecurity and WriteSecurity members in SharePoint
Using ReadSecurity and WriteSecurity members in SharePoint
ReadSecurity and WriteSecurity
ReadSecurity
Using the ReadSecurity we can specify the list permission as
read only access to list created through programmatically, it will restrict the
users for modifications to the items which they are not owners of that items.
WriteSecurity
Using WriteSecurity
we can allow the users to do modifications to list items which they are owners
of the items when we create the list by using the SharePoint Object Model
programmatically.
Sample demo code explains about the ReadSecurity and WriteSecurity by creating reimbursement
expense list in which employee who wants to claim their expanses will have the
permission which they item and others will not have an access ,Creating it
through console application.
//Create the SPSite by passing the url
Using(SPSite spSite=new SPSite(“http://demo/sites/HR”);
{
//Create new GUID
Guid newListGuid=spWeb.Lists.Add(“ExpensesReimbursement”,”
Expenses Reimbursement List”,SPListTemplateType. GenericList );
//open site
Using (SPWeb spWeb=spSite.OpenWeb())
{
//Create new SPList by passing new GUID
SPList newInstanceList
= spWeb.Lists[newListGuid];
}
}
Subscribe to:
Posts (Atom)