16.01.2013 Views

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 37: Using Visual Studio .NET to Create Web Parts 1013<br />

There are two default locations where the .NET common language runtime will look<br />

for .NET assemblies when operating within the context of a WSS-extended server.<br />

One of them is the Global Assembly Cache, <strong>and</strong> the other one is the bin directory of<br />

your WSS extended virtual server root directory (for example, the c:\inetpub\wwwroot<br />

\bin folder).<br />

To specify the build output path<br />

During Web Part development, changing the build output path to the BIN folder of<br />

your SharePoint virtual server is recommended so that you don’t have to copy the<br />

assembly file every time after compilation.<br />

1. In the Solution Explorer, right-click your project name, <strong>and</strong> then click<br />

Properties.<br />

2. Under Configuration Properties\Build\Outputs, set the Output Path to<br />

the Bin folder within the root folder of the Windows SharePoint Services<br />

extended virtual server, for example: c:\inetpub\wwwroot\bin.<br />

Deploying a Web Part<br />

Now you are ready to compile the Web Part. However, before you’re able to use the<br />

Web Part, there are a couple of steps left that you need to take. The <br />

section of the Web.config file specifies which Web Parts are trusted. So, you need to<br />

register your own Web Part as a safe control. The following code shows an example<br />

of the section:<br />

<br />

..<br />

<br />

<br />

<br />

The Assembly attribute of the element shows the assembly name of<br />

the Web Part assembly, <strong>and</strong> optionally a version number, a culture reference, <strong>and</strong> a<br />

public key token. Now you should determine the public key token of your Web Part<br />

library assembly so that you can create a safe control entry for your Web Part in the<br />

Web.config file. The easiest way to accomplish this is to copy the assembly DLL file<br />

into the Global Assembly Cache. Locate the DLL file, right-click the DLL, <strong>and</strong> copy<br />

the public key token. After this, don’t forget to remove the assembly .DLL file from the<br />

Global Assembly Cache. You could also use the Strong Name tool (SN.exe) to obtain<br />

the public key token.<br />

1. From a comm<strong>and</strong> prompt on the drive where you installed Visual Studio .NET,<br />

type the following: cd \Program Files\<strong>Microsoft</strong> Visual Studio .NET\FrameworkSDK\Bin\<br />

or \Program Files\<strong>Microsoft</strong> Visual Studio.NET 2003\SDK\v1.1\Bin if you are using<br />

Visual Studio.NET 2003.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!