Wednesday, May 27, 2009

Enable Anonymous Access on a SharePoint Site

Today I was working on a SharePoint site that needed to be accessed by people outside of our domain.  Assuming you have your site created in the stand way, Users would normally access it via the NTML (windows Challenge/Response) protocol, i.e. SharePoint knows who you are from your domain login.  This was not possible for my Users as they would not be allowed have usernames on our domain.  Therefore the solution was to enable Anonymous access to the site.

1) Access SharePoint Central Administration and select Application Management from the left hand links.

2) Under Application Security select Authentication providers, then select the Web Application using the drop down on the tool bar.  In my case it was “SharePointPortal – 80”.

image 

3) Click on the” Default” zone link and tick the “Enable anonymous access” check box and press Save.

image

This enables Anonymous access on the Server, however each site still needs to be configured to use this setting.  This prevents people from making information available to external sources in error.

4) On the specific site login as the SharePoint Administrator or another User who has assess to the SharePoint Site Settings menu.  From the SharePoint Site Setting screen select “Advanced Permissions”

image

5) From the Advanced Permissions page select Settings/Anonymous Access from the toolbar menu.  When that screen appears you can select the level of access an anonymous user can see information.

image

The options are self explanatorily and in my case Entire Web site was the correct option.  Save this option by Clicking OK.

The site should now be accessible to external Users to view.

Tuesday, May 26, 2009

Google killer? Probably not

Keeping track of new developments on the net is never easy, there is so much going on that usually its all just white noise.  Every now and again you do come across something interesting so I figured I’d do a post in case someone else gets some ideas.

It was all over the recent Tech news that there was a new browser in town called Wolfram Alpha.  This takes a different approach from Google in two ways. First is that it’s a closed system i.e. only information that is vetted by experts is allowed in, which will supposedly increase accuracy. Second is that it takes real English questions like “population of Ireland in 2008” or “convert 100 euro to US dollar”.

image

Having played with it for a while I’m not really impressed, but it’s an interesting idea.

Error running Powershell Scripts

Now that I’m generating Sharepoint sites using Powershell scripts I noticed an error appearing on the servers.

"File xxx cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.".

image

Turns out that for security reasons running scripts this way is disabled by default.  Check out this blog posting for more information on the various options available.

Solution

From within Powershell type the command “Set-ExecutionPolicy Unrestricted” and then “exit”.

Friday, May 1, 2009

SharePoint Development – Creating a webpart

This is the first of many posts which will try to put together the steps you need to develop within the SharePoint platform.  First off it I’ll describe creating a simple WebPart that puts a message on the page. 

Creating the solution

To help with the general issue of creating your Visual Studio 2008 solution we use a handy tool called STSDEV.  More information on this can be found on the projects homepage on Codeplex

Browse to c:\Program Files\StsDev\ and run StsDev.exe.

image

Enter the name of the solution you want to create, in this example I’ll use “EIWebPart”.  Browse to D:\Development\EIPortal\ as the Parent directory.  Select C:\development\eiportal\eiportal.snk as the Signing Key (you can get the latest version of this from SourceSafe).  Select “Web Part Solution (C# Assembly) as the solution type and “Visual Studio 2005 with .Net 3.0” as the version type.  “Why?” I hear you ask?  Well because the version of STSDEV on the VM is not working for some reason and I’ve not had a chance to find out why. yet….

image

All going well, you should see this message.

Working in Visual Studio

Browse to the location shown by STSDEV and open the solution file, allowing for the usual conversion questions for an upgrade to Visual Studio 2008.  The conversion should happen without any errors.

image

You’ll end up with a solution with the following structure.  This structure is very important to sharePoint development as it exactly matches the “12” (aka. “Hive” or “12 Hive”) directory on the server.  The various XML files are also very important as these are used when building and deploying solution.

  • feature.xml – contains the link to the webparts file, version numbers and feature information for the solution.
  • webparts.xml – contains the links to the various webparts in our feature.
  • CustomWebPart1.cs is the code file containing all our work.

We only want one webpart in our solution to I remove from the feature.xml and webparts.xml all references to CustomWebpart2.cs.  Delete the CustomWebPart2.cs and CustomWebPart2.webpart files.

CustomWebPart1.cs

Is a very simple file, it simply adds a able to the page and fills it with the text “Hello”.

protected override void CreateChildControls() {
  Label lblHello = new Label();
  lblHello.Text = "Hello";
  Controls.Add(lblHello);
}

Webparts work and a coded exactly the same as ASPX files, the only exception is that you can’t use the design pallet.  That means you can drag a Text Box from the Tools and have VS create the code for you, you need to hand code this.  My advice is to keep your webparts simple and avoid anything to crazy like messing with viewstate or late data binding.

feature.xml

This feature file contains the information about your feature, it’s name a description, version number etc.  If lets as your feature contained lots of different parts, each part would have an entry in the ElementManifests section.

<Feature
  Id="6FA7C22C-52A7-4A46-B944-44E5E7FECE2B"
  Title="A sample feature: EIWebPart"
  Description="This SharePoint solution was created by the STSDEV utility (http://codeplex.com/stsdev)"
  Version="1.0.0.0"
  Scope="Site"
  Hidden="false"
  ImageUrl="EIWebPart\AfricanPith32.gif" xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest
      Location="WebParts.xml" />
    <ElementFile
      Location="WebParts\CustomWebPart1.webpart" />
  </ElementManifests>
</Feature>

I’m not going to worry about changing anything here, I’m sure you get the idea.

WebParts.xml

Again a simple file that just points to each webpart contained in the feature.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="EIWebPart" List="113" Url="_catalogs/wp" Path="WebParts" RootWebOnly="True">
    <File Url="CustomWebPart1.webpart" Type="GhostableInLibrary">
      <Property Name="Group" Value="EIWebPart" />
    </File>
  </Module>
</Elements>

CustomWebPart1.webpart

This file is one to watch, it contains all the information needed for the user to interact with the webpart.

<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="EIWebPart.CustomWebPart1, EIWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=eb8e38decd6217c5" />
      <importErrorMessage>Error importing Web Part</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="Title" type="string">Default title for CustomWebPart1</property>
        <property name="Description" type="string">A demo Web Part created by stsdev</property>
        <property name="ChromeState" type="chromestate">Normal</property>
        <property name="AllowZoneChange" type="bool">True</property>
        <property name="AllowHide" type="bool">True</property>
        <property name="ExportMode" type="exportmode">All</property>
      </properties>
    </data>
  </webPart>
</webParts>

You get certain properties by default but you can add other is you want.  A good example would be if you wanted to know which Database to connect to, you may have a <property name="DB" type="string">DevWebCDB</property> entry in this file.  While in your C# file you have a public property called DB {get; set;} which your code can use.  But the SharePoint admin can use the SharePoint UI to change this value to anything else later.  This is very handy, but out of scope of what I’m trying to do at the moment.

Ready to go!

All you need to do now is compile the solution, so your configuration should be set to “DebugBuild”.  If everything is building correctly you only need to change this to “DebugDeploy” and build the solution again to place your feature into the servers “12 Hive” directory.  Cool or what!!

image

If you look in the output window you’ll see a whole bunch of STSAdmin commands which is Visual Studio building and then deploying your feature.  You could do this manually, but if VS does all the work anyway, what’s the point of that?

Browse to one of the sites on your VM. 

image

Select “Site Actions” / “Site Settings” from the control menu.  Then select “Site collection Features” on the page. You’ll see that on the last column on the right hand side.

image

An here we go, our new webpart has been added as a resource that an be used by any site collection.  Click “Activate”.  Then browse back to the Americas home page. 

Select “Site Actions”/”Edit Page” and click “Add Webpart” at the top of the first Web Part Zone.

image

Scroll down a bit and you’ll see our webpart, click the check box next to it and click “Add”, then “Exit Page Edit”.

image

The Webpart should appear on the top of the page.