AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1685&pId=-1
Developing and Deploying a SharePoint Feature - Part 2
page
by Steven Barden
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27372/ 73

Introduction

This article will display the deployment of using a feature to install code that creates an unpopulated Word Document List. It is part two in a series of articles that will focus on using install techniques and features to perform various actions. When viewed as a whole, these features are designed to stand alone during development, yet they should work together during runtime. As the next part in the series, this demonstration builds upon Part 1 of this series, and is designed to assist newer SharePoint developers in differentiating between the development of a deployable SharePoint feature solution, and the more complex code that may be deployed in the deployment solution.

In Part 1 of this series the goal was to begin the process of developing and deploying a SharePoint feature solution in such a way that it was easy to tell where the act of deployment left off from where the objects that were deployed to perform the intended efforts began. I better appreciate the example code that is broken into articles that clearly differentiate between one technology or section and the next. Deploying a SharePoint Feature and then inserting and displaying code that is delivered via a feature, yet still has its own show and tell criteria is an example of this for me.

Background

SharePoint is an amazing development platform compiled from numerous components. One of the advantages of SharePoint 2007 over its predecessor is in how well it works with the existing framework that Microsoft has constructed with .NET, IIS, etc. One serious drawback with SharePoint 2003 was that it was in some ways counterproductive in its use of IIS and ASP.NET. Over time the SharePoint development team ended up recreating a significant amount of the  functionality that already existed in ASP.NET on IIS. As the complexity of SharePoint 2003 increased, so did the amount of functionality that needed to be recreated. This was most notable in the lack of namespace functionality. In other words, not all of the tricks you knew in ASP.NET were available for use in SharePoint code. For example, you would know what you want to do, then you would call on the SharePoint namespaces, just to find that the methods and properties you expected to have at your disposal where not available.

In many ways SharePoint 2007 is a complete rewrite. It answers many of these problems by virtue of its real integration with ASP.NET and IIS. It truly sits on top of these products and makes no effort to replace existing functionality (or at least significantly less). This means that if you performed SharePoint 2003 development, and complained about how much SharePoint was not like ASP.NET, you will be much happier… and as such, more productive.

A SharePoint application? A goal driven solution…

So what exactly is a SharePoint application? It may be more helpful to use the term solution. When you determine the goal you are trying to accomplish with SharePoint, it may be more helpful to think of the resulting set of objects in terms of their parts. As you have seen from Part 1, we have prepared the locations for files of different types. In most solutions you will obviously want to use the bulwark of the SharePoint solution, the List. Other needs will be answered by way of ASPX and ASCX objects. And still others by the use of assemblies. In short, you may choose to think of a SharePoint solution as multiple parts similar to ASP.NET applications.

Preparing to continue

As you have seen from the construction of the solution in Part 1, some of the components will be added by you and copied into place, such as page objects. Yet others will be assemblies that you will copy into a bin directory or the GAC. This obviously implies that during these exercises we will be using basic copy processes to place our files in the proper location. SharePoint also allows you to distribute your files in CAB format. This means building your solution like we are doing here, then compiling the components into a CAB file that can be distributed in any number of ways, such as a download or a CD/DVD, along with a setup file. Finally, you may choose to use stsadm to deploy the final solution, for example at a client site. Due to various complexities in the act of building a CAB file in a SharePoint solution, I will cover this method in the future.

If you have not already downloaded the source code from Part 1 of this article series, you can find it by way of the first article at http://aspalliance.com/author.aspx?uId=45726. I am using Visual Studio 2008, but the topics I have covered so far should not be version specific between Visual Studio 2005 and 2008. You may also skip the first article code and download this code by way of the download links provided.

Enabling Intellisence for various SharePoint XML files…

SharePoint XML file Intellisence is not enabled by default. However, there are a few ways to correct this. The following actions will work for many types of SharePoint files, with the following steps specifically targeted at the Feature.xml file.

In short, our goal is to point the use of the Visual Studio IDE toward certain XML / XSD files on the file system, to enable the use of Intellisence. There are actually several different ways to do this, from more manual to more automated.

1) The more GUI operated way is to begin by opening an XML file, such as the feature.xml file. Once you have the feature.xml file open in Visual Studio, navigate to the properties window. Select "Schemas" and click the ellipsis on the right side of the box. Once the XML Schemas popup window is open, click the Add button, navigate to the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML" directory (accounting for the install drive and location you used) and select the "wss.xsd" file. Click Ok and navigate back to the feature.xml file open in Visual Studio and you will now have Intellisence functionality. The options offered in the feature.xml file will seem fairly sparse, but there are not many options here. You will notice far more functionality when it comes to other XML files, such as those that the feature xml file may call (not seen in this project).

2) The second and arguably easier way (although less informative way) to accomplish this task is to directly add the path and file names of the desired XSD files that are found during step one. In other words, you perform step one once, and then use the settings over and over. The complete list of files that are recommended are:

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\CamlQuery.xsd"

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\camlview.xsd"

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\coredefinitions.xsd"

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd"

The lines above are the individual lines. In reality they are all run together, as seen below.

"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\CamlQuery.xsd" "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\camlview.xsd" "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\coredefinitions.xsd" "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd"

3) There is a third solution, which is more elegant, permanent, and global. I learned one in a Ted Pattison Group class (have I suggested you should review his information and courses?), but it has also been published by John Lee on blogs.msdn.com. As a side note, I highly suggest reviewing John's page as it has very valuable reading.

To accomplish the goal of permanently enabling this functionality, start by opening the following directory: "C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas." Then make a text file, and rename it "sharepoint_catalog" and change the extension to ".xml." Inside this file add the contents below: 

Listing 1

<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
<Schema href="C:\Program Files\Common Files\Microsoft Shared\web server 
extensions\12\TEMPLATE\XML\wss.xsd" 
targetNamespace="http://schemas.microsoft.com/sharepoint/" /> 
</SchemaCatalog>

Now, simply close and re-open all instances of Visual Studio and you should be set, that is, each of the XML files you will work with should allow the use of Intellisence as needed. Now, with that said, I ran into a problem where this did not appear to work right. I reset Visual Studio and even rebooted the PC and it still did not seem to work. Then, sometime shortly after that, it started working and has not stopped working correctly. So my point is, do not be surprised if there is a problem at one point enabling Intellisence to find it seems to correct itself.

Building the Required Code

In any application you create there is likely to be code… this is not always the case of course, but quite likely. Now I confess, I tried to do something that I was not sure would work. I tried to build this feature in such a way that the creation of the Word Document List was done declaratively, rather than programmatically, as well as populating the List Metadata and contents. I found that in the time I had allotted myself, this could not be done. What happened is that the list was not created, thus the following actions of population failed.

Now I am sure it is likely that what I am looking to do can be done because I believe I have seen other people's code that did it that way. But I did things wrong, and it failed to work for me in the time I allotted myself. I also want to point out that while I have the typical TYPE-A personality of most developers, I am also humble. If you see the error in my ways, and you would like to supply a detailed explanation, please feel free to do so.

Downloads
About the Source Code and Running the Application

Finally, let us cover the downloadable code for this project. First off, it is intended to be unpacked to C:\Code\SharePoint\Features\DeployHelloWorld for development, mostly because this is where the batch files point to work from, but of course you can do what you like and change things. Assuming you are following along here, from a command prompt run the command:

Listing 2

mkdir C:\Code\SharePoint\Features\DeployHelloWorld

Then unpack the files to the last directory "DeployHelloWorld," such that the *.cmd and *.sln files are here, inside the DeployHelloWorld directory. The SharePoint site used in this project is a generic top level website. No account has been made to search through a collection of subwebs under a top web to locate "the right one" where you will perform this work. You may of course add the code needed to cycle the proper collection to do this for your own practice.

Other than what is described above, you should not have any problem in unpacking, compiling or running the code. If you do hit any snags you can attach a debugger, as expected, to determine the cause of any errors. Once the code has worked correctly, you can de-activate the feature as expected. One quick and dirty way of removing the components after deactivation is to manually delete the list then run the Remove.cmd file. Remember to do this after you have deactivated the feature. This and the install command files are probably two examples of where you may want to use the directories previously described, but you can of course change the command files as needed. Once the feature is installed, you should be able to go to the site, use the Site Actions tab in the upper right corner, and navigate to site settings. Toward the bottom of the Site Administration stack, click on the Site Features link. The Site Features Page should be displayed where you can locate the yellow exclamation point image. This is the feature to enable. If all goes well you should see a new Word Document list on the quick launch section on the main page.

Conclusion

There are many components that have not been coded for, but at this point you should have a good starting point. Good luck and Happy Features!


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 6:34:39 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search