Wednesday, August 31, 2011

"User Information List" instead of "UserProfileManager"

For all those friends who were trying to find out an option for "UserProfileManger" to get the information of user, I found "User Information List" on the root. I am still not sure if it gets sync directly to the active directory or any other user list. But will write a blog on this in future once i find it.

Tuesday, August 30, 2011

Sharepoint 2010 deploy .webpart file Custom Group instead of Miscellaneous.

Goal
To deploy a web part using Module in Visual Studio project. The webpart should be deployed in group custom name "MBD Web Parts" and not in "Miscellaneous".

  • Open Visual Studio 2010.

  • File > New > Sharepoint > Empty Sharepoint Project > Name it "Sample"

  • Right click project > Add a Module > Name "Something".

  • Remove Sample.txt. Add a file(DemoWebPart.webpart) to the module.

  • Make the below given changes to the "Element.xml".

  • Right click project and deploy.

  • Visit your website.

  • Site Actions > Edit Site

  • Click "Add a Web Part". On the top ribbon.


You should now be able to see webpart in "MBD Web Parts" and not in "Miscellaneous".

Change in Element.xml



<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module List="113" Name="Something" Url="_catalogs/wp">
<File Path="Something\DemoWebPart.webpart" Url="DemoWebPart.webpart" Type="GhostableInLibrary">
<Property Name="Group" Value="MBD Web Parts" />
</File>
</Module>
</Elements>


Hope this is helpfull for you!

Sharepoint 2010 Deploy visual web part to "MBD Web Parts" instead of "Custom".

Goal
To deploy our custom visual webpart to a custom group name "MBD Web Parts" instead of getting deployed to "Custom". Please follow below given steps to see how to reproduce.

  • Open Visual Studio 2010.

  • File > New > Sharepoint > Visual Web Part > Name it "Sample"

  • Delete the "VisualWebPart1"(Default) and add a new Visual Web Part file "DemoWebPart".

  • Complete writing code.

  • Right click project and deploy.

  • Visit your website.

  • Site Actions > Edit Site

  • Click "Add a Web Part". On the top ribbon.


This will show up our web part in the Group name "Custom", but we need to the web part in a group name "MBD Web Parts".

Simple Solution


  • Expand "DemoWebPart" and open "Element.xml".

  • Modify an attribute value in the xml from "Custom" to "MBD Web Parts".

  • Right click project and deploy.

  • Visit your website.

  • Site Actions > Edit Site

  • Click "Add a Web Part". On the top ribbon.


You should now be able to see our custom category of "MBD Web Parts" and not in "Custom".

Change in Element.xml


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Module Name="DemoWebPart" List="113" Url="_catalogs/wp" RootWebOnly="TRUE">
<File Path="DemoWebPart\DemoWebPart.webpart" Url="DemoWebPart.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="MBD Web Parts" />
</File>
</Module>
</Elements>



Hope this is helpfull for you!

Problem creating or deleting Sharepoint List in Visual Web Part's Feature Receiver when called from stsadm or powershell.

Summary of Issue.

Working Process
In a Visual Studio Web Part, I was trying to create a Sharepoint List using a Feature Receiver Event. Every thing works fine when I deployed the solution using Visual Studio 2010.

Problem
I tried deploying the solution using STSADM Command or Powershell scripts. The deployment went fine but the Sharepoint List was not getting created. After research I found out the issue was in the activation code. I was using SPContext.Current.Web.Url. Now the correct way to do this is mentioned below.


If the Feature Scope="Web"


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb _web = (SPWeb)properties.Feature.Parent;
});
}



If the Feature Scope="Site"


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPSite _site = (SPSite)properties.Feature.Parent;
});
}



Hope you find this helpfull. Please comment if you have any queries.