Loading...
Showing posts with label Content Type. Show all posts
Showing posts with label Content Type. 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

Monday, September 21, 2009

SharePoint Manger 2007 For Adding Customized content Type

Hello All,

First let me explain, what is content Type? Its FAQ and very important to understand,
A content type is a reusable collection of settings you want to apply to a certain category of content. Content types enable you to manage the metadata and behaviors of a document or item type in a centralized, reusable way.
for the exact definition visit
http://www.documentmanagementworkflowinfo.com/sharepoint-document-management/understand-basics-content-types-sharepoint.htm
For Customizing the New\Edit\Display Forms of Custom List
use SharePoint Manager which can be downloaded at codeplex
its a great tool for customizing content Types
Find more links on google for how to do it
like 1) http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-content-type-user-interface-part-4-of-6
2)Book on Share Point Manager 2007
Photobucket

Saturday, September 12, 2009

validation with standard sharepoint error Page on ListItem adding event

To add validation to listitem adding event( to restrict the no of items to be added per day)in list
1) Visual studio 2008 -->Sharepoint-->Empty Project
2)In solution explorer-->add new item --> content type
3)And check content type with event receiver, you will find three 2 .cs files and 1 xml file
a)itemeventreciver.cs

b)ListItemReciver.cs
in this file uncomment the ItemAdding event

add the following code required for the restriction

public override void ItemAdding(SPItemEventProperties properties)
{

int perday = GetItemCountPerDay();
string dt= properties.AfterProperties[CONST_FIELD_DATETIME].ToString();
SPQuery query = QueryItemForPerDay(dt);

using (SPWeb oWebsite = new SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl))
{

SPListItemCollection collItems = oWebsite.Lists[properties.ListTitle].GetItems(query);

if ((collItems != null) && (collItems.Count > perday - 1))
{
properties.ErrorMessage = String.Format("Adding items to this list is not supported because per day only allowed add {0} items.", PER_DAY);
properties.Cancel = true;
}
}

}


c).xml file


4)Deploy the project
To enable the content type
go to the site Site actions -->create new custom list --> enable the content types for the site
list settings-->advanced settings--selct deployed content type

5)Go to wss --> virtual diectories-> site --> open the web.config file and do the following changes

sharepoint

safemode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false"

customerrors mode="On"