Showing posts with label MOSS Customization. Show all posts
Showing posts with label MOSS Customization. Show all posts

Sunday, October 4, 2009

MOSS 2007 Master Page DOCTYPE Issue

Hi All,
Today i would like to discuss an issue which i think most of us would have faced when we try to add a declaration in the top of the master page like:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


This is a standard declaration you will see on any aspx page and we all know why it is required.

But when you add this declaration in a SharePoint master page...you are inviting trouble..why..simply because of the reason that SharePoint master page is XHTML non-compliant.
You will ask me why you need a DOCTYPE in a master page?
Reason being the fact that i am using a AJAX modal pop up in the master page and we all know what happens when you add a ajax control in a master page without a doctype declaration..The page looks weird and the structure breaks from many places.

The only solution i know in this case is to choose from one of the following options:

1. Remove the AJAX modal pop up and hence the DOCTYPE declaration and use some other pop up . A javascript pop up may be
2. Keep the DOCTYPE declaration and modify the style of the elements whose structure is broken as an effect of adding doctype.

Hmm...you can't refuse clients requirement , and hence you have to go with option 2.

Consider for example after adding DOCTYPE the quick launch menu started looking weird, You tried changing the style sheet class attributes but no use.
The reason being the fact that the master page is no longer taking the out of the box style sheet classes like ms-navheader !
Follow the steps mentioned below and get rid of this problem:
1. Create a new class in your style sheet (Note: Do not make change in CORE.css)
and copy the attributes you were using previously in it e.g if the previous class name was ms-navheader then create a new class by name such as leftnavheader and copy the attributes under its declaration. Similarly create other classes.
2. Open the master page in the designer and replace the old class name with new one at all the places.
3. Save and publish the master page and you will see the changes are visible now.

Go ahead and follow the same procedure at all the places. I know its strange but can't help it.

If you have some better way of solving this issue or facing any problem understanding this post please let us know at sharepointkings@gmail.com

Happy Coding !!

Monday, September 28, 2009

Hide Content Place Holder Programmatically

I was working on replacing a control from the master page by a custom web part. Initially i commented everything inside the content place holder and added my web part. If you want to know how to add a web part in the master page, have a look at my previous post at :

http://www.sharepointkings.com/2009/09/add-web-part-inside-master-page-in-moss.html

Later on i moved the web part reference out of the content place holder and made the visible attribute of the content place holder to false.

But now the requirement is to dynamically turn it ON and OFF (i.e through code)

Lets follow the steps given below to achieve this:

1. Go to the page_load method of the web part.
2. Write the following lines of code.


if (!Page.IsPostBack)
{
ContentPlaceHolder contPlcHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderGlobalNavigation");
contPlcHolder.Visible = false;

//Rest of the code

}


If there is any nested content place holder then append that number of FindControl("ControlName") to the above code where we are finding the control.

That's it. Save the code and deploy the latest web part code.

If you are facing any issue then email us at sharepointkings@gmail.com

Sunday, September 13, 2009

Add Web Part inside a Master Page in MOSS 2007

Imagine that you are designing a master page for your MOSS site and you have a requirement to have a functionality that is not possible out of the box. You brain storm on it and concludes that only custom web part can solve your problem.
But now your concern is how you can make this custom web part as part of your master page?
It’s easy! Just follow the steps given below to add a web part inside a master page.

1. Deploy the web part in your web application as you do normally.
2. Check whether the web part is showing up in the web part gallery.
3. Create a web part page by navigating to the site settings, create web part page.
4. Add your custom web part on the web part page.
5. Start SharePoint designer and open the newly created web part page.
6. You will now find two entries corresponding to the web part you added on the page
i. In the page declaration you will find a entry which looks something like this:


<%@ Register TagPrefix="WpNs0" Namespace="MyNamespace.MyClass" Assembly=" MyNamespace.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"%>

ii. Click on the web part section in the page and you will see an entry like this:


<WpNs0:WebPartName runat="server" ID="g_34cdbb90_38c6_4561_9182_8fbc0d2423a6" ExportMode="All" Title="WebPartTitle" __MarkupType ……………..

7. Copy these entries in separate notepad, and close the page opened in the SharePoint designer.
8. Now open the master page in SharePoint designer and add the first entry in the declaration section and second entry at the place where you want to add the web part to.
9. Save the page, check in and publish it and that’s it. Your job is done.


Do let us know in case you are facing any issue following the steps mentioned.
You can email us at sharepointkings@gmail.com

Wednesday, April 29, 2009

Customize SharePoint Team Site Home Page

Hi All,
As part of most of the client requirements we need to customize the home page of the SharePoint team site. e.g Removing left hand quick launch, hiding header etc.
Here are some samples you can use to customize the home page. You need to add a Content Editor Web Part on the home page and make it invisible by unchecking the visible attribute.

1. Hiding Left Hand Quick Launch


2. Hiding the Page Title (Home) and showing the site title in bold and white color




3. Changing the background color of the title area frame




As you would have noticed that i have used the css classes used by SharePoint and overridden them. For a complete list of stylesheet classes refer:
http://www.sharepointcustomization.com/resources/tipstricks/wss_cssguide.htm
Most of the classes are used both in SharePoint 2003 and 2007 version.

Hope this will help.
For any other issue write to us at sharepointkings@gmail.com

Monday, November 17, 2008

Sharepoint Date time control rendering issue

Hi all,

We are using SharePoint Date time picker Control in Custom Field as well as in custom web parts.

The problem that we are facing is sometime calendar which is opening looks like there is no CSS applied to that control. But same control works in other list.

This is the rendering issue with Sharepoint date time control.

If we are using this date time control with asp.net ajax control then this control is defiantly not work properly.



So while surfing we find the solution on this site

This site says:
To fix the problem, drop the following line of code into %programfiles%\common files\microsoft shared\web server extensions\12\templates\layouts\iframe.aspx
<link rel="stylesheet" type="text/css"href="/_layouts/1033/styles/datepicker.css"/>

Put it right below the <HEAD> tag at the top, and the calendar should render correctly from now on.


We tried it and it work like a charm.
Again thanks to Rich Finn for his wonderful post.

Wednesday, November 5, 2008

How to remove Site Actions and View All Site Content

Hi all,

We had been asked so many times how to remove “Site Actions” or “View All Site Content” for certain users.

So finally we found one simple trick which will work for our system.

Problem statement: remove “Site Actions” or “View All Site Content” for certain user.

Work Around: to remove View All Site Contents and Site Actions we need to modify master page.

For us we are using custom master page. To know how to set custom master page as default master page check this Link .please try not to modify default.master page use custom one.

Removing Site Actions:
Open your master page in any editor like Visual studio (recommended) or notepad.
Find “SharePoint:SiteActions”.
If you opened it in Visual studio toggle the Site Action Control.
Check the screen shot.


Now add SharePoint:SPSecurityTrimmedControl control just before the SharePoint:SiteActions control
Check the screen shot.



Here is the text to add
<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ManageSubwebs">

<<SharePoint:SiteActions control>>

</SharePoint:SPSecurityTrimmedControl>

Now here is the description what we had done.

SPSecurityTrimmedControl as the name suggest, the control check the SharePoint permission and if user is permitted (if the user have permission) then it will access the content inside this control.
And if the user don’t have a permission then the content inside this control will not been accessed.

PermissionsString attribute define which set of permission can access the control.

You can give multiple permission by “,” (comma).
This “,” will work as OR condition to the permission set.
To check the permission set Enumeration check this link of MSDN

There is no other way to hide this buttons but we can do like this way.

Chose a permission from above msdn link like ManagePermissions or ManageWeb or DeleteVersions
the permission that your user don’t have.

And set it in master page.
Because our basic requirement is the END user should not see “Site Actions” and our END user must not have at least one permission from the permission list. Even contributor does not have all the permission.

So you are done by doing this you can remove site actions for non admin users without coding.

Removing View All Site Content:

Find “~site/_layouts/viewlsts.aspx” in the master page.

You will find Sharepoint:SPSecurityTrimmedControl is already there but the
PermissionsString attribute is set as “ViewFormPages”.

Which means that if a person have view rights in the form pages then that person can see this link.

You can also change PermissionsString to high permission like ManageSubwebs or ManagePermissions or something like that so that this link will also be removed if the login user don’t have permission mentioned in permissionstring.

Hope this will solve our basic problem which must have high priority for the clients.

Tuesday, June 17, 2008

Change default redirection in an ECB Menu

MOSS 2007 and Core.js File
Change default redirection in an ECB (Edit Control Block) Menu.

I am sure lots of people would be wondering how to Change default redirection in a ECB Menu items of a list eg On clicking the "Title Column hyperlink" or the ”View Item” in ECB(Edit Control Block) Menu, the redirection must be to a different location.

For this the modifications needs to be done in CORE.JS file located at "C:\Program Files\CommonFiles\MicrosoftShared\webserver extensions\12\TEMPLATE\LAYOUTS\1033\CORE.JS"


NOTE: Make sure you take back up of Core.js file before making any change in order to prevent any server functionality malfunction.


1) Clicking on Title Column hyperlink of a List Item
Default Sharepoint Navigation:
On clicking on the Title Column, SharePoint takes you to the DispForm.aspx page.

See below Image:


The default navigation is done by the function "GoToLink(elm)" present in core.js

Place alerts in the core.js and understand each of the parameters.
Eg. To navigate to a different page, assign the destination url to the targetUrl
String.


See below Image:




ECB(Edit Control Block) Menu Navigation.
2) Clicking on “View Item” of a List Item in the ECB menu
Default Navigation:
On clicking on the View Item in the ECB menu, SharePoint takes you to the DispForm.aspx page.

The default navigation is done using function “AddSharedNamespaceMenuItems(m, ctx)” in present in customcore.js

Place alerts in the core.js and understand each of the parameters.
Eg. To navigate to a different page, assign the destination url to the strAction
String.


Same as you did for the "Title Column hyperlink".

If you are confused....we kings are here...

Monday, June 16, 2008

Breaking long column names in moss

The scenario:
Recently I came across the requirement in which one of our lists has a very big name of the column.
So our look and feel is messed.

The Requirement:
Now what my requirement is I need to break this column name in two lines in “NEW” and “Edit” Mode.
Example- Name of the column is “this is very long name of the column and i want to splilt it“

The Challenge.
Now I have to find the way to break it!!!

First I tried to change the name from “this is very long name of the column and i want to splilt it”
To “this is very long name of<br>the column and i want to spilt it”

But failed. Because while rendering it replaces < to “& lt;” and > to “& gt;”

Now
What I had observer is that while checking in view source the name of the column is rendered in between <nobr> </nobr> tag.
So I there is no chance to break it with my first idea.

The Solution.
I found a strange way to resolve this.
What you have to is that do it with java script.

In java script while loading the page you have to find that label and change it with a BR tag manually.

I will tell you how to do it.
First you have to call java script in this page.
You can do that by
Creating a custom control using .aspx here is the way.
Or create a web part and put it on the list page.(Check This)
Note: for Creating a webpart with user control .ascx (go to this site)

In that .ascx of web part or custom control, you need to find all elements for <nobr>
And find the original text.
And replace this text means inner html of of<nobr> with new text which include <br>
So while rendering it breaks up even if it was on <nobr>.
Using simple JavaScript in SharePoint check this article

Here the sample java script.

// this is default SharePoint function
//it will call after page is loaded.
_spBodyOnLoadFunctionNames.push("split");


//this function finds all <nobr> tag
//then check our original text and
//replace new text which contains <br>
function split()
{
var oP = document.getElementsByTagName('nobr');//the collection of <p> tags
for(var i=0;i<oP.length;i++)
{
//alert(oP[i].innerHTML);
if(oP[i].innerHTML == "this is very long name of the column and i want to splilt it")
{
oP[i].innerHTML = "this is very long name of<br>the column and i want to splilt it"
}
}
}

Wednesday, June 4, 2008

Finding CSS in MOSS

While developing custom webpart, we always wonder for which style sheet class to use.
And try to find out by checking view source of the default page.

Here is the link for
CSS Reference Chart for SharePoint 2007 (Microsoft Office SharePoint Server 2007 and Windows SharePoint Services v3) by Heather Solomon.

This is the wonderful post by Heather Solomon which helped me to solve my many GUI and CSS related problems.

Tuesday, June 3, 2008

Custom Action Button on List's Tool Bar, WSS 3.0

Display a Custom Button say “Load Data” on the Toolbar of the Sales List

Solution:
In a Feature say “CustomContextMenu” we declare a Custom Action.

In the elements.xml file at “\CustomContextMenu\elements.xml” you will need to add this snippet.

<CustomAction Id="CustomContextMenu"
RegistrationType="List"
RegistrationId="10031"
Location="ViewToolbar"
Sequence="239"
Title="Load Data" >
<UrlAction Url="~site/PageFilter.aspx?ListId={ListId}&ItemId={ItemId}&SiteURL={SiteUrl}&Action=7"/>
</CustomAction>

Parameters values:

RegistrationType="List"

RegistrationId is the “Type” id found in the elementManifest.xml of the List on which you want to show the button. Here in our case if you open the elementManifest.xml of Sales List.
You will find that “Type” for this list is “10031”

Location="ViewToolbar". We want the Button to appear on the Tool Bar of the List.

In UrlAction mention the url where you want the control to navigate when you press the button.

Saturday, May 31, 2008

Giving Document level permission in a library

If you want to give separate permission to a folder inside a document library then do the following:
Go to the site settings --> advance settings.
Create a new Permission level and choose permissions which are not available previously with other permission levels.
After doing it go to the folder and choose 'Manage Permissions'.
Add the users you want to give access to . Edit Permissions of the selected users. Select the permission level just created.
Remove all the other users whom you do not want to give access to the folder.

Friday, May 30, 2008

How to use custom redirection page in SharePoint for custom navigation?

The requirement:
Create a page in SharePoint which will redirect you to specific location based on inputs.

All we need to reach at our custom page
For that you can use many ways like...
From Hyper link from quick launch.
From Edit Control Block.
From FormToolbar in List Add/Edit/Display mode and all that.
Click here to know how to do that.

What we need to do is that create a new ASPX page which will execute our custom code.

How to create a new aspx page in SharePoint with feature?
Here is a sample:
I will name this feature as “CustomRedirection”.
Here is the content of elements.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name=" CustomRedirection" Path="" Url="">
<File Url=" CustomRedirection.aspx" Type="Ghostable" IgnoreIfAlreadyExists="FALSE" />
</Module>
</Elements>


The Module element works same as Module element in Onet.xml.
This element useful for using files like webpart or custom page.
So this feature includes our CustomRedirection.aspx as part of site page.
Over here we are putting “Ghostable” page (physical aspx) with these feature.

how aspx looks like?
Here is the content of CustomRedirection .aspx page

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name=" MyCustomCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f3cc8bff1d91557" %>
<%@ Page Language="C#" MasterPageFile="~masterurl\default.master"
Inherits=" MyCustomCode. CustomRedirection "
EnableViewState="true" EnableSessionState="True" EnableViewStateMac="false" %>

<asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderMain" >
Test
</asp:Content>

You can find it out that in this page what we had done is that adding Microsoft.SharePoint assembly and our custom assembly, which contain code we want to executes) then one asp:content with id “ PageTitleInTitleArea” and contentplaceholderid as “PlaceHolderMain”. This content is used by master page.

Now question is
how our custom code executes when this page accessed?
You can see page derivatives in that we are specifying MasterPageFile and we are inheriting our own class (Inherits=" MyCustomCode. CustomRedirection"). So when this page called our custom code in class CustomRedirection.cs will call.
Note: Put your custom assembly as safe control in web.config.

And once we have our execution in code, we are the king.
We can do anything we want. like…
Fetch URL and check which Item from which list is clicked, redirect to its related page like sub site, related list, look up list, do some operation like creating sub site, creating multiple records anything according to your business requirement and then redirect back to same page or anywhere you want.
Here is a part snippet from my CustomRedirection.aspx

if (Request.QueryString["FROM"] == "ECB")
{
// find List id and Item id from URL
// use that data find item from list
// do manipulation according business logic

SPUtility.Redirect(strWebURL, SPRedirectFlags.Default, httpContxt);
}


Summary
1) Create an aspx page from feature and embed in the site.
2) Use page to place content.
3) Use page as middle way for seamless navigation.
Source page -> customeredirection page -> destination page.
4) Use page as a place where you can execute your code and comes back at your place again or you can go ahead.
5) Any many more way that may be I had not discovered yet.

We are using this feature mostly in custom navigation where we know source but don’t know the destination but we need to find destination with custom business logic and then redirect it.

Wednesday, May 28, 2008

How to set custom master page as default master page with site definition in Moss and WSS 3.0?

Changing a default master page for our custom need is not at all good idea and creating a custom master page and use it as default master page is a headache.

Here is the way to create and use your custom master page with site definition.

Go to “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL” where you can find default master page (default.master).

Copy that default.master and pest it with customdefault.master or your own custom name.
(Note: while copying default.master please take care that you must not have already modified It. Use a fresh copy)

Put your custom master page at same location as default.master.

Now go to “12\TEMPLATE\GLOBAL\XML” open “ONET.xml”

At the last you will find module tag which provision “default.master” same way add your entry for custom.master.


<Modules>
<Module Name="DefaultMasterPage" List="116" Url="_catalogs/masterpage" RootWebOnly="FALSE">
<File Url=" customdefault.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
<File Url="default.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
</Module>
</Modules>



This code will automatically put your custom masterpage into the masterpage gallery when a new site is created.

Now open your onet.xml file from 12/template/SiteTemplates
Change the default masterpage to the new one.
Find <Configuration> tag
Add MasterUrl attribute like MasterUrl=”_catalogs/masterpage/customdefault.master” and if you already have this tag change it with your custom master page.

So it will look like

<Configuration ID="0" Name="YOUR NAME" MasterUrl="_catalogs/masterpage/customdefault.master">



Now the new site created with this definition have this master page as default master page. Click here for more info.

What about already existing site?

For that you need to put master page manually and change master page url for each wab
Here is the code snippet (only for setting master page url of the web):
Note: use this snippet carefully. If you run this snippet and you do not have Master page in Master page gallery for that web you will get master or page not found error.


SPSite spsite = new SPSite("Your site name");
foreach (SPWeb Myweb in spsite.AllWebs)
{
string masterurl = Myweb.ServerRelativeUrl;
if (!masterurl.EndsWith(@"/"))
masterurl = masterurl + @"/";
Myweb.MasterUrl = masterurl + "_catalogs/masterpage/customdefault.master";
Myweb.Update();
}



This kind of snippet you will find in Inside WSS 3.0 book

Friday, May 23, 2008

How to edit list forms like NewForm.aspx, EditForm.aspx and DispForm.aspx in MOSS?

Most common question among SharePoint customization is that
“Why Edit Page option is not available in list forms like NewForm.aspx, EditForm.aspx and DispForm.aspx?”

If we need to edit New/Edit/Display Form of list most of the time we are using SharePoint designer.

But here is the one nice trick to achieve this functionality.

Just add “&ToolPaneView=2” at the end of the URL and refresh the page.

So that you’re URL will be like this.
http://sharepointkings/... /Lists/Demo/NewForm.aspx?RootFolder...&Source=…&ToolPaneView=2

http://sharepointkings/... /Lists/Demo/EditForm.aspx?RootFolder...&Source=…&ToolPaneView=2

http://sharepointkings/... /Lists/Demo/DispForm.aspx?RootFolder...&Source=…&ToolPaneView=2

You can see add webpart tool pan beside this web part.



Just add or remove your webpart and your work is done.
cheers

Below contents are Update as on 22/07/08

There is one more parameter with the same name just pass the value 3 with that.

So that you’re URL will be like this.

http://sharepointkings/... /Lists/Demo/NewForm.aspx?RootFolder...&Source=…&ToolPaneView=3


And that will take you to this type of page.



This will allow you to search webpart across all available galleries

Cheers once again...

Thursday, May 22, 2008

How to get igoogle and Google Talk on a Sharepoint Page


To get Google Talk on a Sharepoint Page:

Google Talk can now be added to your blog as a gadget.

Drag a ContentEditorWebpart on your SharePoint Page.
Click on the "Source Editor" button in the Toop Pane on the right side.
Past the following HTML stuff in the Source Editor dialog box:

<iframe width="234" frameborder="0" src="http://talkgadget.google.com/talkgadget/client?fid=gtalk0&relay=http%3A%2F%2Fwww.google.com%2Fig%2Fifpc_relay" height="350"></iframe>


The Google Talk Gadget lets you send instant messages, transfer files, make voice calls (to other Google Talk users) and leave voicemail messages. If you paste a Picasa Web Album or YouTube URL into a chat session, the gadget gives you an instant preview of the photos and videos.

To get any page say igoogle on a Sharepoint Page:

Drag a ContentEditorWebpart on your SharePoint Page.
Click on the "Source Editor" button in the Toop Pane on the right side.
Past the following HTML stuff in the Source Editor dialog box:

<iframe width="1000" height="500" frameborder="0" src="http://www.google.com/ig?referrer=ign" width="500" height="300"></iframe>


Below Image shows both implementations:



Try out the stuff here it self:


"Thoda Aur Wish Karo"

Wednesday, May 21, 2008

How to Implement Live Chat in Sharepoint

This feature of the Windows Live Messenger application enables you to actually add a web-based messenger to your site or blog.

Check out http://settings.messenger.live.com/applications/websettings.aspx to create one for yourself.

I will explain in brief.

Here http://settings.messenger.live.com/applications/WebSettings.aspx
you will see a setting for "Show your Messenger Status on the Web"

The checkbox "Allow websites to see your Messenger status and send you messages"
will allow any one to message you from the gadget.

You can place the gadget on any web page by copying the html code.


To get the HTML code click here
http://settings.messenger.live.com/applications/CreateHtml.aspx

At the bottom you will find these instructions.
"Copy the HTML and paste it into your webpage"

Open your sharepoint page in browser.
Drag and Place a ContentEditorWebPart there.
In it's Source Editor, Past the HTML Code that you have copied.

That's It. Dude now people can catch you and chat with you.
They from the Gadget and you from your MSN Messenger.



For Further Queries Begin a conversation with the "Kings" ;)
Chat Here

Thursday, May 8, 2008

Showing Administrator name instead of System Account

Many times we came across situation when instead of showing your name the site shows Welcome System Account or instead of your name in Modified by column it shows System Account. There is a way to change it. On the top of the page where you see Welcome System Account, click the drop down and click My Settings. There you will find an option to edit the item. Try to change the name from there.



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com