All posts by yen

The Poor Man’s Client-Side Authentication

Recently I had to whip up a quick Web page to disseminate some information requiring a semblance of security in the form of a user name and password. Furthermore, I had HTML and Javascript but no server-side scripting at my immediate disposal. What I came up with as a solution was this.

  • Create a form for entering user name and password. This doesn’t have to be any more complicated than two input fields:
<label>User name:</label>
<input type='text" id='username" />
<input type='password" id='password" />
  • Add a button to submit the form:
<input id="btnSubmit" type="button" value="Submit" onclick="javascript:go()" />

Continue reading The Poor Man’s Client-Side Authentication

How to create a web part containing ASP.NET AJAX-enabled user control in SharePoint 2010

There are existing guides to creating a web part that hosts a user control and others on creating an ASP.NET AJAX-enabled web part. Here I’ll discuss how to create a web part that combines both features. With the user control, you can perform complex layout more easily using the visual designer. And of course, with ASP.NET AJAX you can eliminate full-page postbacks and provide users with a smoother browsing experience.

The walkthrough includes a SoftArtisans.Tutorial.AjaxWebPart for SharePoint 2010 (it can be made to work for SharePoint 2007 with little modification).

SharePoint and ASP.NET AJAX
With SharePoint 2007, the first step would be to configure SharePoint to use ASP.NET AJAX. Fortunately, SharePoint 2010 is already enabled for ASP.NET AJAX, so you can avoid performing error-prone surgery on Web.config.

Step 1: Creating the project

While there are SharePoint project templates, I prefer to use a basic project template for the maximum control and flexibility. It is also more instructive to delve into the nuts and bolts rather than have everything generated for you. Continue reading How to create a web part containing ASP.NET AJAX-enabled user control in SharePoint 2010

How to create a dynamic Reporting Services Shared Data Source Using Linked Servers

When using SQL Server Reporting Services (SSRS), wouldn’t it be nice to be able to specify the data source at run time? For example, you could deploy a report on a single Report Server, but have the ability to retrieve data from any database on any server. Without a dynamic data source, you would have to deploy multiple instances of the report, one for each database server you want to use. Additionally, if you are using stored procedures, you must also duplicate them on each database server.

SSRS already allows for a dynamic data source through an expression-based connection string. The main limitation is that an expression-based connection string can only be used with an embedded data source; i.e., one that is contained in the report definition. You cannot use it with a shared data source. However, a shared data source offers advantages over an embedded data source and is often a necessity. Imagine having to modify the data source for hundreds of reports. With an embedded data source you would have to edit every report, while with a shared data source you could do so in just one place.

This post discusses a solution that lets you specify the database server at run time, while still being able to use a shared data source. The solution uses linked servers. A linked server is essentially an alias for a remote server on a local server. Once defined, a linked server allows you to execute queries on the remote server locally. This solution consists of the following steps: Continue reading How to create a dynamic Reporting Services Shared Data Source Using Linked Servers

Considerations When Using View in CAML Search

I recently worked on a web part which processes test scores for students. Test scores are stored in a list, organized by course and by user. The web part should retrieve the test scores for the logged in user, then the user’s score for each course. A previous implementation used a view, My Scores, which showed test scores for the logged in user by defining a filter, “Username is equal to [Me]”.

It occurred to me to retrieve a user’s test score for a course by performing a CAML search on the My Scores view. Typically, when searching a list using a CAML query, you can do something like this:

SPQuery query = new SPQuery();
query.Query = <query for course>;
results = list.GetItems(query);

There is an overloaded version of the SPQuery constructor that takes an SPView. Additionally, SPList.GetItems has an overloaded version that also takes an SPView. Given the availability of the SPView parameter, I was tempted to perform the CAML search on the My Scores view by doing the following: Continue reading Considerations When Using View in CAML Search

Automating Installation and Uninstallation for SharePoint 2010 Farm Solution

I’ve been trying to figure out how to automate the process for uninstalling a farm solution in SharePoint 2010. This is a two-step process:

  1. Retract the solution from the farm
  2. Remove it from the solution store

Unfortunately, you can’t perform the second operation right after the first, because there’s a delay when SharePoint retracts a solution. The delay can be several seconds, so you can either wait, or do something else while remembering to perform the second step.

Similarly, when installing a farm solution, you must first add it to the solution store before deploying it. Deployment can also take several seconds. In this case the delay is less inconvenient because you can let it run and work on something else, but it’d be nice to know when deployment completes. Continue reading Automating Installation and Uninstallation for SharePoint 2010 Farm Solution

SharePoint 2010 Sandbox Solution Failure with Single Dot Path

Converting a SharePoint 2007 solution to SharePoint 2010 is straightforward. In fact, other than recompiling the Visual Studio project with the SharePoint 2010 DLLs, you do not have to do anything else at all. When it comes to deploying the solution in SharePoint 2010, you can deploy it as a farm solution or a sandboxed solution. A farm solution is the same as a SharePoint 2007 solution; it is scoped to the farm level and operates with full trust. A sandboxed solution is scoped to a site collection and is limited in capabilities, but it offers certain benefits to both farm administrator and developers. The distinction between a farm and sandboxed solution lies in the deployment process, not in the solution package (which is the same in both cases).

After recompiling a project for SharePoint 2010, I was able to deploy it successfully as a farm solution. I then attempted to deploy the same solution package as a sandboxed solution. The first step was to add the solution package to the solution store with the following PowerShell cmdlet:

add-spusersolution -literalpath C:\solutions\SoftArtisansTutorial.wsp -site http://echo/sites/postone

However, this immediately resulted in the following error:

Add-SPUserSolution : The manifest.xml file could not be found within “SoftArtisansTutorial.wsp”. Continue reading SharePoint 2010 Sandbox Solution Failure with Single Dot Path

Managing SharePoint 2010 Farm Solutions with Windows PowerShell

In SharePoint 2007, you can manage solutions using the stsadm command. In SharePoint 2010, stsadm still works, but is deprecated in favor of PowerShell cmdlets. Whereas with stsadm you use a command-line switch to specify the operation to perform, with PowerShell you use separate cmdlets. Below are the list of stsadm commands and equivalent PowerShell commands for common tasks to manage a farm solution. SharePoint 2010 also includes support for sandbox solutions. While they are not discussed here, you’d use similar cmdlets to manage them as well.

When running a cmdlet, the cmdlet returns right away, but the operation will take some time to complete. If you attempt to execute one cmdlet immediately after another, you may get an error if the previous operation hasn’t finished running.

To get further information on a cmdlet, for instance add-spsolution, just type get-help add-spsolution in PowerShell. Continue reading Managing SharePoint 2010 Farm Solutions with Windows PowerShell

Targeting a SharePoint Site in a Custom Action

In my initial attempt to create a custom action for a SharePoint list, I specified it as follows:

    Title="Export to SoftArtisans OfficeWriter for Excel"
    <UrlAction Url="/_layouts/SoftArtisansTutorial/ExcelWriter.aspx?ListId={ListId}"/>

WSS replaces the special {ListId} token with the actual id of the list. In the application page I tried to retrieve the list from which the action had originated as follows:

SPWeb web = SPContext.Current.Web;
string listId = Request.QueryString["ListId"];
SPList list = web.Lists[new Guid(listId)];

However, I found that SPContext.Current.Web always returned the root-level Web site, even if the action was activated from a child site. So I modified the URL of the action to include the URL of the site: Continue reading Targeting a SharePoint Site in a Custom Action

Adding a View When Provisioning a Custom List

When creating a custom list, you need to provide a list definition in the form of a schema.xml file. Rather than creating a schema.xml file from scratch, a recommended approach is to copy an existing list definition. The out-of-the-box SharePoint custom list is a good starting point as it provides the barest minimum of features required. Armed with a stock list definition, you need to modify it for the list you want to create. If you want to use a specific content type, you can specify it in the <ContentTypes> section. You need to specify the columns of the list in the <Fields> section. Finally, you will want to modify the view definition to specify the columns to be included in the view.

Modifying an existing list definition is a quick way to create a custom list. Often, however, you will want to have more control over the view definition other than what fields are included in it. The view definition is the largest section in the schema.xml and can be rather daunting. Here is where SharePoint Manager comes in. Continue reading Adding a View When Provisioning a Custom List

Defining Managed Path When Creating New SharePoint Site

I needed to create a new sub-site underneath an existing SharePoint site, which is located at http://server/site1. The sub-site’s URL should be http://server/site1/site2. The simplest way to create a new site is to use an option normally exposed through the UI, such as the Create page under the Site Actions menu. However, in this case, I’m working with an existing site that’s customized so that the Site Actions menu isn’t available.

The first idea that occurred to me was to use Central Adminitration to add a new site collection. To do so, I selected Create Site Collection under the Application Management menu. In order to create the new site collection under the desired path, I decided to define site1 as a managed path. This worked well enough and allowed me to create a new site collection under http://server/site1/site2. However, to my horror I discovered that the site located at http://server/site1 had disappeared, replaced by the dreaded HTTP 404 screen! Continue reading Defining Managed Path When Creating New SharePoint Site