Thursday 31 January 2008

Call of Duty 4:Modern Warfare

Just a side note I made it to the 1st prestige level last night and decided to go for and start the ranking again.

Wednesday 30 January 2008

I'm looking at setting the search scope and results page for our dev MOSS 2007 installation.

After setting the scope for the Shared Service Provider (SSP) it appears that this is used for all sites that use this SSP - that may cause a problem if we are going to use the same SSP for our public Internet facing site and an Extranet/Intranet. So more reading required. If anyone has the answer drop me a line here.

With the settings I have I want to restrict anon users, from our Internet access, from searching on the lists that we have set up for populating drop downs.

Thursday 24 January 2008

Web Part bin vs _app_bin vs GAC

I thought I'd just post this up. After struggling with the creation of the webpart that displays drop downs using the SharePoint Object Model (i.e. SPSite and SPList) to get to the lists it turns out that the errors are related to the permission that the part has to this object model. (No surprise there then)

What was surprising was that there were a number of different solutions to the problem:

1. Install the dll into the bin
2. Install the dll into the GAC
3. Install the dll into the _app_bin

If the dll is installed into the GAC then it runs under full trust, if you install into the bin then Code Access Security Policy has to be applied and the wss_minimaltrust.config has to be edited, or installing into the _app_bin runs OK.

So far I have not found a definitive solution - even from good sources the response seems to be mixed as the best place for these dll's.

Well happy days!!

Friday 18 January 2008

MOSS 2007 WebPart

Here is some code for a WebPart that is a clickable image (you'll need to edit the out HTML):

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;


namespace FMWebPartImage
{
[Guid("4f37cd37-d097-41c1-9c1c-37d8faea816d")]
[XmlRoot(Namespace = "FMWebPartImage")]
[ToolboxData("<{0}:WebPart1 runat=server>")]
public class FMWebPartImage : Microsoft.SharePoint.WebPartPages.WebPart
{
public FMWebPartImage()
{
this.ExportMode = WebPartExportMode.NonSensitiveData; //Set so no export
this.ChromeType = PartChromeType.None; //Set so no title by default
}
protected string imageLocation = "";
protected string imageAlternateText = "";
protected string imageURL = "";
protected int imageHeight = 100;
protected int imageWidth = 100;
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("Location"),
Description("Location of image")]
public string ImageLocation
{
get
{
return this.imageLocation;
}
set
{
this.imageLocation = value;
}
}
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("Alternate Text"),
Description("Alternate text for image")]
public string ImageAlternateText
{
get
{
return this.imageAlternateText;
}
set
{
this.imageAlternateText = value;
}
}
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("Image Url"),
Description("Image click goto Url")]
public string ImageClickUrl
{
get
{
return this.imageURL;
}
set
{
this.imageURL = value;
}
}
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(100),
WebPartStorage(Storage.Shared),
FriendlyName("Height"),
Description("Height of image")]
public int ImageHeight
{
get
{
return this.imageHeight;
}
set
{
this.imageHeight = value;
}
}
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(100),
WebPartStorage(Storage.Shared),
FriendlyName("Width"),
Description("Width of image")]
public int ImageWidth
{
get
{
return this.imageWidth;
}
set
{
this.imageWidth = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
string outHTML =
"<a href='" + imageURL + "' style='text-decoration:none;'><img src = '" + imageLocation +
"' alt = '" + imageAlternateText +
"' height = '" + imageHeight +
"' width = '" + imageWidth +
"' /%gt;</a>";
writer.Write(outHTML);
}
}
}

MOSS 2007 Webparts

After much searching and hitting my head on the desk I got the following to work: I was looking at getting a drop down on a web page, for our public facing MOSS site, that has a list of items from a list. Here is the code (there is still an issue if I create another WP, pointing to a different list, and add it to the page - it raises a DISP_E_EXCEPTION)

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace ListMenu
{
[XmlRoot(Namespace="ListMenu")]
[Guid("F10D314C-6CFF-4098-BF03-4F763099B0A5")]
[ToolboxData("<{0}:LocationDetail runat=server>")]
public class ListMenuLocation : Microsoft.SharePoint.WebPartPages.WebPart
{
private DataTable tblLocation;
///
/// Set the Export Type, Chrome State/Type of the Web Part
///

public ListMenuLocation()
{
this.ExportMode = WebPartExportMode.NonSensitiveData;
this.ChromeState = PartChromeState.Normal;
this.ChromeType = PartChromeType.None;
}
///
/// Populate the DataTable with the publicly visible location
///

private void PopulateDataTable()
{
try
{
tblLocation = new DataTable();
using (SPSite spSite = SPContext.Current.Site)
{
SPList spList = spSite.AllWebs[0].Lists["Locations"];
SPQuery oQuery = new SPQuery();
...

SPListItemCollection spLIC = spList.GetItems(oQuery);
tblLocation = spLIC.GetDataTable();
}
}
catch (SPException ex)
{ throw ex; }
catch (Exception ex)
{ throw ex; }
}
protected override void CreateChildControls()
{
try
{
PopulateDataTable();
CreateDropDown();
base.CreateChildControls();
}
catch(Exception ex)
{
System.Web.UI.WebControls.TextBox message = new TextBox();
this.Controls.Add(message);
message.Visible = false;
message.Text = ex.Message.ToString();
}
}
///
/// Create and Populate the drop down
///

private void CreateDropDown()
{
System.Web.UI.WebControls.DropDownList ddlLocation = new DropDownList();
ddlLocation.ID = "LocationDropDown";
ddlLocation.DataSource = tblLocation;
ddlLocation.DataTextField = "Title";
ddlLocation.DataValueField = "TabID";
ddlLocation.DataBind();
ddlLocation.Items.Insert(0, new ListItem("Please select...", "0"));
ddlLocation.SelectedIndexChanged += new EventHandler(ddlLocation_SelectedIndexChanged);
this.Controls.Add(ddlLocation);
}
void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
...

WriteOutURL(redirectTo);
}
///
/// Write out the location for the redirect to a text box.
///

/// string: Redirect URL
private void WriteOutURL(string url)
{
...

}
}
}