Monday, October 10, 2011

Hide Breadcrumb Node in Breadcrumb Trail in SharePoint 2010

Hi, I came across a requirement that wanted to hide breadcrumb node in the breadcrumb trail.
I tried with navigation settings but it didn’t work out for me.Finally I landed up with JavaScript code.

My requirement was to hide “Department “from the following trail.

Home / Department / Labs / XYZ

So I used following JavaScript code for it.

script language="JavaScript"
var url = window.location.href;
if ((url.toString().indexOf("/Department /") > 0))
{
var breadNode = document.getElementById("ctl00_PlaceHolderTitleBreadcrumb_siteMapPath");
if ((breadNode != null) && (breadNode.childNodes[2] != null) && (breadNode.childNodes[3] != null))
{
breadNode.childNodes[2].style.display = 'none';
breadNode.childNodes[3].style.display = 'none';
}
}
/script


And following was the output:

Home / Labs / XYZ

For reference visit :
http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/0600ae0b-6925-483a-b5aa-6016f68c0d8b

Happy Coding :) :)

Tuesday, June 21, 2011

Open modal dialog (lightbox) with a hyperlink in SharePoint 2010


A new feature of SharePoint 2010 is the modal dialog which resembles the classic Light Box behavior. This allows us to add and edit items, manage Meta data and perform administrative tasks within the context of a page without leaving the page.

In just two simple steps we can implement this.
Step1:
In your Master page/aspx page add this tag for java script function to be called. For me I have added this in my master page.

script type="text/javascript">
var options = {
url: "/Lists/Announcements/NewForm.aspx", //Add your url u want to redirect your link to
title: "Add New Announcement", //Add title to your pop up window
allowMaximize: true,
showClose: true,
width: 625,
height: 525,
dialogReturnValueCallback: silentCallback
};
function open()
{
SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallback(dialogResult, returnValue)
{

}
function refreshCallback(dialogResult, returnValue)
{
SP.UI.Notify.addNotification('Operation Successful!');
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
/script>


Step2:
Add this href anchor tag on link you want to create.

a href="javascript:open()">Click Here
:) Happy Coding

Thursday, June 9, 2011

Create Blog sub site programmatically and set permissions of its parent site


public SPWeb Add(
string strWebUrl,
string strTitle,
string strDescription,
uint nLCID,
string strWebTemplate,
bool useUniquePermissions,
bool bConvertIfThere
)

Parameters

strWebUrl
Type: System.String

A string that contains the new website URL relative to the root website in the site collection. For example, to create a website at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a website one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.


strTitle
Type: System.String

A string that contains the title.


strDescription
Type: System.String

A string that contains the description.


nLCID
Type: System.UInt32

A 32-bit unsigned integer that specifies the locale ID.


strWebTemplate
Type: System.String

A string that contains the name of the site definition configuration or site template.
By default, a global site template (GLOBAL#0) is added to all site definitions. You cannot explicitly create a site based on a global site template.


useUniquePermissions
Type: System.Boolean

true to create a subsite that does not inherit permissions from another site; otherwise, false .


bConvertIfThere
Type: System.Boolean

true to convert an existing folder of the same name to a SharePoint site. false to throw an exception that indicates that a URL path with the specified site name already exists.



E.g.: For
Public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = properties.Feature.Parent as SPWeb;
CreateBlogSubsite(web);
}
catch (Exception ex)
{
}
}

private void CreateBlogSubsite(SPWeb site)
{

//useUniquePermissions true to create a subsite that does not inherit permissions from another //site; otherwise, false.

using (SPWeb blog = site.Webs.Add(strWebUrl,strTitle,strDescription,nLCID,
strWebTemplate,useUniquePermissions,bConvertIfThere,false, false))
{
blog.Update();
}
}

Wednesday, March 3, 2010

12 Hive in sharepoint

SharePoint development relies on “12-hive” folder and each who writes code for SharePoint uses that folder intensively. SharePoint uses that folder to store features, log, content types are other stuff.

12 hive folder structure is not private and you can find full description all folders in google, the core folders you should know about are the following:

\ADMISAPI - The directory contain the web service used used by the SharePoint Central Administration and appears as a virtual directory.
\BIN - The directory contains all the core binary files, utilities that are used by Windows SharePoint Services. Your command line tools such as STSADM.EXE reside in this folder
\BIN\LCIDD - A directory will be created for each language will be created that contains language specific binary files.
\CONFIG - This directory contains a set of configuration, binary and resource files used by SharePoint. Some files are the default values which will be copied to web site instances.
\DATA - SharePoint uses this directory structure for the indexing services where content will be indexed.
\HCCab\LCID - This directory has a set of cab files containing manifest and content information used by the SharePoint help sytem
\HELP - The folder contains a compiled html help file (.chm) used by the configuration wizard.
\ISAPI - This directory contains all the standard Web Services for SharePoint and some additional DLL’s, resources and configuration files that the web services use. Every web application provisioned in SharePoint will have a virtual directory strong>/_vti/_bin that points to this directory, thus giving each web application it’s own set of web services.
\ISAPI\HELP - This directory contains all the help files used by SharePoint. The folder also contains LCID sub directories for each language installed thus globalising the help system.
\LOGS - This is the directory that you will visiting frequently whilst doing development and administration as it contains the log files of what SharePoint did and what errors occurred.
\RESOURCES - This directory contains the core.resx file used for creating language packs for SharePoint. If you are going to be localising your SharePoint sites with different languages and cultures, this is the folder to do it in.
\TEMPLATE - This directory structure contains the core web site functionality in SharePoint, that is the features, templates, configurations, resources of a web site. What is important to note about this directory structure is that the Virtual Path Provider hides and masks this directory structure, thus it appears under each web site, list in a completely different structure

How to: Create or Delete Lists

To create a new list, use the one of the Add methods of the SPListCollection class.

The following example adds a new Generic, Events, or Announcements list, based on user input. A Switch clause is used to determine the type of list that the user specifies and sets the type of list template accordingly.



SPWeb mySite = SPContext.Current.Web;
SPListCollection lists = mySite.Lists;

string listTitle = TextBox1.Text;
string listDescription = TextBox2.Text;
string listType = ListBox1.SelectedItem.Text;

SPListTemplateType listTemplateType = new SPListTemplateType();

switch(listType)
{
case "Generic List":
{
listTemplateType = SPListTemplateType.GenericList;
break;
}

case "Events":
{
listTemplateType = SPListTemplateType.Events;
break;
}

case "Announcements":
{
listTemplateType = SPListTemplateType.Announcements;
break;
}
}

lists.Add(listTitle, listDescription, listTemplateType);