Tuesday, December 14, 2010

Various ways to Deploy SharePoint WebParts

 There are several ways to deploy Webparts

Method 1 - manual
  • Copy assembly DLL to either
    - /bin directory for a given IIS virtual server (e.g., c:\inetpub\wwwroot\bin)
    - Global Assembly Cache (e.g., c:\windows\assembly)
  • Copy DWP file to C:\Inetpub\wwwroot\wpcatalog
  • Copy resources to
    - For GAC-registered parts, C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources
    - For Web Parts in the /bin directory, C:\Inetpub\wwwroot\wpresources
  • Adjust web.config
    - Register as SafeControl
    - Select Code Access Security settings

Method 2: CAB File
  • CAB file should contain
    -Assembly DLL
    -DWP file(s)
    -Manifest.XML
    -Resource files (if needed)
  • CAB won't contain
    - Code Access Security settings
  • Server-side object model has methods for deploying such a CAB file
  • Deploy with STSADM.EXE
    Located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN
    Add it to your path
    Stsadm -o addwppack -filename filename [-globalinstall] [-force]

Method 3: MSI File via WPPackager
  • All of the features of CAB file deployment, but with
    - Code Access Security support
    - Ability to uninstall via Control Panel
  • Get WPPackager.exe
  • Add additional files to project for use by WPPackager
  • Run WPPackager after project is built

Sharepoint Tips & Tricks

1. Deleting error occurred webparts in the portal

  If an error occurs like “An unexpected error has occurred.” and unable to open the design page and the aspx page in the site then follow the below step.


This can be done by adding “?contents=1” to default.aspx page.
 ex: http://myportal/default.aspx?contents=1


2. Adding Quick Launch to Custom webpart Pages


   To  display quick launch bar in Custom web part pages, all you need to do is simply remove couple of lines in the web part page by opening the page in the Designer.

<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>


Wednesday, December 1, 2010

Configuring host header for site in IIS 7.0

 

You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.

User Interface

To use the UI
  1. Open IIS Manager. For information about opening IIS Manager, see Open IIS Manager (IIS 7).
  2. In the Connections pane, expand the Sites node in the tree, and then select the site for which you want to configure a host header.
  3. In the Actions pane, click Bindings.
  4. In the Site Bindings dialog box, select the binding for which you want to add a host header and then click Edit or click Add to add a new binding with a host header.
  5. In the Host name box, type a host header for the site, such as www.contoso.com.
  6. Click OK.
  7. To add an additional host header, create a new binding with the same IP address and port, and the new host header. Repeat for each host header that you want to use this IP address and port.

Command Line

To add a host header to a Web site's binding, use the following syntax:
appcmd set site /site.name: string /bindings.[protocol=' string ',bindingInformation=' string '].bindingInformation: string
The variable site.name string is name of the site to which you want to add a host header. The variable [protocol='string',bindingInformation='string'] is the existing binding to which you want to add a host header, and bindingInformation string is the new binding with host header.
For example, to configure a site named contoso with an existing HTTPS binding for all IP addresses, on port 443, without a host header to have a host header named marketing, type the following at the command prompt, and then press ENTER:
appcmd set site /site.name: contoso /bindings.[protocol='https',bindingInformation='*:443:'].bindingInformation:*:443: marketing
For more information about Appcmd.exe, see Appcmd.exe (IIS 7).

Configuration

The procedure in this topic affects the following configuration elements:
<bindings> under <site> element

Sunday, November 14, 2010

Writing Server-side ( C# ) code in SharePoint custom pages

There are basically two approaches to write server side code:
A) Inline coding ( C# and HTML code in same ASPX page)
B) Code-Behind (C# and HTML code in seperate files)

A) Inline coding

1) In this approach, first you have to modify application's web.cofig file.
Locate PageParserPaths node in config file and then change it as per your requirement.

If you doesn't know page(s) name which is(are) using server side code, then write /* in VirtualParth attribute,
else write page name as /pagename.aspx in VirtualParth attribute.
[For each page add a seperate PageParserPath node,
for example you want to allow server side code in 5 pages then you have to add PageParserPath nodes.]




<PageParserPaths>
        <PageParserPaths>
        <PageParserPath VirtualPath="/Custom Webpart Pages/*" CompilationMode="Always"   AllowServerSideScript="true" />
      </PageParserPaths>
</PageParserPaths>




2) Write server side code as


<script runat="server">

protected void Page_Load(Object sender, EventArgs e)
{
    Response.Write("Server code in Sharepoint");
}

</script>

The above script
I placed  inside the PlaceHolderMain place holder.

B) Code-Behind approach

1) Create a C# file (or VB file) for your server code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyNameSPace
{
    public class MyClass : Microsoft.SharePoint.WebControls.LayoutsPageBase
    {
        //Server control declarations
        protected Label lblMessage;

        protected void Page_Load(Object sender, EventArgs e)
        {
            lblMessage.Text = "Server Code";
        }
    }
}



Points to remember:
- Inherits the class with LayoutsPageBase (there are other options also available for choosing base class)
- Declare ASP.Net server control with protected modifier.



2) Register the DLL (that contains above class) in GAC.

3) safecontrol entry in application's web.config file.

4) Create ASPX file for HTML code


<%@ Assembly Name="MyNameSPace, Version=1.0.0.0, Culture=neutral, 
       PublicKeyToken=bf118dafb4e11f4b" %>
<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" 
       Inherits="MyNameSPace.MyClass" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Label runat="server" ID="lblMessage" ForeColor="Red" 
        Visible="false"></asp:Label>
</asp:Content>


Merits & Demerits

Inline coding
-
In case of any change(s) in code (HTML + C#), replace the existing ASPX file with modified one in SharePoint Designer.
- It is unsafe, to allow server side code by modifying PageParserPaths node in web.cofig
- Can't debug the page [Major disadvantage while development].
-
Easy to deploy, no need to do DLL registration in GAC, IISRESET and safecontrol entry in web.config


Code-Behind
- Can debug server side code ( Debug -> Attach to Process -> w3wp.exe process )
- Need to do DLL registration in GAC, IISRESET and safecontrol entry in web.config
-  In case of any change(s) in HTML code, replace the existing ASPX file with modified one in SharePoint Designer.
- In case of any change(s) in server-side ( C# ) code, re-register the DLL in GAC (drag-n-drop dll in assembly folder) and do IISRESET [ Must ] to see the change(s).

Login pop-up in SharePoint

If you gets login pop-up whenever you opens any SharePoint page in Internet Explorer (IE), then solve this issue we need to change following IE settings...Add the SharePoint site to the list of Local Intranet (IE7/8).
1) In Internet Explorer, on the Tools menu, click Internet Options. 
2) On the Security tab, in the Select a Web content zone to specify its security settings box, click Local Intranet, and then click Sites. 
3) Clear the Require server verification (https:) for all sites in this zone check box. 
4) In the Add this Web site to the zone box, type the URL to your site, and then click Add. 
5) Click Close to close the Local Intranet dialog box. 
6) Click OK to close the Internet Options dialog box. 

A sales engineer is someone who promise you a bridge, even when there's no river.