Sunday, June 28, 2009

70-630 exam brain dump. Microsoft Office Sharepoint Server 2007, Configuring

The 70-630 exam covers concepts and skills related to installing, configuring, and managing SharePoint server farms, site collections, and interoperations with other Microsoft technologies. It emphasizes the following elements of design and administration:

  • Configuring Microsoft Office SharePoint Server 2007 Portal
  • Managing search
  • Configuring content management
  • Configuring business forms
  • Managing business intelligence
  • Managing administration
  • Deploying and upgrading Microsoft Office SharePoint Server 2007

This exam is quite specific regarding SharePoint Server 2007 requirements and operational settings, and it can be particular about how administrative and configuration tasks are performed within SharePoint. It also focuses on fundamental concepts of SharePoint’s operation and its interoperability with other Microsoft Office suite products, particularly other Office 2007 applications.

wsshelp.blogspot.com Question: 1
You have configured the serial approval workflow on the Reports document
library. A manager has final approval on the workflow, but the manager is not available. You need to
find out which documents are awaiting the managers approval. What should you do?
A. Manage the checked-out files for the Reports document library.
B. Remove the workflow from the Reports document library.
C. Create a new approval workflow and assign yourself as an approver.
D. View the workflows task list.
Answer: D

wsshelp.blogspot.com Question: 2
Your company has a Web-enabled forms library, which is accessed daily by
approximately 10,000 users. While monitoring your network bandwidth, you discover that the session
data for your InfoPath forms is always lower than 40 KB. You need to decrease the work load on your
Microsoft SQL Server computer. What should you do?
A. Configure InfoPath Forms Services for cross-domain data access.
B. Implement a data connection file for InfoPath Forms Services.
C. Set Form Session State to Form view.
D. Configure InfoPath Forms Services to allow SQL Server authentication.
Answer: C

wsshelp.blogspot.com Question: 3
A user designs a form by using Microsoft Office InfoPath 2007. The user
reports that she is not able to upload a new form to a forms library. You need to assign the user the
minimal permissions necessary to upload forms to the forms library. What should you do?
A. Assign the user the Contribute permission on the forms library.
B. Assign the user the Design permission on the forms library.
C. Add the user to the site Members group.
D. Add the user to the site Owners group.

Answer: A

wsshelp.blogspot.com Question: 4
A user creates an expense report form by using Microsoft Office InfoPath
2007. The user is a member of the Contributors group on the Finance site. You need to ensure that the
form is available from the Finance site. What should you do?
A. Instruct the user to create a new list by using the task list template.
B. Instruct the user to save the form as an XML file to the Finance site.
C. Instruct the user to publish the expense report form to the Finance site.
D. Instruct the user to export the form by using a form template converter.
Answer: C

wsshelp.blogspot.com Question: 5
You need to ensure that all data connection settings that are referenced by
your Microsoft Office InfoPath forms are held in external files. What should you do?
A. Create a Microsoft Data Link file that has the data connection settings.
B. Set all forms to be accessible anonymously.
C. Enable the Web service proxy.
D. Create a universal data connection (UDC) that has the data connection settings.
Answer: D

wsshelp.blogspot.com Question: 6
You r company uses a custom property in Microsoft Office d ocuments
named TrackingID. You need to ensure that users can find documents based on the TrackingID
property even if the documents are stored in a library that does not contain a TrackingID column. What
should you do?
A. Create a new file type inclusion that has the extension trackingid.
B. Create a new search scope named TrackingID.
C. Create a new managed property named TrackingID.
D. Create a new SharePoint site named TrackingID by using the Search Center template.
Answer: C

wsshelp.blogspot.com Question: 7
You create a new site that uses the Records Repository template. Within the
records repository, you create a document library named Contracts. You need to ensure that all
contracts that are sent to the records repository are automatically placed in the Contracts document
library. What should you do?
A. In the Classified document library, create a new folder named Contracts.
B. In the Unclassified document library, create a new folder named Contracts.
C. Add a new entry to the Record Routing Type table.
D. Create a content type named Contracts and associate it with the Contracts document library.
Answer: C

wsshelp.blogspot.com Question: 8
You store sales reports in several document libraries. You need to collect
custom metadata for all sales reports. What should you do?
A. Configure a new content type. Associate it with all document libraries that will contain sales reports.
B. Create a new document property mapping for the sales extension.
C. Enable update query support in the Data Retrieval service.
D. Create a new information management policy for the default content type.
Answer: A

wsshelp.blogspot.com Question: 9
You need to place a link on the top navigational bar of your companys
corporate Web site. You also need to ensure that the link appears on all pages within the root site
collection. What should you do?
A. Modify the logo URL for the root site collection.
B. Modify the default.aspx page for the root site collection by using Microsoft Office SharePoint Designer
2007.
C. Configure the site navigation settings for the root site collection.
D. Enable the tree view navigation option for the root site collection.
Answer: C

wsshelp.blogspot.com Question: 10
You create a content type named Sales Report and associate it with a
document library for the sales department. You need to ensure that the metadata for all sales reports
appears when the document is opened in Microsoft Office Word 2007. What should you do?
A. Modify the document information panel settings for the Sales Report content type.
B. Create a new column named Metadata and associate it with the Sales Report content type.
C. Create a new site that uses the Document Center template. Move all sales documents to the new site.
D. Configure the variation settings for the site collection.
Answer: A

wsshelp.blogspot.com Question: 11
Several of your Microsoft Office InfoPath forms gather data from Web
services by using data connections. You discover that Web-enabled forms that are created by users
cannot gather data from these Web services. You need to ensure the data from these Web services is
accessible to the user-created forms. What should you do?
A. Enable the Web service proxy for user forms.
B. Enable cross-domain access for user form templates.
C. Embed authentication in the connection string.
D. Configure SSL for HTTP authentication to data sources.
Answer: A

wsshelp.blogspot.com Question: 12
Your network contains a single server farm that has a single shared services
provider. The server farm contains multiple site collections.
You need to ensure that a certain user can access the search usage reports that cover all site collections.
What should you do?
A. Assign the user permissions to the shared services provider.
B. Assign the user permissions to the root site collection.
C. Assign the user permissions to the site directory.
D. Assign the user permissions to the Document Center.
Answer: A

wsshelp.blogspot.com Question: 13
You need to identify the most commonly used search terms and the
associated search results for your companys SharePoint sites. What should you do?
A. Analyze the query log.
B. Analyze the Office Diagnostics event log.
C. Analyze the crawl log.
D. Analyze the Application event log.
Answer: A

wsshelp.blogspot.com Question: 14
Your company uses an application that creates documents that have a .xyz
extension. Users report that when they perform searches from the root SharePoint site, documents that
have the .xyz extension appear in the search results only if the search query includes the file name. You
need to ensure that the content from documents that have the .xyz extension is included in the search
results. What should you do?
A. Create a new content type for documents that have the .xyz extension.
B. Create a new search scope named xyz.
C. Implement a new keyword best bet for xyz.
D. Implement a custom IFilter that handles .xyz files.
Answer: D

wsshelp.blogspot.com Question: 15
You need to configure the Search Center site to meet the following
requirements:
The advanced search controls should be visible, by default, when users access the Search Center
site.
The basic search controls should not be visible when users access the Search Center site.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Rename the advanced.aspx page in the Search Center site to index.aspx.
B. Add the Advanced Search Box Web part to the default.aspx page in the Search Center site.
C. Add the Advanced Search Box Web part to the advanced.aspx page in the Search Center site.
D. Remove the Basic Search Box Web part from the default.aspx page in the Search Center site.
E. Remove the Basic Search Box Web part from the advanced.aspx page in the Search Center site.
Answer: B, D

wsshelp.blogspot.com Question: 16
You need to add a tab to the Search Center site. What should you do?
A. Add a new site content type, and then add a new tab to the default page in the Search Center site.
B. Create a new page in the Search Center site, and then add a new tab to the default page in the Search Center
site.
C. Enable the tree view for the Search Center site, and then add a new tab to the default page in the Search
Center site.
D. Create a new SharePoint site by using the Search Center template.
Answer: B

wsshelp.blogspot.com Question: 17
Your company has several document libraries that include .dot files. You
need to ensure that searches performed from the root SharePoint site do not contain .dot files in the
search results. What should you do?
A. Include .dot as a blocked file type.
B. Run the stsadm command with the remove-ecsfiletrustedlocation operator.
C. Remove the .dot extension from the file type inclusion list.
D. Run the stsadm command with the searchdiacriticsensitive operator.
Answer: C

wsshelp.blogspot.com Question: 18
You create a site collection for each department in your company. You
need to schedule the deployment of content from the Sales site collection to the Marketing site collection.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Configure the content deployment settings for the Marketing site to accept incoming content deployment
jobs.
B. Create a new content deployment path and job.
C. Configure the Data Retrieval Service for update query support.
D. Create a new Content Management Server migration profile.
E. Configure the content deployment settings for the Sales site to not require encryption.
Answer: A, B

wsshelp.blogspot.com Question: 19
Your company stores profile information for remote users in Active
Directory Application Mode (ADAM). You need to import profiles for the remote users. What should
you do?
A. Configure the user profile import source to be the Entire Forest.
B. Create a new user profile import source connection. Use the Business Data Catalog connection type.
C. Create a new user profile import source connection. Use the LDAP Directory connection type.
D. Create a new user profile import source connection. Use the Active Directory connection type.
Answer: C

wsshelp.blogspot.com Question: 20
You need to create SharePoint usage logs in a flat text file. What should
you do?
A. In Event Viewer, save the Office Sessions event log as a comma separated values (CSV) file.
B. In the Shared Services Provider, enable advanced usage analysis processing.
C. In SharePoint Central Administration, enable logging in usage analysis processing.
D. In SharePoint Central Administration, enable recurring policy usage reports.
Answer: C

wsshelp.blogspot.com Question: 21
You want to update your form templates.
Prior to updating the templates, you need to prepare your environment so that the following
requirements are met:
Users cannot establish new connections to forms.
Users who are currently connected to forms are able to complete the forms without being
disconnected.
No other server functions are interrupted.
What should you do?
A. Create a scheduled task to run the stsadm command with the registerwsswriter operator.
B. Disable the Shared Services Provider Synchronizing job.
C. Create a scheduled task to run the stsadm command with the quiesceformtemplate operator.
D. Pause the Windows SharePoint Timer Service.
Answer: C

wsshelp.blogspot.com Question: 22
You deploy the English-language version of Microsoft Office SharePoint
Server (MOSS) 2007. You install the French, German, and Japanese language packs. You need to
ensure that users do not create personal sites in any language other than English. What should you do?
A. Configure My Site Settings to Disable the Language Options.
B. Ensure that the language preference for all users is set to English in Internet Explorer.
C. Force all subsites to inherit the regional setting of the root site.
D. Disable all translatable column settings in the root site.
Answer: A

wsshelp.blogspot.com Question: 23
You establish a corporate design standard by using a customized site
definition. A Web designer modifies several pages by using Microsoft Office SharePoint Designer 2007.
These pages no longer conform to the corporate standards. You need to revert the pages to conform to
the corporate standard. What should you do?
A. Deploy a new SharePoint solution that contains the corporate site definition.
B. Reset all sub-sites to inherit the site master page settings.
C. Change the site master page by using Microsoft Office SharePoint Designer 2007.
D. Use the Reset to site definition option.
Answer: D

wsshelp.blogspot.com Question: 24
You need to automatically create a new Announcements list item when new
documents are added to the Communications document library. What should you do?
A. Create a new lookup column from the Communications document library in the Announcements list.
B. Create a new workflow by using Microsoft Office SharePoint Designer 2007. Associate the workflow with
the Communications document library.
C. Associate the disposition approval workflow with the Communications document library.
D. Associate the approval workflow with the Communications document library.
Answer: B

wsshelp.blogspot.com Question: 25
You need to prevent users from printing confidential documents that are
stored in the document library. Which two actions should you perform? (Each correct answer presents
part of the solution. Choose two.)
A. Install the Internet Printing component for IIS.
B. Enable Information Rights Management on the document library.
C. Configure the server farm to use Information Rights Management.
D. Create a new Web application policy to deny write access to the Authenticated Users group.
E. Add a permissions policy level to deny Use Remote Interfaces.
Answer: B, C

wsshelp.blogspot.com Question: 26
A user reports that he cannot access his original file after saving
modifications. The file is located in a document library named Sales Reports. You need to configure the
document library to retain previous versions of files. What should you do?
A. Configure information management policy settings for a new content type.
B. Configure the Sales Reports document library to require content approval.
C. Enable versioning on the Sales Reports document library.
D. Enable audience targeting on the Sales Reports document library.
Answer: C

wsshelp.blogspot.com Question: 27
You need to log all deletions from a document library. The log must include
the user name, date, time, and file name of the deleted item. What should you do?
A. Enable auditing for object access by using a Group Policy object (GPO).
B. Create a retention policy for the site collection.
C. Enable auditing for deleted item events.
D. Configure the Recycle Bin quota for the Web application.
Answer: C

wsshelp.blogspot.com Question: 28
Your companys i nternal and remote users require access to an existing
Web application.
You need to configure your environment to meet the following requirements:
Remote users must use forms-based authentication.
Internal users must use Integrated Windows authentication.
Internal users and remote users must use different URLs to gain access.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Modify the authentication provider for the default zone.
B. Modify the authentication provider for the intranet zone.
C. Modify the authentication provider for the extranet zone.
D. Add a managed path to the existing Web application.
E. Extend an existing Web application to the extranet zone.
Answer: C, E

wsshelp.blogspot.com Question: 29
You need to create a Business Data Catalog (BDC) data list Web part that
will query a Microsoft SQL Server 2005 database. You also need to ensure that users are not prompted
for authentication when they access the BDC data list Web part. What should you do?
A. Implement a new Web application security policy.
B. Implement an LDAP membership provider.
C. Implement a SQL Server membership provider.
D. Enable and configure single sign-on.
Answer: D

wsshelp.blogspot.com Question: 30
You need to create a link to the sales department SharePoint site for all
users in the sales department. You also need to ensure that the link is visible only in the sales department
users personal sites. Which two actions should you perform? (Each correct answer presents part of the
solution. Choose two.)
A. Use the Shared Services Administration Web site to modify the profile services policy.
B. Create an Active Directory global group that contains all sales department users.
C. Create an audience that contains all sales department users.
D. Use the Shared Services Administration Web site to create a personalization link.
Answer: C, D

wsshelp.blogspot.com Question: 31
Users report that several links within the SharePoint site directory no
longer function. The links all appear to reference external Web sites. You need to identify all links
within the site directory that are not functioning. What should you do?
A. From the site directory, run Scan for Broken Links.
B. Run the stsadm -o enumsites command.
C. Run the stsadm -o deletesites command.
D. Open the site directory by using SharePoint Designer, and run the Optimize HTML command.
Answer: A

wsshelp.blogspot.com Question: 32
A site collection administrator reports that she is unable to view usage
analysis reports for the site collection. You need to ensure that she is able to view the site collection
usage summary. Which two actions should you perform? (Each answer presents part of the solution.
Choose two.)
A. In the Shared Services Provider, enable advanced usage analysis processing.
B. In Central Administration Operations, enable recurring policy usage reports.
C. In Central Administration Operations, change the storage location of the trace log to a file share.
D. In Central Administration Operations, enable logging and usage analysis processing.
E. In Central Administration Application Management, configure a records repository connection.
Answer: A, D

wsshelp.blogspot.com Question: 33
A developer provides you with a new feature for a site collection. You need
to make the feature available for activation by your site collection Administrator. What should you do?
A. Run the stsadm command with the activatefeature operator.
B. Run the stsadm command with the scanforfeatures operator.
C. Run the stsadm command with the installfeature operator.
D. Run the stsadm command with the addwppack operator.
Answer: C

wsshelp.blogspot.com Question: 34
You enable usage analysis processing. You need to identify the links that
users follow to access your SharePoint sites. What should you do?
A. Analyze the SharePoint trace log.
B. In the Application event log, analyze events from the Office SharePoint Server source.
C. In the Report Center, create a dashboard named Usage.
D. In the site collection, analyze the Referrers report.
Answer: D

wsshelp.blogspot.com Question: 35
A user frequently accesses resources on a Microsoft Office SharePoint
Server (MOSS) 2007 server. You change the users logon name. You need to ensure that the user
maintains access to the same resources on the MOSS server. What should you do?
A. On the Policy for Web Application settings, give the user account full read permissions.
B. Create a new user profile property.
C. Run the stsadm command with the migrateuser operator.
D. Run the stsadm command with the updatefarmcredentials operator.
Answer: C

wsshelp.blogspot.com Question: 36
You create a custom home page for a site collection that is shared between
the sales department and the marketing department. You add a Web part for the sales department to
the home page of the site collection. You need to configure the Web part to ensure that only users in the
sales department can view the Web part by default. What should you do?
A. Create an audience that contains all sales department users. Target the Web part to the audience.
B. Create an Active Directory group. Add all sales department users to the group. Add the group to the site
Members group.
C. Create an Active Directory group. Add all sales department users to the group. Add the group to the site
Owners group.
D. Create an Active Directory group. Add all sales department users to the group. Add the group to the site
Readers group. Ensure that no marketing department users are members of the site Owners group.
Answer: A

wsshelp.blogspot.com Question: 37
You want to perform scheduled maintenance on your server farm. You
need to prevent users from establishing new sessions. You must achieve this goal without terminating
user sessions that are already established. What should you do?
A. Disable the Config Refresh timer job in the Timer Job definitions.
B. Stop the Windows SharePoint Services Timer service.
C. Disable session state for the server farm.
D. Quiesce the server farm.
Answer: D

wsshelp.blogspot.com Question: 38
The development team creates a sales application that uses a Microsoft SQL
Server 2005 database. The database contains information that you want to expose through a Business
Data List Web part. You need to configure your server to support this configuration. What should you
do?
A. Request a signed assembly from the development team. Upload the assembly to the global assembly cache.
B. Create a new content source for the URL of the Microsoft SQL Server database.
C. Request an application definition file from the development team. Install the file.
D. Add the URL of the sales application to the trusted file locations list.
Answer: C

wsshelp.blogspot.com Question: 39
You store a Microsoft Office Excel spreadsheet on an external Web site. You
configure the external Web site to allow anonymous authentication. When users attempt to open the
spreadsheet through Excel Services, they receive an access denied error. You need to configure your
SharePoint server to ensure that the external Excel spreadsheet is available through Excel Services.
What should you do?
A. Add a new Excel Services trusted data provider.
B. Configure the External Data Unattended Access account for Excel Services.
C. Add a new Excel Services trusted file location.
D. Add a new Excel Services trusted data connection library.
Answer: C

wsshelp.blogspot.com Question: 40
A list view Web part named Products displays product names. You need to
add another Web part to ensure that users are able to manually enter filter values on the Products Web
part. Which Web part should you add?
A. Search Box
B. Reusable Content
C. Text Filter
D. Business Data List
Answer: C

wsshelp.blogspot.com Question: 41
You create a new SharePoint site that uses the Report Center template.
You need to create a new page in the Report Center that contains the following default Web parts:
Excel Web Access
Key Performance Indicators
KPI Details
What should you do?
A. Create a new page in the Report Center that uses the Article page layout.
B. Create a new page in the Report Center that uses the News Home page layout.
C. Create a new site that uses the Document Center template.
D. Create a new dashboard page in the Report Center.
Answer: D

wsshelp.blogspot.com Question: 42
You create a Business Data Catalog (BDC) application that queries a Microsoft SQL Server 2005 database. The content that is exposed through the BDC is not available in search results. You need to make the data available to searches. What should you do?
A. Assign the Selectable in Clients right to the Administrator account.
B. Add the Document Library Web part to the BDC profile page template.
C. Assign the Copy Selected Permissions to all the Applications and Entities in the Business Data Catalog
right to the Administrator account.
D. Configure a default access account for the BDC application.
Answer: D

wsshelp.blogspot.com Question: 43
You need to create a new site that will have a built-in key performance indicators (KPI) list, a built-in data connections library, a built-in reference library.
Which site template should you use to create the new site?
A. Document Center
B. Records Repository
C. Publishing
D. Report Center
Answer: D

wsshelp.blogspot.com Question: 44
You need to add a disclaimer to all e-mail alerts that users receive from
Microsoft Office SharePoint Server 2007. Which file should you modify?
A. the web.config file for the SharePoint application
B. the layouts.sitemap.policy.xml file
C. the alerttemplates.xml file
D. the onet.xml file
Answer: C

wsshelp.blogspot.com Question: 45
You need to ensure that when you reset the content index, users do not
receive e-mail alerts for content that has not changed. What should you do?
A. Stop the SharePoint Search service.
B. Configure the Search results removal option. Add the root URL to the URLs to remove list.
C. Set the Search alert status to inactive.
D. Run the stsadm.exe command with the osearch operator.
Answer: C

wsshelp.blogspot.com Question: 46
Your company consists of 12 divisions. You anticipate that you will create
hundreds of SharePoint sites over the next year. You need to organize the content within the SharePoint
site directory to reflect the 12 divisions. What should you do?
A. Implement a new managed path for each division. Instruct users to create new SharePoint sites under the
appropriate managed path.
B. Create a new site definition for each division. Instruct users to create new SharePoint sites by using the
appropriate site definition.
C. Create a new site template for each division. Instruct users to create new SharePoint sites by using the
appropriate site template.
D. In the site directory, modify the choices available in the Division column of the sites list. Instruct users to
set the appropriate division when they create new site links.
Answer: D

wsshelp.blogspot.com Question: 47
An Active Directory security group named Sales contains all users from the
sales department. You need to ensure that only users from the sales department can create personal
sites by using the My Site feature of SharePoint Server. What should you do?
A. Modify the personalization services permissions for the shared services provider.
B. Modify the site creation rights for the root SharePoint site.
C. Use the personalization site template to create a new site. Add the Sales group to the Owners group of the
new site.
D. Add the Sales group to the Owners group of the root SharePoint site.
Answer: A

wsshelp.blogspot.com Question: 48
Users report that new content is not returned in search results when they
perform searches from the root SharePoint site. You need to ensure that search results display all
relevant content for the queries. What should you do?
A. Restart the Office SharePoint Server Search service.
B. Perform an IIS reset.
C. Restart the Windows Search Service service.
D. Reset all crawled content. Start a full crawl.
Answer: D

wsshelp.blogspot.com Question: 49
You need to extend user profiles to include the employeeID property from
Active Directory. What should you do?
A. Create a new connection to an Active Directory directory service domain controller.
B. In the root SharePoint site, add an employeeID column to the Contacts list.
C. Create a new user profile property that has import mapping.
D. Create a new profile properties section named employeeID.
Answer: C

wsshelp.blogspot.com Question: 50
You access content in a SharePoint Portal Server 2003 area by using a
desktop icon to the following URL: http://www.contoso.com/c1/technology. You upgrade the server that
runs SharePoint Portal Server 2003 to Microsoft Office SharePoint Server (MOSS) 2007. You need to
access the migrated content after the upgrade. What should you do?
A. Run the stsadm command with the syncsolution operator.
B. Run Scan for Broken Links in the site directory.
C. From the Microsoft Office SharePoint Server (MOSS) 2007 installation CD, run the prescan.exe command.
D. Edit the shortcut to reference the new URL.
Answer: D

wsshelp.blogspot.com Question: 51
You are planning the migration of a Microsoft Content Management Server
(MCMS) 2002 server to your Microsoft Office SharePoint Server (MOSS) 2007 environment. You need
to identify the migration tasks that need to be completed. What should you do on the MOSS server?
A. Run the prescan.exe command from the Microsoft Office SharePoint Server 2007 installation CD.
B. Run the stsadm command with the upgradesolution operator.
C. Run the stsadm command with the createcmsprofile operator.
D. Run the CMS Assessment tool.
Answer: D

Monday, May 26, 2008

Creating Advanced Solutions for SharePoint 2007

Introduction: Building Solutions, Hands-On

The .cab deployment solution for WebParts in SharePoint 2003 was the basis for the design of SharePoint 2007 Solutions. A SharePoint Solution consists of all the files needed for the components to be deployed plus a manifest (xml) file that describes the modus operandi of the files. The Solution file is a cabinet-based .cab file with a ".wsp" extension in place of the ".cab" extension.

By way of a Solution, it is possible to install most types of customizable components of SharePoint such as Site definitions, Features, WebParts, Templates and assemblies. Additionally, the Code Access Security (CAS) policies can be modified in the web.config.

Solution Schema and Walking Through the Creation of Solutions

The .wsp file can have an internal tree structure, and the Solution manifest file (obligatory to have the name "manifest.xml") must be located in the root of the structure. The manifest file gives instructions to the Solution engine in SharePoint regarding the modus operandi of the other files in the Solution; however, it does not define the structure of the components. Subsequently, a file may exist in the .wsp Solution file, but if the file is not mentioned in the manifest, it will always be disregarded.

The general schema of the manifest file is:

<Solution
DeploymentServerType = (Optional) "ApplicationServer" | "WebFrontEnd"
ResetWebServer = (Optional) "TRUE" | "FALSE"
SolutionId = (Optional) "Text or GUID"
xmlns="http://schemas.microsoft.com/sharepoint/">
<Elements...
ApplicationResourceFiles
ApplicationResourceFile
Assemblies
Assembly
SafeControls
SafeControl
ClassResources
ClassResource
CodeAccessSecurity
PolicyItem
PermissionSet
IPermission
Assemblies
Assembly
DwpFiles
DwpFile
FeatureManifests
FeatureManifest
Resources
Resource
RootFiles
RootFile
SiteDefinitionManifests
SiteDefinitionManifest
WebTempFile
TemplateFiles
TemplateFile
...>
</Solution>

The parameters of the "Solution" section define the scope of deployment; the Solution initiates "iisreset" after activation ("ResetWebServer" Parameter), as well as the ID (a string or GUID) and the NameSpace. Inside the Solution tag, the Elements of the Solution can be defined. The following illustrates a Solution with different elements, beginning with the Solution metadata:


<Solution SolutionId = "12345678-90AB-CDEF-1234-567890ABCDEF"
xmlns="http://schemas.microsoft.com/sharepoint/">
. . .
</Solution>

The GUID can be created with the Visual Studio generator or constructed manually.


RootFiles Element


The "RootFiles" element copies the defined files in a particular directory:


<RootFiles>
<RootFile
Location = "Text">
</RootFile>
...
</RootFiles>

The "Location" parameter identifies the final localization of the file. The localization in the structure of the .wsp file needs to mirror the final localization in the server, and is relative to the 12 hive where the SharePoint files are localized. Thus, the tags


<RootFiles>
<RootFile
Location = "TEMPLATE\IMAGES\MyPic.jpg">
</RootFile>
</RootFiles>

will copy the file "MyPic.jpg", found in the directory "TEMPLATE\IMAGES" in the .wsp file, to the directory "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES" of SharePoint.


If the file cannot be found in the correct place in the .wsp file, the installation of the Solution will be aborted.


TemplateFiles, Resources, and ApplicationResourceFiles Element


The TemplateFiles, Resources, and ApplicationResourceFiles elements are very similar to the RootFiles element; they create a copy of one or more templates, resources, or resource files for the complete application in the chosen directory:


<TemplateFiles>
<TemplateFile
Location="Text"/>
...
</TemplateFiles>


<Resources>
<Resource
Location="Text"/>
...
</Resources>


<ApplicationResourceFiles>
<ApplicationResourceFile
Location="Text"/>
...
</ApplicationResourceFiles>

Resource files need to be installed in a feature directory. In the following example, the resource file "JupiterMedia.es-co.resx" will be copied to the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\FeatureName" directory:


<Resources>
<Resource
Location="FeatureName\JupiterMedia.es-co.resx "/>
</Resources>

Application Resource Files are general resources that SharePoint will use for different purposes, for example, localization files that can be installed in the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Resources" directory.


FeatureManifests Element


Features are a new concept introduced in SharePoint 2007, and offer services to install, activate, deactivate, and uninstall functionality. There are some notable differences between Solutions and Features: the former were created to install complete packets of functionality, covering the entire SharePoint system; Features can install only one element at a time. However, within that limitation, Features modify the user interface of SharePoint (add menu's, for example) in an uncomplicated way.


Features can be installed using Solutions (the opposite is not possible). The syntax is:


<FeatureManifests>
<FeatureManifest
Location="Text"/>
</FeatureManifests>

For example:


<FeatureManifests>
<FeatureManifest Location="JupiterMediaFeature\feature.xml"/>
</FeatureManifests>

Install the "JupiterMediaFeature" feature in the features directory "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\FEATURES". Observe that Features will be installed, but not activated, by the Solution.


SiteDefinitionManifests Element


To install SharePoint Site Definitions, the following syntax is applied:


<SiteDefinitionManifests>
<SiteDefinitionManifest
Location="Text">
<WebTempFile
Location="Text">
</SiteDefinitionManifest>
...
</SiteDefinitionManifests>

Each Site Definition needs to be linked to a location in the Template structure of SharePoint. The subsequent example copies the Site Definition "webtempSTS.xml" to the "STS" Template:


<SiteDefinitionManifests>
<SiteDefinitionManifest Location='STS'/>
<WebTempFile Location='1033\STS\webtempSTS.xml'/>
</SiteDefinitionManifest>
</SiteDefinitionManifests>

Assemblies and ClassResources Elements


Installing assemblies is also possible using a Solution. The assembly can be installed in the GAC or in the local Bin directory, together with its registration in the web.config file by means of the following:


<Assemblies>
<Assembly
DeploymentTarget = "GlobalAssemblyCache" | "WebApplication"
Location = "Text">
<SafeControls>
...
</SafeControls>
</Assembly>
</Assemblies>

The "DeploymentTarget" parameter determines whether the assembly reaches the GAC or goes to the Bin directory; the "SafeControls" element ensures its registration in the Safe Controls section of the web.config (this element is not obligatory):


<Assemblies>
<Assembly DeploymentTarget="GlobalAssemblyCache"
Location="JupiterMediaAssembly.dll">
<SafeControls>
<SafeControl
Assembly="JupiterMediaAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=f435cbfb3fb57aec"
Namespace="JupiterMediaAssembly"
TypeName="*" Safe="True" />
</SafeControls>
</Assembly>
</Assemblies>

The "ClassResources" element identifies the resources class for an assembly. The syntax permits defining the file name and location, in the same way as previously explained for other elements:


<ClassResources>
<ClassResource
FileName = "Text"
Location = "Text">
</ClassResource>
...
</ClassResources>

 


CodeAccessSecurity Element


The CodeAccessSecurity element characterizes the CAS policies for the Solution. The Element contains a chain of sub-elements:


<CodeAccessSecurity>
<PolicyItem>
<PermissionSet
class = "Text"
Description = "Text"
Name = "Text"
version = "Text">
</PermissionSet>
...
<Assemblies>
<Assembly
Name = "Text"
PublicKeyBlob = "Text"
Version = "Text">
</Assembly>
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>

The next example delineates a CAS policy, an aspect of the Full Trust standard CAS policy of SharePoint:


<CodeAccessSecurity>
<PolicyItem>
<PermissionSet
class = "UnionCodeGroup"
Description = "This code group grants code signed with
the Microsoft strong name full trust"
Name = "Microsoft_Strong_Name"
version = "1">
</PermissionSet>
<Assemblies>
<Assembly
Name = "System.Security.NamedPermissionSet"
PublicKeyBlob = "00000000000000000400000000000000"
Version = "1">
</Assembly>
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>

DwpFiles Element


As a final point, the recommended way of installing WebParts in SharePoint 2007 is via Solutions. The previous system in SharePoint 2003, applying CAB files and the "stsadm" administrator utility, is still supported, but principally to maintain the compatibility between the two versions. The syntax for the manifest file looks like this:


<DwpFiles>
<DwpFile
Location = "Text">
</DwpFile>
...
</DwpFiles>

Caution: The Software Development Kit indicates the name of the parameter for the "DwpFile" subsection to be "FileName", but that is an error in the sporadically inaccurate SharePoint 2007 SDK. There are numerous syntax errors in the information about Solutions, so caution is advised as regards the information from the SDK.

It is important to consider that, in most working situations, a single element will rarely be used in a manifest for a Solution. For example, to install a WebPart, in addition to employing the "DwpFiles" component, the "Assemblies" element to install the DLL of the WebPart and the "SafeControls" element are needed to configurate it. And, if the WebPart uses resources files (icons, translations), you also will need the "Resources" component and the "CodeAccessSecurity" element to define the Security Police.


Consequently, a complete manifest solution file to install a WebPart may appear as:


<Solution SolutionId="4AFC1350-F354-4439-B941-51377E845ABC"
xmlns="http://schemas.microsoft.com/sharepoint/">
<DwpFiles>
<DwpFile Location = "MyLibrary.webpart"></DwpFile>
</DwpFiles>
<Assemblies>
<Assembly DeploymentTarget="WebApplication"
Location="MyLibraryWebPart.dll">
<SafeControls>
<SafeControl
Assembly="MyLibraryWebPart, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=6a50a9d627073d83"
Namespace="MyLibraryWebPart"
TypeName="*" Safe="True" />
</SafeControls>
</Assembly>
</Assemblies>
<ApplicationResourceFiles>
<ApplicationResourceFile
Location="pic.gif"/>
</ApplicationResourceFiles>
</Solution>

In SharePoint 2007, it is possible to use traditional DWP files (.dwp) or the more current DotNet 2.0 WebPart definition files (.webpart).


Creating a CAB File and Some Helpful Tools


After the creation of the manifest file, the next step is to compress all the required files into a CAB file. Microsoft provides the key software in the "Cabinet Software Development Kit," which can be downloaded from the Microsoft site, http://support.microsoft.com/kb/310618.


To construct a CAB file, apply the "Cabarc" tool with the syntax:


CABARC [options] command cabfile [@list] [files] [dest_dir]

The support commands are:



  • N: Create new cabinet

  • L: List contents of an existing cabinet

  • X: Extract files from a cabinet


And the support options are:



  • -c: Confirm files to be operated on

  • -o: When extracting, overwrite without asking for confirmation

  • -m: Set compression type [LZX:<15..21>|MSZIP|NONE], (default is MSZIP)

  • -p: Preserve path names (absolute paths not allowed)

  • -P: Strip specified prefix from files when added

  • -r: Recurse into subdirectories when adding files (see -p also)

  • -s: Reserve space in cabinet for signing (for example, -s 6144 reserves 6 Kb bytes)

  • -i: Set cabinet set ID when creating cabinets (default is 0)


To make a simple .wsp Solution file, utilize the following:


CABARC N mySolution.wsp file1.aspx file2.dll manifest.xml

This command creates the Solution file mySolution.wsp containing the files "file1.aspx", "file2.dll", and "manifest.xml" (bear in mind the "manifest.xml" file is obligatory), in a single folder, drawing on the default compression mode, MSZIP.


To make Solution files that deploy files to special directories in the 12 hive of SharePoint, it is essential that the directory structure within the WSP file is preserved relative to the 12 hive. For example, to deploy a Feature, the files need to be located in a "TEMPLATEFEATURES" directory in the WSP file. Figure 1 illustrates the directory structure for the files of a sample feature:




image

Figure 1: File structure for a Solution



In this case, where the file structure is preserved, the syntax to make the Solution_Test.wsp at the root of C: directory will be:



CABARC.EXE -p -P TemporaryJupiterMediaFeature n C:Solution_Test.wsp
C: TemporaryJupiterMediaFeatureResources*.*
C: TemporaryJupiterMediaFeature CTypes.xml
C: TemporaryJupiterMediaFeatureFeature.dll
C:Temporarymanifest.xml


This is considerably more complicated than employing a simple structure. To assist with the construction of the file, there is a gratis windows application that can be downloaded from www.gavd.net/servers/sharepointv3/spsv3_item.aspx?top=5&itm=431. This application asks for the files to be compressed and their location inside the 12 hive; after configurating the location and type of output (WSP or CAB), all the intricacies will be assumed by the application:




image 

Figure 2: Making a .wsp file with the SolutionBuilder


There is also a Visual Studio 2005 Template that can be downloaded for free from http://www.codeplex.com/sptemplateland. This Template creates a Visual Studio 2005 Project that takes care of the construction of the .wsp file.


Conclusion


The litany of grievances regarding development and the installation process, and specifically deployment of custom-made software, with SharePoint Portal Server 2003 or Windows SharePoint Services 2.0 is legion. The tiresome process of manual copy-and-paste of files and the time-consuming construction of custom-installed programs were the only options available.


With the launch of SharePoint 2007 (MOSS and WSS) and the introduction of the SharePoint Solutions framework, in one sweep, there was a solution to these inadequacies. the framework ensures the deployment, activation, deactivation, and removal of the customizations, as well as deployment in all of the servers in the farm. It does this in a controlled and time-tabled manner, allowing for version organization and complete transparency for system administrators.


Solutions can be employed programmatically, from the user interface of the SharePoint Central Administration or using the administrators' tool "stsadm". The construction of the manifest file is efficient and orderly, and there are tools to assist in the construction and compilation of the final WSP file.


from http://www.developer.com/mgmt/article.php/11085_3675576_1

Sunday, February 24, 2008

Catching unhandled exceptions in SharePoint

"An unexpected error has occurred. " is something that you probably don't want to see at your browser... you want to have customized error page. In ASP.NET application you normally put Application_Error into you global.asax file. However in SharePoint that place has been taken by the product itself :-) So if you want to do customized approach then you can take HttpModule approach which I'm going to go through in this post.

So let's create our custom exception handler http module. Here's the code for that:

using System;
using System.Web;

public class MyExceptionHandler : IHttpModule
{
public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.Error += new EventHandler(context_Error);
}

void context_Error(object sender, EventArgs e)
{
Exception[] unhandledExceptions = HttpContext.Current.AllErrors;

HttpContext.Current.Server.ClearError();
HttpContext.Current.Response.Clear();
HttpContext.Current.Server.Transfer("/_layouts/MyCustomErrorPage.aspx");
}
}



You can probably see from the code that I'll attach my code to the Error event and in my event I'll do some basic stuff and then transfer to my MyCustomErrorPage.aspx. I used Server.Transfer just because I want user to stay at the same url where exception happened. If I would use Response.Redirect it would "change" the url at the users browser. Same "change" would happen if your custom error page would be normal SharePoint publishing page (i.e. /Pages/MyCustomErrorPage.aspx). If the url stays the same the user can actually press F5 and retry the operation right away. Of course it can be bad thing too and you may want to redirect to another page to avoid creating the same exception all over again. I'll let you decide what you want :-) So do some testing and then decide what's good for you.


But one important thing to notice. You need to put your IHttpModule before SharePoint specific modules in your web.config or otherwise your error routines may not work as you would expect. Here's example from that:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<!-- ... -->
<httpModules>
<clear />
<add name="MyExceptionHandler" type="MyExceptionHandler,Example,
Version=1.0.0.0, Culture=neutral,PublicKeyToken=34a2bd01f6f6eb10"
/>

<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule,
Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
/>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<!-- ... -->

Saturday, January 19, 2008

How to: Create a Web Service for SharePoint

This article will guide you through the process of creating a custom web service for SharePoint. This web service will work with new versions of SharePoint, Office SharePoint Server 2007 and Windows SharePoint Service 3.0. We will create a simple service that will upload documents to SharePoint. We will call it UploadService. Remember, there are steps in the Microsoft articles that are confusing especially for the beginners, I have taken care of that as well. I have tried to include as much information as possible including screenshots and code snippets to make the job easier for the developer. I have used Microsoft articles as a base for this article. There are some mistakes in the Microsoft articles that have been corrected in this article.

Basic Steps for Creating a Web Service

Create an ASP.NET web service in Microsoft Visual Studio 2005. There are two ways to do this. You can develop a web service on the server machine that hosts SharePoint or you can develop it on a remote machine that does not host SharePoint and later deploy the service on the machine that hosts SharePoint. We will discuss the second method in this article.

Add .ASMX file to your project if it's not already there. This file will contain the programming logic for the web service. Note, you can add programming logic to the markup page as well as the code behind. The choice is yours.
Generate a static discovery file (disco) and a Web Services Description Language (WSDL) file.
Modify the disco and wsdl files for SharePoint.

Deploy the web service files to the SharePoint server.

Create a client application to consume the web service.
You can download the sample application (web service) here. Download size is 361 KB.

The zip file contains the web service and its related files. It also contains an installer to help you install the service easily on your server. Unzip the file to your hard disk. It will create a "WSUploadService" folder. You can unzip the file anywhere on your hard disk. There is no restriction on unzipping it to a particular folder. Run "UploadServiceCopier.exe" to install the service. Installer will ask you to select a SharePoint site where this service should be installed. Select your site from the drop down and keep the folder name as "bin" (second field: textbox) and click "Next".

To uninstall, run the "UploadServiceCopier.exe" again. It will give you the following message:

"Service is already installed. Do you want to uninstall it?"

Select "Yes" and then select "Remove WSUploadService" and click "Finish" to uninstall the service. Uninstall will remove all copied files from your hard disk.

Please run "UploadServiceCopier.exe" to install/uninstall the service. Do not run "setup.exe" directly as it will not install the service correctly.

Creating a Custom Web Service

1. The first step is to create an ASP.NET web service project in Visual Studio 2005. If you don't find a web service project template in visual studio, that means that you are still running an old version of Visual Studio 2005, the one without the service pack. You will have to download and install the Visual Studio 2005 Service Pack 1 Beta from Microsoft here. It's a 371.9 MB download and let me tell you in advance that the installation is very slow and takes a lot of time. On the File menu, click New Project.

2. In the Project Types box, select Visual C#.

3. In the Templates box, select ASP.NET Web Service Application.

4. In the Name box, type UploadService. In the Location box, type the following path: C:\WebService. You can also click the browse button to browse the folders and select the destination folder. This is the path where the project will be stored. In the Solution Name box, type UploadService and check Create directory for solution checkbox.

5. Click OK.

6. In the Solution Explorer, right-click Service1.asmx and rename the file Files.asmx and then right click Files.asmx and click View Code.

7. Add a reference to the assembly for Microsoft Office SharePoint Server 2007 (Microsoft.SharePoint.dll). This assembly is located in the following directory: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI. Please note that if you are developing on a machine that does not have SharePoint installed then you can copy the required files from the SharePoint machine to your development machine.

8. Make sure following using directives are included at the top:

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Net;

9. Change your class name from Service1 to Files.

public class Files : System.Web.Services.WebService

10. Comment out the web method definition. The commented out web method code will look like as follows:

//[WebMethod]
//public string HelloWorld()
//{
//return "Hello World";
//}

11. Add following code (web method) in the class:

[WebMethod]
public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
{
if (fileContents == null)
{
return "Null Attachment";
}

try
{
int iStartIndex = pathFolder.LastIndexOf("/");
string sitePath = pathFolder.Remove(iStartIndex);
string folderName = pathFolder.Substring(iStartIndex + 1);

SPSite site = new SPSite(sitePath);
SPWeb web = site.OpenWeb();

SPFolder folder = web.GetFolder(folderName);

string fileURL = fileName;

folder.Files.Add(fileURL, fileContents);

if (folder.Files[fileURL].CheckedOutBy.Name != "")
{
folder.Files[fileURL].CheckIn("File Checked In");
}

return "File added successfully!";

}
catch (System.Exception ex)
{
return "Error: " + ex.Source + " - " + ex.Message;
}
}

12. Open Files.asmx markup page. In Solution Explorer, right-click Files.asmx and select View Markup. You will notice that the markup page has following line:


<%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="UploadService.Service1" %>


Change it to the following line:


<%@ WebService Language="C#" Class="UploadService.Files" %>

13. Create a strong name for the class library. In Solution Explorer, right-click the web service project, and in the Properties dialog box, click Signing, select Sign the assembly, and select in the box for choosing a strong name key file.

14. In the Create Strong Name Key dialog box, provide a file name for the key, deselect Protect my key file with a password, and click OK.

This was the easy way. You can also strong name your assembly using the command line utility called as sn.exe. Use following steps if you want to strong name your assembly manually:


1. Strong naming utility (sn.exe) can be found in the following folder: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

Copy the sn.exe utility to the folder where your assembly is located and run the following command to strong name your assembly:

sn.exe -k key.snk

Resulting key will be written to the key.snk file.

2. Go to your project's properties (right-click project name in the Solution Explorer and select Properties from the menu) and select Signing from the menu that appears on the left. This will open a form.

3. Check Sign the assembly checkbox and choose the key file from the drop down (Click the Browse... button in the drop down to locate the key.snk file that you generated in the previous step).

4. Re-compile your assembly.


15. Compile the web service project.

16. As we are developing this web service on a machine that does not host SharePoint, therefore, we need to create a virtual directory in IIS. Click Start, point to Administrative Tools (You may have to go to the Control Panel first to select Administrative Tools), and then click Internet Information Services (IIS) Manager.

Note: In case you are developing the service on a SharePoint server, then skip steps 17-20 and use following instructions and then start with step 22:


1. Copy the Files.asmx to the following folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

2. Run disco.exe (from C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin) at the command prompt from the LAYOUTS directory to generate .disco and .wsdl files.

Run a command in the following format to generate the files in LAYOUTS:

disco http://localhost/_layouts/Files.asmx

17. Expand the branch for the server computer to which you want to add a virtual directory. Under the server computer branch, expand the Web Sites folder, and right-click the Default Web Site and select New and then Virtual Directory.... If you don't want to use Default Web Site, you can create a new web site.

18. Click Next and enter an alias in the text box, for example, for this service you can enter UploadService.

19. Click Next and then click Browse... button to browse to the project folder (containing the .asmx file) and click Next.

20. Click Next again and then click Finish.

Generating and Modifying Static Discovery and WSDL Files

21. Use Disco.exe to generate .disco and .wsdl files. This command line utility is located in the following directory:

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

Open command prompt and type the following line and press Enter:

Disco http://localhost/uploadservice/Files.asmx

Make sure you have entered the correct path in the command above otherwise you will get an error. If you created a virtual directory on a port other than the port 80, then you must mention the port number in the path (For example, http://localhost:8080/uploadservice/Files.asmx). This will generate the .disco and .wsdl files.

22. To register namespaces of the Windows SharePoint Services object model, open both the .disco and .wsdl files and replace the opening XML processing instruction -- -- with instructions such as the following:


<%@ Page Language="C#" Inherits="System.Web.UI.Page"%>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<% Response.ContentType = "text/xml"; %>

23. In the .disco file, modify the contract reference and SOAP address tags to be like the following example, which replaces literal paths with code generated paths through use of the Microsoft.SharePoint.Utilities.SPEncode class, and which replaces the method name that is specified in the binding attribute:


<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %> docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q1="http://microsoft.com/sharepoint/webpartpages" binding="q1:WebPartPagesWebServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q2="http://microsoft.com/sharepoint/webpartpages" binding="q2:WebPartPagesWebServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

24. In the .wsdl file, make the following, similar substitution for the SOAP address that is specified:


<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

Make the following substitution for the SOAP12 address:


<soap12:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

25. Rename both files in the respective formats Filedisco.aspx and Fileswsdl.aspx so that your service is discoverable through SharePoint.

Deploying web service on the SharePoint server

Copy the Web service files to the _vti_bin virtual directory

26. Copy the web service files to the _vti_bin directory of the SharePoint server. Web service files that are to be copied are as following:

Files.asmx
Filesdisco.aspx
Fileswsdl.aspx

The _vti_bin virtual directory maps physically to the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI directory, which contains the default Web service files used in Windows SharePoint Services.

To include the Web service in the list of web services on the server

27. In Notepad, open the spsdisco.aspx file. spsdisco.aspx is located in the following directory (on the SharePoint server):

Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

28. Add the following lines to the end of the file within the discovery element and save the file:


<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %> docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q1="http://microsoft.com/sharepoint/webpartpages" binding="q1:WebPartPagesWebServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q2="http://microsoft.com/sharepoint/webpartpages" binding="q2:WebPartPagesWebServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

Copying the assembly to the correct Bin folder


29. I have seen blogs and forums where people have recommended to copy the assembly to the following folder:

Local_Drive:\program files\common files\microsoft shared\web server extensions\12\isapi\

Some people say it should be copied to the following folder:

Local_Drive:\Inetpub\wwwroot\bin

bin folder is not there by default and has to be created but safest place to copy the assembly is the bin folder of the virtual directory of the web application where you intend to use the web service. Following path contains the virtual directories of web applications that you have created on your SharePoint server.

Local_Drive:\Inetpub\wwwroot\wss\VirtualDirectories

For example, if you want to use the web service in web application at port 81, then you should copy the assembly to the following folder:

Local_Drive:\Inetpub\wwwroot\wss\VirtualDirectories\81\bin

Similarly, if you want to use the web service in web application at port 17316, then you should copy the assembly to the following folder:

Local_Drive:\Inetpub\wwwroot\wss\VirtualDirectories\17316\bin

I am not saying that you can not copy the assembly to the _vti_bin folder or wwwroot folder, of course you can but I have often seen people struggling with the service deployment. People often ask me where they should copy the assembly and what is the best place to put the assembly in. I tested my web service by putting the assembly file in all the recommended places and I found that bin folder of the virtual directory of the web application is the safest place where your web service is guaranteed to work.

Copy the assembly to the bin folder of the virtual directory of the web application of your choice. You will have to create the bin folder yourself. It is not there by default.


Adding web service to the GAC


30. You must add your assembly in the GAC on your SharePoint server. This is necessary otherwise you will get permissions error on the server. There are three ways to avoid this permissions error. One way is to add the assembly in the GAC. Second way is to change the trust level to medium in the web.config file and the third is to create a custom trust policy of your own. There is an article on Microsoft site that has all the details of Code Access Security (CAS) and it also shows how to create a custom policy file. Here is the article if you are interested in exploring this topic.

Unfortunately, this is an old version and works only with SharePoint 2003. I am not sure if Microsoft has already released an updated version of this article or not. I intend to write an updated version of this article (at least the custom policy file part) for Office SharePoint Server 2007 and Windows SharePoint Services 3.0.

To add your assembly to the Global Assembly Cache (GAC), you can either drag and drop the assembly into the %windows%\assembly directory using 2 instances of Windows Explorer, or use the command line utility gacutil.exe that is installed with the .NET Framework SDK 2.0. This utility is located in the following folder:

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

To use gacutil.exe to copy the class library DLL into the GAC

To open the Visual Studio command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and click Visual Studio 2005 Command Prompt.
At the command prompt type a command in the following form, and press ENTER:
gacutil.exe -i "".

You can also use ".NET Framework 2.0 Configuration" tool to add the assembly to the GAC.

1. Go to control panel, click Administrative Tools and select Microsoft .NET Framework 2.0 Configuration.

2. Click Manage the Assembly Cache and then select Add an Assembly to the Assembly Cache. Locate the assembly and click Open.

Creating a Windows Application to Consume the Web Service

After copying the Web services files to the _vti_bin directory, the next step is to create a Windows Application to consume the Web service.

31. Create a new C# Windows Application in Visual Studio 2005.

32. In Solution Explorer, right-click References, and then click Add Web Reference.

33. In the address bar of the Add Web Reference browser, type the URL for the site to which to apply the service, as follows, and then press ENTER:

http://localhost/_vti_bin/Files.asmx?wsdl

If you installed the service on another port, for example, port 17316, then the url would be:

http://localhost:17316/_vti_bin/Files.asmx?wsdl

You can also browse all web services available on the server. Files.asmx will be listed in the web services available on the server. There will be multiple entries, each entry representing the service available for a different web application. Therefore, if you want to upload documents to a site on port 80, then you should select Files.asmx for port 80.

34. Include following using directives at the top:

using System.Net;
using System.IO;

35. Add following code to your application:


try
{
localhost.Files oUploader = new localhost.Files();

oUploader.PreAuthenticate = true;
oUploader.Credentials = CredentialCache.DefaultCredentials;

string strPath = @"C:\test.doc";
string strFile = strPath.Substring(strPath.LastIndexOf("\\") + 1);

string strDestination = "
http://sp:17316/Docs";

FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 0, (int)fStream.Length);
fStream.Close();

string str = oUploader.UploadDocument(strFile, binFile, strDestination);
MessageBox.Show(str);
}
catch (Exception ex)
{
MessageBox.Show(ex.Source + " - " + ex.Message + " - " + ex.InnerException + " - " + ex.StackTrace);
}



localhost is the name of the web reference that you added in previous step. strPath contains the filename that is to be uploaded. This is just a sample to show you how the service works, that's why i have hard coded the filename but in a real life situation you may want to add a text box and a browse button to select files from your hard disk. strDestination contains the destination path. This should be the path representing the document library where file is to be uploaded.

36. Finally, before testing the service, make sure the current user has privileges to upload documents in the destination document library. The user should have "Contributor" rights in the document library otherwise, you will get "401: Unauthorized" error. Run the application to test the service.

Saturday, December 29, 2007

Building Master Pages for Windows SharePoint Services 3.0

See Also: http://msdn2.microsoft.com/en-us/library/bb687712.aspx

The Visual Studio 2005 extensions for Windows SharePoint Services 3.0 provide new support for creating SharePoint applications. The tools significantly simplify the process of creating SharePoint site definitions, with Microsoft Visual Studio 2005 automating the creation of the necessary content, configuration, and deployment files. This Office Visual How To illustrates how to build a Windows SharePoint Services 3.0 site definition and add a custom master page to the definition by using Visual Studio 2005 and Visual Studio 2005 extensions for Windows SharePoint Services 3.0.

How to install WSS and MOSS SP1

Service Pack 1 for SharePoint is here. The SharePoint Team blog has a great full length article on all of fixes and tweaks. You can read it here Announcing the Release of WSS 3.0 SP1 and Office SharePoint Server 2007 SP1.

This post is just meant to give you the easy version of the install instructions. If you have complex scenarios or have issues I highly recommend you read Planning and deploying SP1 for Microsoft Office SharePoint Server instead of my instructions. Cool?

Ok here is my setup that I am about to patch. Server 1 is the SQL 2005 SP2 database box. Server 2 is a Windows Server 2003 SP2 with MOSS 2007 Enterprise installed. I am doing everything on Server 2. I give you run times on the longer parts for reference points. Your times will vary!

  1. Backup SharePoint! Seriously handy little paper here if you need help.
  2. Download the software you need. For my servers I downloaded the 32 bit editions. You must install BOTH the WSS and MOSS update if you have MOSS installed.
    1. WSS SP1 downloads
    2. MOSS SP1 downloads
  3. Stop the World Wide Web Publishing Services to keep your users off the server.
    1. Start > Administrative Tools > Services
    2. Scroll to the bottom of the list, click World Wide Web Publishing Service
    3. Click the Stop button
  4. Install the Windows SharePoint Services Service Pack (total time less than 2 minutes)
    1. Find the downloaded file. For me this was wssv3sp1-kb936988-x86-fullfile-en-us.exe
    2. Double click to run the file
    3. Read the license terms, click accept
    4. Click continue
    5. At the reminder message click OK
    6. Now it starts processing the update.
    7. At the installation complete message click OK
  5. Now if you have just WSS skip to step 8
  6. If the configuration wizard opens close it.
  7. Install the MOSS update (total time less than 2 minutes)
    1. Find the downloaded file. For me this was officeserver2007sp1-kb936984-x86-fullfile-en-us.exe
    2. Double click to run the file
    3. Read the license terms, click accept
    4. Click continue
    5. At the reminder message click OK
    6. Now the update processes…
  8. Run SharePoint Configuration Wizard (15 minutes)
    1. Start > All Programs > Microsoft Office Server > SharePoint Product and Technologies Configuration Wizard
    2. Click Next at the Welcome screen
    3. Click Yes at the warning about restarting services
    4. Click Next at the Completing the SharePoint Product and Technologies Configuration Wizard
    5. Your server is now processing step 1
    6. You will be prompted to now install the updates on other servers in your farm. Click OK since you only have 1 SharePoint server.
      1. NOTE: If you did have multiple servers you would repeat all of the above steps on each of those servers before moving on. Also, if you are wondering you should probably start with the server that host central admin.
    7. Now your server is processing steps 2 through 9.
    8. Speaking of step 8 it took my server approximately 13 minutes to process 4.4 GB of content. I am sure your times will vary. Just don't panic on this step if it takes a while. It is essentially touching all of your content.
    9. At Configuration Successful click Finish
  9. Check out Central Admin
    1. Restart the World Wide Web Publishing service you stopped in step 2. If you had to reboot this is not necessary.
    2. Click Operations tab
    3. Under Topologies and Services click Servers in farm
    4. Next to your server you should see Version 12.0.0.6219 not 12.0.0.4518. If you do you should be good to go.

Thursday, December 27, 2007

Add Silverlight to Sharepoint 2007

Recently I was asked how to display Rich media (mainly video) in Sharepoint 2007 by our communications department. This shouldn't be too hard to do so time to whip up a quick demo/proof of concept to make sure that it in fact can be done, and what better way than to create a custom web part that embeds Microsoft's Silverlight.

Adding Silverlight to your web application is easy enough so it shouldn't be too difficult to do in Sharepoint 2007 either. There are a few different files that you will need in order to do this however, a couple of Javascript files, a XAML and of course your custom web part.

Silverlight

So kick off Visual Studio and lets get cracking.  First off we'll create the Javascript file that you will need (the other one you don't create, just copy from the SDK but more on that later).

I'm assuming that you have Sharepoint extensions for Visual Studio installed (currently available only for 2005 although a version for Visual Studio 2008 is apparently due out shortly).

Go to File/New and select New Project from the list of available options. Next within the C# Project Type folder, go to the Sharepoint folder and select Web Part. Call it SilverLightPart, give it a location and hit OK.  This will create the outline of the custom web part we'll create later.

Next right click on SilverLightPart project and select Add/New Item. In the dialog that pops up, click on the Visual C# Project Items under categories and select JScript for the Javascript file we'll create and call it CreateSilverLight.js.

The Javascript function that we'll create is a small function that simply kicks off the main Silverlight Javascript routine. Copy the following code into your blank Javascript file :-

function createSilverlight()

    Silverlight.createObject(
        "/_layouts/videoplayer.xaml",       // Source property value.
        parentElement,                      // DOM reference to hosting DIV tag.
        "myPlugin",                         // Unique plug-in ID value.
        {                                   // Plug-in properties.
            width:'320',                   // Width of rectangular region of plug-in in pixels.
            height:'200',                   // Height of rectangular region of plug-in in pixels.
            inplaceInstallPrompt:true,     // Determines whether to display in-place install prompt if invalid version is detected.
            background:'white',             // Background color of plug-in.
            isWindowless:'true',           // Determines whether to display plug-in in windowless mode.
            framerate:'24',                 // MaxFrameRate property value.
            version:'1.0'                   // Silverlight version.
        },
        {
            onError:null,                   // OnError property value -- event-handler function name.
            onLoad:null                     // OnLoad property value -- event-handler function name.
        },
        null,                               // initParams -- user-settable string for information passing.
        null);                              // Context value -- passed to Silverlight.js onLoad event handlers.
}

The code is commented so it's fairly self explanatory. Here we are instantiating the actual Silverlight object. This takes a number of parameters. The first parameter is where the Silverlight object can find the associated XAML file that it requires, next is a reference to a DIV tag that Silverlight will be embedded in, the third parameter is a Unique ID for the plugin followed by a number of parameters giving the width, height, framerate of the video etc. etc.

In the above code, the only parameter that I am effectively passing in is the parentElement parameter, however in your own code you may want to pass in parameters for the XAML file, the width and height properties and a Unique ID. And that's all there is to this file.

Next we want to create the XAML file that this script references, so add an XML file to your project and call it VideoPlayer.XAML. Delete the default <xml> tag that has been created and insert the following :-

<Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="root"
        >
    <Canvas x:Name="VideoLayer">
        <MediaElement x:Name="media" Source="http://download.microsoft.com/download/d/e/2/de2bec9c-4ba1-406e-8029-5c4767dca3eb/WPFE_Getting_Started_2MB_Ch9.wmv"
            Width="300" Height="200" />

    </Canvas>
</Canvas>

Here we are defining the root element to be a canvas (just like the canvas painters use to paint on, a blank area with potential) and pointing to the relevant xml namespaces required for XAML files. Next we create our actual Canvas in which we will display our video file. The video file is marked up in XAML using the <MediaElement>  tag and here we simply point it to a video that we wish to display and give it a width and height (width and height are optional but if you do input these they are in pixels. You cannot use percentages e.g. 100%).  Since this is just a proof of concept we'll end things here. You can of course add whatever you like to the XAML file, video controls for play, pause etc. and hook into Javascript events that will deal with them, skin it to give it your own personal touch, overlay controls or text etc. For more information on how to do these things you may want to take a look at the excellent Quick Start videos that are freely available on MSDN at the moment.

The last Javascript file that you will need is the actual Silverlight javascript file itself. In order to get this file you will need to download a copy of the SDK found here.

OK so that is the ancillary files out of the way, next we start on the web part itself. I'm not going to do anything fancy here, simply display the Silverlight control which has the video file hard coded within it, however you may want to create your own web part editor and add inputs so that an end user could select the video source, change the width and height etc.
Back to our web part. Open the SilverLightPart.cs file. As you will see, the Microsoft Sharepoint template that you loaded from has already given you an outline to what you will need, so all we need to do is flesh it out a bit. Here is the finished code :-

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using System.Security.Permissions;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

[assembly: AllowPartiallyTrustedCallers]
namespace SilverLightPart
{
    [Guid("07cd69ef-44e8-403a-93d8-9aa2bdb4f37a")]
    public class SilverLightPart : System.Web.UI.WebControls.WebParts.WebPart
    {
        public SilverLightPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<div id='slControlHost'>\n");
            writer.Write("<script type='text/javascript'>\n");
            writer.Write("var parentElement = document.getElementById('slControlHost');\n");
            writer.Write("createSilverlight();\n");
            writer.Write("</script>\n");
            writer.Write("</div>");
        }

        protected override void OnPreRender(EventArgs e)
        {
            string script = "<script type='text/javascript' src='/_layouts/CreateSilverlight.js'></script>\n";
            string script2 = "<script type='text/javascript' src='/_layouts/Silverlight.js'></script>\n";
            if (!Page.ClientScript.IsClientScriptBlockRegistered("Silverlight"))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Silverlight", script2);
            }
            if (!Page.ClientScript.IsClientScriptBlockRegistered("CreateSilverlight"))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateSilverlight", script);
            }
            base.OnPreRender(e);
        }
    }
}

First we've added a couple of extra namespaces and the Assembly reference to allow for partially trusted callers. This is a security setting used within Sharepoint. Each web part has to have it's own GUID but this is already supplied for you by the template (as well as the .snk file for signing your DLL when you build it amongst other things).

Next we have the constructor. As this is essentially an ASP.Net 2.0 web part and not specifically a Sharepoint web part, this setting allows you to export this web part so that you can use it in other sites. This isn't actually required for a Sharepoint web part and you can feel free to delete ExportMode line, however you do require a constructor, even if it's blank.

Next we have the Render method. The contents in here is actually what will be written to the page. As this was just a proof of concept, I hard coded these lines, however if you were actually building this web part for deployment you might want to use RenderBeginTag, RenderEndTag and AddAttribute methods instead.
Here all that we're doing is defining is DIV which will hold the silverlight control, then adding some javascript to create the variable parentElement and call the createSilverLight Javascript function we defined earlier. As you may remember, the parentElement variable is actually used within createSilverLight function to tell the Silverlight control where to display.

Finally we override the OnPreRender event. We have to add our two Javascript files to the page. Here we're simply saying that if these Javascript files aren't contained within the page, then add the references to them.

And that's it. Build your project and next we'll deploy it.

First things first, we want a place that we can add the Javascript and XAML files to so that they can be references no matter where you deploy the web part within the site. As you may have picked up from the source above, I've chosen the _Layout directory as this is globally accessible.
Within Windows Explorer, navigate to  C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Template\Layout and copy both the Javascript files (Silverlight.js and CreateSilverLight.js) and the XAML file (VideoPlayer.XAML) into this directory.
Next navigate back to where you created your project and copy the dll from the bin directory to the clipboard (CTRL + C or right click the file and select copy). Now navigate to your Sharepoint site. This will normally be found under the c:\inetpub\wwwroot directory then navigate to your sharepoint sites' bin directory (your sharepoint site may be under the wss\VirtualDirectories folder within the wwwroot folder) and paste the dll into the bin directory.

Nearly done, next we have to ammend the web.config file to tell Sharepoint that our web control is safe to use. So open the web.config file for your site in either Visual Studio or notepad and add this to the end of the list of SafeControls already defined there :-

<SafeControl Assembly="SilverLightPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="SilverLightPart" TypeName="*" Safe="True" />

As we've changed the web.config file it's always best to do an IISReset so that Sharepoint will immediately pick up the new config file.
Now open your Sharepoint site, and under the Site Actions menu select Site Settings and Modify All Site Settings. From the page that appears, click on the "Web Parts" link under the Galleries heading then click on New. Find the Silverlight webpart and select the checkbox next to it then click on the Populate Gallery button at the top.

All that is left is to add your new Silverlight video streaming web part to your page. Navigate to the Sharepoint page where you wish to add this web part, select Edit Page from under the Site Actions menu, click on one of the Add Web Part links that are on the page and add the SilverlightPart web part to your page (found under Miscellaneous).

Sharepoint

And there you have it, how to add Silverlight to your Sharepoint 2007 site.