Monday, June 20, 2011

Hide recycle bin and content links from Left Nav in Shp 2010

In order to hide the recyle bin and view all site content links from the left nav in sharepoint 2010 follow the below procedure. You need to retain the left nav and all other links.

Find the master page v4.master or your custom master page and find head, above head add the following code:

STYLE
.s4-specialNavLinkList
{
display:none !important;
}
/STYLE

The two links will be hidden

Thursday, March 17, 2011

Deploy a web part using feature

Create a normal cs file for the web part. To deploy it, create 2 files in the feature folder - Feature.xml, elements.xml and webpart.webpart

wpchat.webpart---------------------------------------

webParts
webPart xmlns="http://schemas.microsoft.com/WebPart/v3"
metaData
type name="Eversheds.InstantMessaging.WebParts.WPChat, Eversheds.InstantMessaging, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=b0c7276684f0a390 "/type
importErrorMessageCan not import WPChat/importErrorMessage
/metaData
data
properties
property name="Title" type="string"IT Service Desk/property
property name="Description" type="string"A web part which allows the user to chat /property
property name="MissingAssembly" type="string"Cannot import this Web Part./property
property name="DisplayName" type="string"IT Service Deskproperty
property name="Name" type="string"ITServiceDesk/property
property name="AllowHide" type="bool"False/property
property name="AllowClose" type="bool"False/property
property name="ChromeType" type="chrometype"None/property
property name="AllowZoneChange" type="bool"True/property
property name="Hidden" type="bool"False/property
property name="AllowMinimize" type="bool"False/property
property name="AllowEdit" type="bool"True/property
/properties
/data
/webPart
/webParts

Feature.xml ---------------

?xml version="1.0" encoding="utf-8"?
Feature Id="D34D00B1-EC5C-4da8-8C50-009CB4B8BB42"
Title="IMCHATFEATURE"
Description="This is the chat Webpart"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
ReceiverAssembly="Eversheds.InstantMessaging, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=b0c7276684f0a390 "
ReceiverClass="Eversheds.InstantMessaging.FeatureReceiver.ReceiverChatFeature"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/"
ElementManifests
ElementManifest Location="elements.xml"/
ElementFile Location="WPChat.webpart" /
/ElementManifests
/Feature


Element.xml--------------------

?xml version="1.0" encoding="utf-8" ?
Elements xmlns="http://schemas.microsoft.com/sharepoint/"
Module Name="WebPartPopulation" Url="_catalogs/wp" RootWebOnly="TRUE" List="113"
File Url="WPChat.webpart" Type="GhostableInLibrary"
/File
/Module
/Elements

Deploy this using wsp and the web part can be added to the web part gallery.

Tuesday, March 1, 2011

Create custom page layout using Feature

If you want to create a custom page layout using features in your solution, use the below steps-

Create a folder structure as -

12----
Template---
Features------
ABCPageLayout---
layout.aspx
Feature.xml
Elements.xml

layout.aspx-----------------------------

First create the entire layout in sharepoint designer and copy paste into .net aspx file.


Feature.xml-----------------------------

Feature Id="8C463F26-AE3C-4309-A284-AC095EB351A9"
Title="ABCPageLayout"
Description="page layoutt for use"
Version="12.0.0.0"
Scope="Site"
Hidden="True"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/"
ElementManifests
ElementManifest Location="ProvisionedFiles.xml"/
/ElementManifests
/Feature

Elements.xml---------------------------------

Module Name="OSGPageLayouts" Url="_catalogs/masterpage" Path="PageLayout" RootWebOnly="TRUE"
File Url="ABCPageLayout.aspx" Type="GhostableInLibrary"
Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" /
Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/
/File


Deploy this as a feature and your page layout will automatically go to the sharpoint pagelayouts.

Feature to create page of a page layout type

In case you want to create a page of a certain page layout in your solution folder, Follow the below steps.

First create the page layout in your solution using feature. (Steps in another post)

Create a structure as below in your solution -

12 --
Template --
Features ---
Page123-----
Elements.xml
Feature.xml
TemplatePage.aspx


Elements.xml------------------------

Elements xmlns="http://schemas.microsoft.com/sharepoint/"
Module Name="PublishingHomePage" Url="$Resources:cmscore,List_Pages_UrlName;" Path=""
File Url="TemplatePage.aspx" Name="Welcome.aspx" Path="TemplatePage.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE"
Property Name="Title" Value="Online Services" /
Property Name="ContentType" Value="Article Page" /
Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/HomePageLayout.aspx, /sites/onlineservices/_catalogs/masterpage/HomePageLayout.aspx" /
/File
/Module
/Elements

Feature.xml----------------------------------

Feature Id="523E7D1F-052A-42e6-BD85-3ACFC82831EE"
Title="Page123"
Description="Home Page"
Version="1.0.0.0"
Scope="Site"
Hidden="True"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/"
ElementManifests
ElementManifest Location="Elements.xml"/
ElementFile Location="TemplatePage.aspx" /
/ElementManifests
/Feature

change the Feature id in your code.

TemplagePage.aspx--------------------- It is the normal templatepage in every site.

%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage, Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" %
%@ Reference VirtualPath="~TemplatePageUrl" %
%@ Reference VirtualPath="~masterurl/custom.master" %

Deploy this as a feature and your page is ready.

Window.Unload() not working in IE6

I was not able to get this simple thing working in IE 6. It worked on IE7 and IE8 and not on IE6. I found the below workaround.


SCRIPT FOR="window" EVENT="onunload"
alert("on unload");
/SCRIPT

This works without any problem.

Wednesday, January 19, 2011

Programmatically hide pages from Navigation

Suppose you are creating a page using Features, now you want that page to be hidden from the navigation when you create it. How will you go about it---

Create a Feature Receiver for that page and enter the below code at Feature activated event.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
PublishingWeb publishingWeb = null;
var objWeb = properties.Feature.Parent as SPWeb;
try
{
if (PublishingWeb.IsPublishingWeb(objWeb))
{
publishingWeb = PublishingWeb.GetPublishingWeb(objWeb);
// get the pages collection
PublishingPageCollection pages = publishingWeb.GetPublishingPages();

if (pages[publishingWeb.Url + "/Pages/chat.aspx"] != null)
{
//page exists hide it
PublishingPage page = pages[publishingWeb.Url + "/Pages/chat.aspx"];
page.IncludeInCurrentNavigation = false;
page.IncludeInGlobalNavigation = false;
}
}
}
catch (Exception ex)
{
using (StreamWriter w = new StreamWriter("C:\\log.txt"))
{
w.WriteLine(ex.ToString());
}
}
}

Wednesday, January 12, 2011

How to add a page in pages directory of Sharepoint site

Suppose you want to add a new page in the pages library of your sharepoint site programatically, how will you go about it.

Create the structure in your project -

12 - template - features - NewPageFeature -

In that create an aspx page, a feature.xml file and an elements.xml file

You will also need a cs file outside of the 12 folder, and will provide the path to the same in your aspx file.

Feature.xml ---------------------------------------------------------


Feature Id="94D273A9-B9AE-46f0-A56A-03289ACC87FF"
Title="IMCHATPAGE"
Description="Activate Chat Page"
Scope="Web"
Hidden="True"
xmlns="http://schemas.microsoft.com/sharepoint/"
ElementManifests
ElementManifest Location="Elements.xml"/
ElementManifests
/Feature


Element.xml -----------------------------------------------------------

?xml version="1.0" encoding="utf-8"? Module Name="Pages" Url="$Resources:cmscore,List_Pages_UrlName;" Path="" RootWebOnly="False"
File Name="Chat.aspx" Url="Chat.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="False" /
/Module
/Elements


.aspx file ---------------------------------------------------------

In your aspx file, include the path of you cs file like below -

Inherits="Eversheds.InstantMessaging.Chat, Eversheds.InstantMessaging,Version=1.0.0.0,Culture=neutral, PublicKeyToken=b0c7276684f0a390"

Run wsp builder and your page will be created in the pages directory of your site