Loading...
Showing posts with label Sharepoint 2010. Show all posts
Showing posts with label Sharepoint 2010. Show all posts

Thursday, August 1, 2013

Building Custom Service Applications But When?

1)Whenever there is requirement to share the data across cross sitecollections or across farms
 or if you want to associate third party service may be for analytics or computation. building custom service application is must
2)To do so, you need to develop Webfront end server (Proxy UI for configuration), Application server (WCF end point) and SQL databases
Checkout this to get standard template to build custom service application


Friday, June 7, 2013

SharePoint Content Targeting With Audience Rules

SharePoint contents can be targeted to dynamic set of audience (SPUsers) satisfying  the Audience Rule
and matching particular user profile property or combination of multiple SharePoint groups or distribution lists

1)To do so, Under user profiles (In Central admin) --> select  Manage Audience



2)Create new audience and apply audience rules like follows and compile this audience group


Note--> You need to enable audience targeting for lists or libraries in settings page
3)Now whenever , New app part or webpart is added to the page ,(In Edit mode)In Edit toolpane, you can set custom Audience , irrespective of particular SharePoint Group

Monday, September 19, 2011

OOB authorization with SPSecurityTrimmedControl

Using In Webparts
1)Declare SPSecurityTrimmedControl
SPSecurityTrimmedControl stcEditItem = new SPSecurityTrimmedControl();


2)Define Controls in WebPart
protected override void CreateChildControls()

{

stcEditItem.ID = "idPrm";

stcEditItem.Permissions = SPBasePermissions.ManageWeb;

ltrPopup.ID = "ltrPerm";

stcEditItem.Controls.Add(ltrPopup);

this.Controls.Add(stcEditItem);
}
3)Render the Trimmed Html contents,Now these content are available to administrators only


protected override void Render(HtmlTextWriter writer)

{

StringBuilder sb = AddModalPopUp(SPContext.Current.Web);

ltrPopup.Text = sb.ToString();

stcEditItem.RenderControl(writer);

}
Using in Visual Webpart
Open the .ascx file and add the controls inside SPSecurityTrimmedControl
SharePoint:SPSecurityTrimmedControl ID="ctrlSecurityTrimmed" runat="server" Permissions="ManageWeb">
controls. here..
SharePoint:SPSecurityTrimmedControl>

'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">

Friday, September 2, 2011

To Position the Modal Popup Correctly...

Override the following css class and update the refering css file
.ms-dlgContent

{
position:fixed !important;
}
or use CSSRegistration.Register("_/layoout%Path%..") method (in CreatechildControl for Webpart/Prerender for usercontrol).

Friday, August 5, 2011

WebEventReceivers on Publishing Custom Site Template

To Get the Publishing custom site template
type in browser   http://server:port/sites/publishingsite/_layouts/savetmpl.aspx
and save the template.

Prerequisites for Restoring Publishing Custom Site Template without errors
 1)Error for activating feature with specific guid
    If  you restore the Publishing template on  any other non-publishing site collection ,you will get the error for activating feature with specific guid.
To avoid this ,restore this site template in publishing site collection only.

Still if you are getting the error,
Open the WSP Package in Visual Studio 2010
Search for Onet.xml in the solution.
Ctrl+F Find the featureId for which you are getting error.
Activate it in Parent site collection and You are done.

2)Web Page not found error when subsite is created using publishing custom site template.
Write the event Web Event Receiver to set the welcome Page

public class EventReceiver1 : SPWebEventReceiver

{

public override void WebProvisioned(SPWebEventProperties properties)

{
base.WebProvisioned(properties);

SPWeb web = properties.Web;
if (properties.Web.MasterUrl.Contains("MasterPageNameofcustomTemplate") )

{

web.AllowUnsafeUpdates = true;

SPFolder rootFolder = web.RootFolder;

rootFolder.WelcomePage = "sitepages/customwelcomePage.aspx";

rootFolder.Update();

web.AllowUnsafeUpdates = false;

}

}

If you know the better approach to attach event receiver to particular site template only please add the comment

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.

Tuesday, July 12, 2011

Comparing the old value and new value in Itemupdating Event

In Itemupdating event Of SPItemeventReceiver class

properties.ListItem["column name"]  gives the old value (b4 updating)
properties.AfterProperties["column_0x0200_name"]  gives the new value (after updating)

where column_0x0200_name is the internal name of column.

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

Friday, April 15, 2011

Writing Code Behind for MenuItems defined in Custom Action

A)

When ever you want to  add the application page to Particular location in sharepoint site
Get the reference of this site
http://www.customware.net/repository/pages/viewpage.action?pageId=69173255
for example


To add code behind, You need to inherit  the class from MenuItemTemplate, and to Capture the Postback events inherit for Interface IPostBackEventHandler
public class MyListSiteActionMenu : MenuItemTemplate, IPostBackEventHandler
{
public MyListSiteActionMenu()
{
this.ID = "myOwnIdHura";
}

protected override void CreateChildControls()
{
this.Text = "Delete Item";
this.Description = "Deletes Item";
this.ClientDEFANGED_OnClickPostBackConfirmation = "Are you sure you want to delete this item?";
this.ClientDEFANGED_OnClickUsingPostBackEvent = this.ID;
}

public void RaisePostBackEvent(string eventArgument)
{
SPContext.Current.ListItem.Delete();
SPUtility.Redirect(SPContext.Current.List.DefaultViewUrl, SPRedirectFlags.Default, this.Context);
}
}

Some more links  adressing postbacks of  Menuitem template
http://www.dev4side.com/community/blog/2010/3/9/implement-postbacks-in-the-spmenufield-sharepoint's-control.aspx

B)Modifing the text of the MenuItem depending on  Custom List Property value
in 

Psedo Code as follows
CreateChildControl()
{
 //Code to display text of  menuitem depending on Custom List Property value
set the text of menuitem  according to property of list 
} 

RaisePostBackEvent(string eventargument)
{
//updated list Propery on menuitem click
list.rootfolder.Addproperty();
list.rootfolder.SetProperty() ;
} 





Tuesday, February 1, 2011

How to enable Powershell’s Integrated scripting environment for running Sharepoint 2010

Run following commands on powershell
Import-Module ServerManager; Add-WindowsFeature PowerShell-ISE
alternatively
Search for server manager and add this feature as follows


Configuring ISE for sharepoint
• Copy or type the following text in the Command Pane (View > Go to Command Pane) and press ENTER:


# Creates a local user PowerShell ISE profile

if (!(test-path $profile ))

{new-item -type file -path $profile -force}

# opens it for edit

psEdit $profile

• Running these commands will open a new script file in the Script Pane. Type the following commands in the script file and save it by clicking the Save button on the toolbar:

# Copy the following into the new file and save it

cd 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration'

.\SharePoint.ps1

cd \

From now on, the SharePoint cmdlets will automatically load every time you start Windows PowerShell ISE as the same user. If you are still having problems using it, you may need to run it as an Administrator by right-clicking the shortcut and selecting Run as administrator (you can also force it to run as an administrator every time by right-clicking the shortcut, selecting Properties and then the Advanced button).

Tuesday, January 11, 2011

How to Create the Sharepoint 2010 Projects Where MOSS 2010 is not Installed?

Hello EveryOne,

        This article is just for knowledge sake and  to know about managing on machine where sharepoint 2010 is not installed.
If you have installed VS2010(visual studio ultimate) ,& Navigated as  Start ->VS2010 ->Run as administrator->New Project->Sharepoint 2010. You will get the popup that you can not create the sharepoint projects as MOSS 2010 is not installed.


But dont fear,If there is Will , there is Way :-)
Follow me as follows
1)Start -->Run-->RegEdit-->Select HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0

and Export the file
and Import on  machine where SP2010 is not installed.
2)Now you wont get the popup but it will ask for the url in Wizard.
still go ahead. and put the IP address of the remote server or any dummy url.
and dont click on validate url  and click on finish

3)With this settings you can just  create the wsp but once you click on the Deploy the project
then again You have to face the same error that 'Sharepoint is not installed on local machine'

4)You can put your commands in a PowerShell script (.ps1) file and pass the path of the script file to PowerShell.exe.  Then you can just put this command in your post build event to run your PowerShell script after you compile

5)This will hold the command which will be executing on the remote machine where Sharepoint 2010 is installed.
to enable the remote execution of powershell commands follow the steps as given in this blog

6)If you get 'Access Denied error' while execution of PS commands, then check if Active directory domain services is enabled on Target machine


Thursday, January 6, 2011

How to Import CSV files to Term Store in Sharepoint 2010

1)Go to the term strore as directed in following Image


Click on view sample Import file  and Import it back.
This will generate the terms for tagging
Next I will demonstrate  how to use tagging..

2)Create the list with column of Type Managed Metadata as directed as following Image
3)When List is created and You add/update new items this column will have the ability to Select values from term store