Loading...
Showing posts with label Learning. Show all posts
Showing posts with label Learning. Show all posts

Monday, September 19, 2011

'value does not fall in expected range' When assigning SPUser to ListItem


If you try to assign,
ListItem["UserField"]=SPContext.Web.CurrentUser
And you get th Error  " value does not fall in expected range"
Cause:  ListItem is in different Sitecollection
So Directly You can not assign current user.
Resolution:
SPUser differntSiteCollectionUser = differentWeb.SiteUsers.GetByEmail(currentUserMailId);-->GetmailID with SPFieldUserValue

Thursday, September 8, 2011

Modal Popup and The Notification Area

Here I am covering
        1)Passing Url to Modal Popup from Server code in .cs file
          i)add the hiddenfield control to .aspx page          
and set value in cs file
hdnUrl.Value = "../Lists/ListName/NewForm.aspx?RootFolder=&";

        2)On Click of Ok button of Modal Popup Displaying the message in notification area which is part of sp2010 framework
Add following in Javascript tags
var url = document.getElementById('').value;

var options = {

url: url

title: "title",

allowMaximize: true,

showClose: true,

dialogReturnValueCallback: refreshCallback

};

function open() { SP.UI.ModalDialog.showModalDialog(options); }

function silentCallback(dialogResult, returnValue) {

}

function refreshCallback(dialogResult, returnValue) {

SP.UI.Notify.addNotification('Successful!');

SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

}


Invoke the function

asp:Label runat="server" ID ="lblr" Text ="Open Popup">

Thursday, August 4, 2011

A Method To Get Selected Value in spuc:PeopleEditor control (Quickly)

-- Add Control in ascx


AllowEmpty="true" MultiSelect="false" SelectionSet="User" />
 
-- Get User value in ascx.cs
public SPUser GetUser(PeopleEditor p)

{

PickerEntity entPropMgr = (PickerEntity)p.ResolvedEntities[0];

SPFieldUserValue Proposalmgrvalue = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entPropMgr.EntityData[PeopleEditorEntityDataKeys.UserId]), entPropMgr.Description);

if (Proposalmgrvalue != null)

return Proposalmgrvalue.User;

else

return SPContext.Current.Web.CurrentUser;



}

Wednesday, August 3, 2011

SPDispose Check Results

- I have noticed that objects(SPWeb) created inside for loops are not being disposed. These objects need to be disposed eventhough you main block of code is "Using".

- Also when you use following snippet it will not dispose SPSite object:
using(SPWeb oWeb=new SPSite("http://abc").openWeb())

{

-------

}
Here SPSite object is not disposed so follow below style in case of such scenerios:

using(SPSite oSite=new SPSite("url"))

{

using(SPWeb oWeb=oSite.OpenWeb())

{

------

}

}


This will solve the problem of disposing.
- Do not use "Using" when you work with SPContext. As SPContext are disposed automatically and if you use withing Using block than it will dispose SPWeb object and page will not work.

Saturday, July 9, 2011

Modal Popup with Content Editor Webpart

Open the sharepoint Site
In Ribbon,Find Insert Link-->Select Webparts-->In Media and Content Category-->Select Content Editor Webpart.-->Add/Edit the webpart

In SP 2010, Select Contents in CEWP, Format--> Html Source in the ribbon,
Add the javacript code
<script type="text/javascript">
     function OpenDialog(URL) {
         var NewPopUp = SP.UI.$create_DialogOptions();
         NewPopUp.url = URL;
         NewPopUp.width = 700;
         NewPopUp.height = 350;
         SP.UI.ModalDialog.showModalDialog(NewPopUp);
     }
 script>

=  "javascript:OpenDialog(‘../_layouts/MyAppPage/MyPage.aspx’)"--To Make it Server relative.
So that Dialog box opens anywhere in site collection

Thursday, January 8, 2009

Screencasts for sharepoint developers

1)http://msdn.microsoft.com/hi-in/sharepoint/aa905382(en-us).aspx