Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Wednesday, November 5, 2014

Get web part assembly name and type name from SharePoint web part gallery


Today i was trying create to custom webpart preview page as test canvas for site admins. For this i wanted to add webpart on fly.  We need few properties like web part type name and web part assembly name for this.



string webPartTitle = " Content Editor Web Part";
string webPartTypeName = string.Empty;
string webPartAssemblyName = string.Empty;

SPList wpGallery = SPContext.Current.Site.GetCatalog(SPListTemplateType.WebPartCatalog);

SPQuery wpQuery = new SPQuery();

wpQuery.Query = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + webPartTitle + "</Value></Eq></Where>";
SPListItemCollection items = wpGallery.GetItems(wpQuery);

if (items != null && items.Count > 0)
{
       webPartTypeName = items[0]["WebPartTypeName"].ToString();
       webPartAssemblyName = items[0]["WebPartAssembly"].ToString();
}

Some other useful properties are below

- WebPartDescription
- WebPartPartImageLarge
- LinkWebPart
- WebPartIcon
- Group
- QuickAddGroups

Tuesday, July 17, 2012

SharePoint Server 2013 released in preview along with Pro and Developer training materials

Today is good news for SharePoint professionals, finaly Microsoft released SharePoint new version that is SharePoint Server 2013 in preview edition, though it's preview we get chance to look into it and play with new features

Here below are few usefull links

SharePoint 2013 new features and capabilities

SharePoint 2013 training for developers

What's new for developers in SharePoint 2013

Download Microsoft SharePoint Server 2013 Preview

Tuesday, January 10, 2012

Find all ContentByQueryWebParts from the page programatically

Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager manager = web.GetLimitedWebPartManager("Pages/default.aspx", PersonalizationScope.Shared);

foreach (Microsoft.SharePoint.WebPartPages.WebPart webPart in manager.WebParts)
{
 string type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0,   Culture=neutral,    PublicKeyToken=71e9bce111e9429c";

 Type type = webPart.GetType();
 if (type.FullName.Contains("ContentByQueryWebPart")
 {
  //then it is ContentByQueryWebPart
 }
}

Friday, August 19, 2011

Unable to open SharePoint site on host machine

Few weeks back, i created one SharePoint site means a web application using Central Admin. One thing which i did different from usual is Host hearder entry. After creating site i tried to open it using host header or say fully qualified name but i couldn't open it on my local machine but though i can open it from other machines.

Also one more problem i was facing at the time of creating new SharPoint project from Visual Studio 2010. Error like below
Cannot connect to SharePoint Site: http://<sitename>/. Make sure that this valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL Property of the project.

One of my friend gave me this useful link that i am sharing with you

http://support.microsoft.com/kb/896861

To create/open project in Visual Studio try to use host header URL not machine name or localhost.

Thursday, May 5, 2011

Sharepoint: User Type field in schema.xml

I was writting schema.xml for Custom List Template, there i need field of type User like below


I was setting value of ShowField property to Job Title which i was using in CAML query to filter out the users. I searched lot for ShowField values of User type but i coudn't found anything from MSDN, even not an expected results from google. I am very much habitual of seeing the View Source of the HTML pages so i see the page source of Task list's User column and i got all the values from that source. I think looking out HTML pages source is not a bad practice :)

Friday, April 22, 2011

Webpart Preview Page: Event handler not firing in webpart

Today i faced realy strange issue with button event handler in webpart, my webpart created from SharePoint webpart class. This is code

public class MyFirstWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
 Label userName = new Label();
 Button button;

 protected override void CreateChildControls()
 {
  button = new Button();
  userName.Text = "Sandip";
  button.Text = "Change this text";
  button.Click+=new EventHandler(button _Click);
  this.Controls.Add(userName);
  this.Controls.Add(button);
 }

 protected void button _Click(object sender, EventArgs e)
 {
  userName.Text = "Sandip Patil";
 }
}

I wired up event handler in CreateChildControls method so that was not an issue. Issue is with testing webpart on the page. I was testing webpart on webpart preview page. You can find webpart preview page whenever you select any webpart from webpart gallery page. After 1 hour of wasting time, i created one webpart page and put that webpart inside webpart zone. Thereafter i could see that event handler was firing. Means problem was not with the code but with testing scenario.
Be careful when you test webpart on Webpart Preview page.
Good Bye, Have a nice time...!

Friday, March 11, 2011

What is new in Visual Studio 2010 for SharePoint Developer?

Many of us are curious about new features of VS 2010 for SharePoint, Microsoft has provided good articles about this on their official site but we couldn't find this easily because keywords are not well defined for this entries.

First checkout the informational

What's New in SharePoint Development

then watch below video

Visual Studio 2010 for SharePoint 2010 Development

Enjoy SharePointing...!

Saturday, February 26, 2011

SharePoint 2010: Choice column not supported in lookup

One of the issue or we can say a bug that i found in new SharePoint 2010 version and it is confirmed from Microsoft team.

Issue is like this,

If you try to create a lookup column and select list from which you are setting lookup column, you will not get choice field columns in primary as well as secondary fields. For testing purpose take Task list and check the fields in dropdown as well as checkbox

ID
Title
Modified
Created
Version
Title (linked to item)
% Complete
Start Date
Due Date


You never get Priority and Status columns

On one of the Microsoft blog, i found a post where they say it is supporting but it's not true, Here below it is

Create list relationships by using lookup and unique columns

get confirmation from this post

Restrictions on additional columns available for addition with Lookup column?

Hope in upcoming hotfix this bug will be solved...!


Thursday, February 17, 2011

Awarded Microsoft Community Contributor

Hi Friends,

Today i have been awarded as Microsoft Community Contributor, Thanks Microsoft and all Friends/Microsoft Community Members who trust on me and my contributions.


Saturday, January 1, 2011

Deploying webpart in SharePoint


We can deploy webpart to SharePoint site either deploying assembly to BIN or GAC.

Some steps are mandatory for this

Steps
1: Put assembly in web application BIN or WFE's (Web Front End Server) GAC
2: Register assembly as safe control in web.config of web application
3: Add .webpart file into webpart gallery

Let's see master's(Andrew Cornell) quote on this 3rd point
In order to make the Web Part discoverable, or enable users to pick the Web Part from a list of available Web Parts, a Web Part definition file must exist in one of two places: the Web Part Gallery in a top – level site of a site collection or the wpcatalog folder within the Web root of a site ’ s hosting Web application. If the Web Part definition is deployed to the wpcatalog folder, all sites within all site collections within the Web application will have access to the Web Part. However, if the Web Part definition is added to the Web Part Gallery, a special document library in the top - level site of a site collection, only the sites within that site collection will be able to add the Web Part to their pages.
In this post we will concentrate on deploying webpart only to BIN.

A) Manual Deployment

A.1: Add webpart assembly (<WebPartName>.dll) to Bin directory of web application
Web application path would be C:inetpubwwwrootwssVirtualDirectoriesPort_No
A.2: Add Safe control entry to web.config file of web application

Example.

<SafeControl Assembly="<WebPartName>" Namespace="<WebPartName>" TypeName="*" Safe="True" />
OR

<SafeControl Assembly="<WebPartName>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="<WebPartName>" TypeName="*" Safe="True" />

A.3: Add webpart to webpart gallery
Here we will not add any .webpart file to webpart gallery but this task will done by SharePoint itself. See how this is done.

Go to webpart gallery from "Site Actions". Click "New" and select your webpart assembly and populate it. This action actually create .webpart file for you webpart.
You can see this file content too. Click on "Edit" button in front of webpart in galley, then click "View XML" and save .webpart file. Open this file in notepad and see the xml markup.

A.4: Use webpart
Now open webpart page, edit it and put webpart in webpart zone.

B) Deployment by WSP package

B.1: Create solution for deployment
Create separate class library project in same solution which is totally a dummy project, we will not use it's assembly for deployment but it will help us to make deployment structure. Add one folder named "Defination" then copy your webpart assembly(DLL) there.

B.2: Create one text file and save it as manifest.xml, manifest file is actually a instruction file to STSADM utility which tells him where to place the files on server.
manifest.xml

<Solution xmlns='http://schemas.microsoft.com/sharepoint/' SolutionId='A54EF786-3131-4f6c-AF90-A7116DF2B814'>
<Assemblies>
<Assembly DeploymentTarget='WebApplication' Location='sandip.helloworldwebpart.dll'>
<SafeControls>
<SafeControl Assembly="sandip.helloworldwebpart" Namespace="sandip.helloworldwebpart" TypeName="*" Safe="True" />
</SafeControls>
</Assembly>
</Assemblies>
</Solution>
Above schema tells to STSADM that put my webpart assembly (sandip.helloworldwebpart.dll) into BIN folder of respective application and add safe control entry into web.config file of that application.

B.3: Create one text file and save it as inst.ddf, ddf(data definition file or diamond directive file) file is actually a instruction file to makecab utility which tells him how to create a package.
inst.ddf
 .Set CabinetNameTemplate="sandiphellowworldwebpart.wsp"
 .set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
 .Set CompressionType=MSZIP;** All files are compressed in cabinet files
 .Set MaxDiskFileCount=1000 ; Limit file count per cabinet
 .Set UniqueFiles='OFF'
 .Set Cabinet=on
 .Set DiskDirectory1="../Defination"
 manifest.xml
 sandip.helloworldwebpart.dll
Above schema tells to makebcab that create package of name “sandiphellowworldwebpart.wsp", put manifest file and assembly to root of
WSP package and save it into current directory.

B.4: Create WSP package
Open command line and go to Defination folder of your deployment project
C:Documents and Settingssandip.patilMy DocumentsVisual Studio 2008ProjectsWSSsandip.helloworldwebpartDeploymentDefination>
and run this command

makecab /f inst.ddf

Now you will get package in same folder. To confirm files in WSP package, copy/paste package(.wsp) file on same directory and change extension to .cab. Open cab file and see 2 files (manifest.xml, sandip.helloworldwebpart.dll) should be there.

B.5: Create deployment/retraction file
Deployment file will add package to solution store and deploy to respective application.
Retraction file will retract solution (delete webpart from BIN and safe control from your web application) and delete solution from solution store.

DeploySolution.cmd
 :begin
 @echo off
 set solutionName=sandiphellowworldwebpart
 set url=http://sandip:6666
 @set PATH=C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN;%PATH%
 echo --- Adding solution %solutionName% to solution store...
 stsadm -o addsolution -filename %solutionName%.wsp
 echo --- Deploying solution %solutionName%...
 stsadm -o deploysolution -name %solutionName%.wsp -url %url% -immediate -allowCasPolicies -force
 stsadm -o execadmsvcjobs
 if errorlevel == 0
 echo ### Error deploying solution %solutionName%
 echo .
 goto end
 
RetractSolution.cmd

 :begin
 @echo off
 set solutionName=sandiphellowworldwebpart
 set url=http://sandip:6666
 @set PATH=C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN;%PATH%
 echo --- Attempting to deactivate/retract existing solution...
 stsadm -o retractsolution -name %solutionName%.wsp -url %url% -immediate
 stsadm -o execadmsvcjobs
 stsadm -o deletesolution -name %solutionName%.wsp -override
 rem stsadm -o execadmsvcjobs
B.6: Deploy solution package and confirm it
Double click DeploySolution.cmd and see webpart assembly(DLL) in your web application BIN and safe control entry in web.config too. You can see there is minor difference in safe control entry which is placed by there by STSADM and our manifest file entry.

<SafeControl Assembly="sandip.helloworldwebpart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=48cc2196eaf8dbe7" Namespace="sandip.helloworldwebpart" TypeName="*" Safe="True" />

Don't worry about this change.

B.7: Add webpart to webpart gallery and use it.
When we deploy webpart using WSP package without feature, our .webpart file is placed into wpcatalog directory in the application.
Path could be C:inetpubwwwrootwssVirtualDirectoriesPort_No
This insure that our webpart will available in all site collections of the application and ready to use, Follow A.4 steps to use webpart on the pages.

B.8: (Optional)Retract solution package and confirm it
If you don't need this solution then retract it by running RetractSolution.cmd file.
Double click RetractSolution.cmd and see webpart assembly(DLL) in your web application BIN and safe control entry in web.config has been removed.

Thursday, December 30, 2010

Introduction to Webparts in Sharepoint

About WebParts


Microsoft first introduced Web Parts in Windows SharePoint Services (WSS) 2.0. Information workers and developers quickly adopted Web Parts because they enable end users to modify the content, appearance, and behavior of pages through a browser.
Not only could users easily modify the content and experience with the browser, but they could also modify pages for just their own experience, rather everyone ’ s shared experience. Web Parts became so popular that the ASP.NET team decided to add a Web Part Framework to ASP.NET 2.0. The ASP.NET 2.0 implementation is different from the WSS 2.0 implementation in that ASP.NET 2.0 adds a new component to the page: the WebPartManager . The WebPartManager control is responsible for managing all aspects of Web Parts on the page. It knows what Web Parts are allowed on the page, what Web Parts are already on the page and which Web Part zones they are in, any connections that have been established between two Web Parts, as well as the personalization data for each Web Part. Personalization data contains all the settings, or values, set on the public properties, for a Web Part. This is very different from the WSS 2.0 Web Part Framework in that each Web Part maintained its own connection and personalization information and Web Part zones managed which Web Parts were in each zone.

What happens when a Web Part is added to a Web Part zone?


SharePoint adds some XML to the Web Part zone that contains information about the assembly
containing the Web Part and the Web Part class itself. This XML also contains the values of the public
properties on the Web Part class.

<WebPart xmlns=”http://schemas.microsoft.com/WebPart/v2” xmlns:iwp=”http://schemas.microsoft.com/WebPart/v2/Image”>
<Assembly> Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c </Assembly>
<TypeName> Microsoft.SharePoint.WebPartPages.ImageWebPart </TypeName>
<FrameType> None </FrameType>
<Title> Watch My Gears Run </Title>
<iwp:ImageLink> /_layouts/images/GEARS_AN.GIF </iwp:ImageLink>
</WebPart>

This XML, shown in above, is then stored as personalization information for a specific user (if the personalization scope is set to User) or for all users who access the page (if the personalization scope is set to Shared) depending on the mode of the page. The next time a page is requested, SharePoint loads the personalization information for the Web Part, which tells it which class to load from which assembly and the values of the public properties to set on that class. The Web Part is then loaded within the ASP.NET 2.0 page life cycle, which generates the rendered HTML output.

WebParts Base Classes


Microsoft has provided two base classes from which developer can create custom web parts
ASP.NET 2.0 — System.Web.UI.WebControls.WebParts.WebPart
WSS / SharePoint 3.0 — Microsoft.SharePoint.WebPartPages.WebPart

Why to use ASP.Net web part class not SharePoint web part class?


When creating a new Web Part, Microsoft ’ s recommendation is to always create ASP.NET 2.0 Web Parts instead of SharePoint - specific Web Parts. Web Parts created from ASP.Net web part class (System.Web.UI.WebControls.WebParts.WebPart) are fully supported in Windows SharePoint Services, and can be used not only in ASP.NET applications but also in Windows SharePoint Services too. The SharePoint web part class was designed specifically for SharePoint sites, and Web Parts that inherit from this class can be used only in Windows SharePoint Services sites.
When creating new Web Parts, you have the option of creating Web Parts that inherit from System.Web.UI.WebControls.WebParts.WebPart (recommended) or Microsoft.SharePoint.WebPartPages.WebPart. The Windows SharePoint Services WebPart class exists primarily for the purpose of backward compatibility (Web Parts written for Windows SharePoint Services 2.0 continue to work in Windows SharePoint Services 3.0 without modification).

References
Professional SharePoint 2007 Web Content Management Development
Webpart Class

Saturday, August 21, 2010

Benefits of detaching publishing page from page layout

In the publishing feature of Sharepoint every page must be derived from the page layout. This page layout actually decide the look and feel plus contents of the page, so if u use one layout more than a page then it is difficult to manage the look and feel because if u make change in page layout then this changes are automatically reflected on all the pages which using this page layout.
Sharepoint designer has given one nice functionality to detach the page from it's layout. By detaching page from it's layout, page got a following benefits.

  • All the content fields and page fields can be used on the page.

  • Use any designs templates to the page,this will not affect to other pages.

  • Getting advantage of using DataView, FormView webparts etc.


That's all here.