Microsoft Technology, .Net, BizTalk, Sharepoint & etc.

Liedong(Ken) Zheng, Senior SharePoint Developer at SIMPLOT

Posts Tagged ‘webpart’

Add Webpart zone on Masterpage in SharePoint

Posted by ken zheng on July 28, 2009

You know you can’t add a webpart zone into Master page directly, but there is tricky you can do it.

Just add

<asp:ContentPlaceHolder id="WeatherPart" runat="server"></asp:ContentPlaceHolder>

In the pagelayouts, set a control with the same id-name and place your webpartzone inside. You have to do this for every pagelayout that needs a header image in the masterpage. For each page though, there has to be added a image webpart, or whatever webpart you like. So be aware of this, if you use a webpartzone in your masterpage.

<asp:Content ContentPlaceHolderId="WeatherPart" runat="server">
    <div>
	<WebPartPages:WebPartZone runat="server" Title="WeatherPart" ID="WeatherPart"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
	</div>
</asp:Content>

Posted in Sharepoint | Tagged: , | 1 Comment »

DocumentExplorer WebPart Extenstion

Posted by ken zheng on April 24, 2009

Atidan Document Explorer for SharePoint is a tree-view control that displays your Microsoft® SharePoint site’s document library structure and content in the familiar explorer type view.

Document libraries and associated contents are presented in an intuitive, collapsible, hierarchical format.

The is a great control, but the problem is it displays all document libraries under site. Because it is using User Control and no property to set. So I decide to extend the web part which allow user specify the document library.

24-04-2009-4-30-23-pm1

You can download the source from here.

Posted in Sharepoint | Tagged: , | Leave a Comment »

Easily get to the WebPart Maintenance page for any Sharepoint Site Url

Posted by ken zheng on September 29, 2008

Symptom:

Often times, developers in WSS3.0/MOSS2007 probably run across the issue where a web part is dropped on to a page
and then Sharepoint errors out for one reason or the other. Sometimes, the user is directed to a Web Part Maintenance page,
which helps the developer remove the offending web part from the page.

However, there is no way to get to this page from any easily available link.

Resolution:

In order to get to the Web Part Maintenance page for ANY sharepoint url, try the following trick.

Append the querystring ?contents=1 to the url in the browser as shown below
http://portal/area/default.aspx?contents=1

Posted in Sharepoint | Tagged: , , | Leave a Comment »

Create a SharePoint WebPart calling Web Service

Posted by ken zheng on September 29, 2008

To call a WCF Web Service, your code needs to have a config file. To do this in Sharepoint 2007, you need to use the web application config file so you can edit the web.config file of that web application adding the bindings and the client sections to the system.serviceModel section making the web.config file will look something like that. Add ServiceModel seciton after configSections

WebPart Config

The way I did is to create a WCF in VS 2008. Hosted and create a webpart in vs 2008. Use the same way to add service reference and write some code. Remember always catch excpetion in webpart otherwise the whole page will not work. Deploy the web part and modify the web.config to add ServiceModel.

Posted in Sharepoint, VS2008 | Tagged: , | 2 Comments »

SiteList WebPart for SharePoint

Posted by ken zheng on September 26, 2008

This webpart will list all the sites you have permission to access.

Create a webpart project in vs 2005/2008,below is the source code:

[Guid("56d8a90d-8186-4333-b05d-f3b6b47a132c")]
    public class SiteList : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                SPWeb Web = SPControl.GetContextWeb(Context);
                SPWebCollection webs = Web.GetSubwebsForCurrentUser();

                if (webs.Count == 0)
                {
                }
                else
                {
                    SPTreeView siteTreeView = new SPTreeView();
                    siteTreeView.ExpandDepth = 10;
                    int i = 0;
                    foreach (SPWeb webToDisplay in webs)
                    {
                        siteTreeView.Nodes.Add(new TreeNode(webToDisplay.Title, webToDisplay.Url, "", webToDisplay.Url, ""));

                        TreeNode topNode = siteTreeView.Nodes[i];
                        ProcessWeb(topNode, webToDisplay);
                        i++;
                    }
                    Controls.Add(siteTreeView);
                }
            }
            catch (Exception ex)
            {
                Controls.Clear();
                Label errorMessage = new Label();
                errorMessage.Text = "There was an error in the code.  Please contact your system administrator and rely the following " +
                    "message: " + ex.Message;
                Controls.Add(errorMessage);
            }
        }

        private void ProcessWeb(TreeNode topNode, SPWeb subsite)
        {
            SPWebCollection webs = subsite.GetSubwebsForCurrentUser();
            foreach (SPWeb webToDisplay in webs)
            {
                topNode.ChildNodes.Add(new TreeNode(webToDisplay.Title, webToDisplay.Url, "", webToDisplay.Url, ""));

                 ProcessWeb(topNode, webToDisplay);

            }
        }
    }

Posted in Sharepoint, VS2008 | Tagged: , | Leave a Comment »

How To Debug WebPart in VS 2008

Posted by ken zheng on September 26, 2008

In some situations, it will be necessary to debug a web part. In order to make a WSS web part able to be debugged, the web.config of the WSS web site where you deploy your webpart to must be modified.

Open the Web.config file and modify the existing options to look like the following:

<customErrors mode=“Off” />

<compilation batch=”false” debug=”true“>

Once the web.config is modified, you can directly set breakpoint and hit F5 in a Visual Studio environment.

Posted in Sharepoint, VS2008 | Tagged: , | 1 Comment »

Create A WebPart in VS 2008

Posted by ken zheng on September 26, 2008

One of the tricky bits with developing WebParts using Visual Studio 2005 is the deployment aspects.

As mentioned in this article, you firstly have to create a strong-name key, and compile the DLL, load the assembly into the GAC, and include as a SafeControl.

There are STSADM scripts that can be used to do the same thing or you need to load your dll into Web Part Gallery

With the release of Visual Studio 2008, you can use SmartTemplate and WSPBuilder (Both available in CodePlex).

It registers the DLL in the GAC, adds the feature (installfeature) and activates the feature (WSP) for each chosen Web Application.

When the wizard completes, just have to flip back to SharePoint to turn it on for each particular Site Collection :

* Site Settings > Site Collection features > Activate

The WebPart will then be available from the WebPart gallery, and can be added to a page.

This is a great time-saver – making deployment of WebParts much easier.

You also can use Deploy function to deploy the dll for quick test.

There is a good example to show you how to do it. http://www.aspfree.com/c/a/Windows-Scripting/Beginning-SharePoint-Web-Part-Development/1/

But the problem is if you redeploy you may get error:
“This solution contains two assemblies with the same name, or the SharePoint server already has an assembly with the specified name.” when deploying a solution using the Visual Studio Extensions for SharePoint (VSEWSS) after you have already deployed it to a different site on the same server.

Answer:

Remove the solution’s assembly from the Global Assembly Cache (GAC).

· Gacutil /uf assemblyName (note: no .dll extension is specified)

· Rename or Remove the feature from “Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\FeatureName” (note: FeatureName may not be the same as assembly name – look in your manifest.xml to find the correct name)

If you deleted projects after you deploy the solution. You will get error as the manifest file still there.
Go to folder called pkg under your solution file folder and delete the folder which you have removed from solution

Posted in Sharepoint, VS2008 | Tagged: , | Leave a Comment »

SmartTools for SharePoint

Posted by ken zheng on April 20, 2008

Found 2 great webpart which can be used for learing purpose, you can download it from http://www.codeplex.com/smarttools

  • What’s New: a customizable web part that can display a list of recently added or changed items of a SharePoint site or site collection
  • Autocomplete Text Field: a field that allows users to pick items from a list by making use of an AJAX autocomplete text box. See the Autocomplete Text Field in action: screencast

 

What’s New Web Part screenshot:

WhatsNew0.jpg

Autocomplete Text Field screenshot:

AutoComplete2.jpg

 

Posted in Sharepoint | Tagged: | Leave a Comment »