Sharepoint set user or group to SPListItem

We are going to use a sharepoint web control to get user or groups  named “PeopleEditor” .For using these please fallow the instructions below.

Add fallowing code to top of your page:

<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Add fallowing control to your page front for get users or groups:

Note: If  you want to set or retrieve the account types that are associated with the control use attribute “SelectionSet”
and enums are:

  • User = single user
  • DL = AD distribution list
  • SecGroup = AD security group
  • SPGroup = Sharepoint group

<SharePointWebControls:PeopleEditor runat=”server” ID=”txtScope” MultiSelect=”false” MaximumEntities=”1″ ValidatorEnabled=”true” SelectionSet=”User” Width=”300px”></SharePointWebControls:PeopleEditor>

Add fallowing to your page behind:

using Microsoft.SharePoint.WebControls;
public SPFieldUserValueCollection GetSelectedUsers(PeopleEditor editor)
{
       string selectedUsers = editor.CommaSeparatedAccounts;
       // commaseparatedaccounts returns entries that are comma separated. we want to split those up
       char[] splitter = { ',' };
       string[] splitPPData = selectedUsers.Split(splitter);
       // this collection will store the user values from the people editor which we'll eventually use
       // to populate the field in the list
       SPFieldUserValueCollection values = new SPFieldUserValueCollection();
       // for each item in our array, create a new sp user object given the loginname and add to our collection
       for (int i = 0; i < splitPPData.Length; i++)
            {
                string loginName = splitPPData[i];
                if (!string.IsNullOrEmpty(loginName))
                {
                    SPUser user = SPContext.Current.Web.SiteUsers[loginName];
                    SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, user.ID, user.LoginName);
                    values.Add(fuv);
                }
            }
            return values;
        }
}

And now i describe add to listitem and update:

SPList list = SPContext.Current.Web.Lists[APPLIB];
SPListItem item = list.Items.Add();
item["ProgramAdmin"] = GetSelectedUsers(txtScope);
item.Update();

That’s all.

Sharepoint solution deployment with Stsadm

Tips & Tricks :
Here is the command list of stsadm that deploy a wsp file to your sharpoint site.
.
//First we retract if exist solution
stsadm -o retractsolution -name myproject.wsp -immediate
.
// Forcing sharepoint to run timer jobs.
stsadm -o execadmsvcjobs
.
//and delete solution after retract
stsadm -o deletesolution -name myproject.wsp
.
//add solution
stsadm -o addsolution -filename c:\solutions\Hello.wsp
.
//deploy it
stsadm -o deploysolution -name Hello.wsp -immediate -allowGacDeployment
.
//Execute timer jobs
stsadm -o execadmsvcjobs
.
//Recycle Application Pool.
%windir%\system32\inetsrv\appcmd recycle AppPool “Application Pool Name”
.
Thats all .

Sharepoint Exit Edit Mode programmatically

Sharepoint Tips & Tricks: Sharepoint exit edit mode programmatically.

We can do it with redirect to same page.

“Microsoft.SharePoint.Utilities” Namespace has a static class named SPUtility.

Example:

SPUtility.Redirect(SPContext.Current.ListItem.File.ServerRelativeUrl , SPRedirectFlags.Default, this.Context);

Easy isn’t it…

The page took too long to save…

See my post about:

Saving Page Content Sharepoint with IE8 cause annoying delay:

https://blog.bugrapostaci.com/2010/03/03/saving-page-content-sharepoint-with-ie8-cause-annoying-delay/

See you next article…

Saving Page Content Sharepoint with IE8 cause annoying delay

This is very annoying problem when you are programming with IE8 and using sharepoint .We are working with custom layout pages coding and this problems occured and waste our valuable time.

Symptom

When navigating away from a publishing page that is in edit mode the browser displays “Saving Page Content…” in the status bar which can take up some time (about 15 sec)  to complete before asking for confirmation to not save the page.There were no such error with either IE7 or FireFox.

Cause

SBN_CallBackHandler() client function of SaveBeforeNavigationControl is not called as it supposed to. It looks like the implementation of XMLHttpRequest object in IE8 is somehow different from the previous release

Solution: There are three different solution

1) Change IE8 configuration parameter

Click -> tools -> Internet Options -> Advanced (tab)  and uncheck

Enable native XMLHTTP support (checked by default)

(This solution not worked with me but some blogs say thats ok )

2) Edit
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\PublishingConsole.ascx
and remove this component.
<PublishingWebControls:SaveBeforeNavigationControl id=”sbn1″ runat=”server”>
< / PublishingWebControls:SaveBeforeNavigationControl>
And also did not work for me !!

3) Add javascript to your page:

<script type=”text/javascript”>
_spBodyOnLoadFunctionNames.push(“UnloadHandler”);
function UnloadHandler()
{
document.body.onUnload = “”;
window.onbeforeunload=””;
}
</script>
Thats all folks…