Showing posts with label WebPart. Show all posts
Showing posts with label WebPart. Show all posts

Thursday, 15 January 2009

Remote debugging

I was looking at a way to get remote debugging working for debugging MOSS custom webparts from an VS2008/XP PC to the Win2003 server running MOSS.

The section “The Remote Debugging Monitor is the one accepting your debug calls and the talking back to Visual Studio on your client, so to get these things to work you have to start the client as the user running Visual Studio (or have administrative permissions on the client). You can either log in to the remote host using that user or, as I prefer, right-click on the msvsmon.exe and choose Run As... Make sure that the user you are using to run the monitor with is member of the local Administrators group.” was a ‘gotcha’ that I missed first time round.

http://www.wictorwilen.se/Post/How-to-get-Remote-Debugging-work-properly.aspx

Do remember that when you attach to the w3p process during debugging it will prevent other users on MOSS from performing any actions.

Friday, 19 December 2008

Removing Webparts

I had an instance where I needed to remove webparts from a page but MOSS would allow it in the usual manner directly from the page. To get around this append ?contents=1 to the url and you can check off which parts to remove – the page needs to be in edit mode for this to work.

Wednesday, 20 February 2008

MOSS 2007 Webpart Control Events not Firing

I found this an 'interesting one'.

protected override void CreateChildControls()
{
try
{
PopulateDataTable();
CreateDropDown();
base.CreateChildControls();
}
catch(Exception ex)
{...}
}

When creating a Webpart and I had the events wired up in the CreateDropDown() they would not fire but when I moved them into the CreateChildControls() they did!

All the CreateDropDown() did was populate a drop down from the table created in the PopulateDataTable() and wire up the Click event.

I haven't found an answer yet as to why this would happen but I'll look into it later but it worked for me.

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)
{
...

}
}
}