Thursday, November 01, 2007

Creating Web Part Page libraries in WSS 3.0

We were trying to programmatically provision a library to store web-part pages, and to make sure that the web-part page would be the default template. Ended up with the code below. If there is a smarter way, please point me in the right direction !!

 

private static void ProvisionPageLibrary(SPWeb targetWeb, string libraryName, string libraryDescription)
        {
            //Work out the index of the Web Part Page in the DocTemplates as there is no text indexer
            bool foundWebPartPage = false;
            int counter = 0;
            int webPartPageIndex=0;
            try
            {
                while (!foundWebPartPage && counter <= targetWeb.DocTemplates.Count)
                {
                    if (String.Compare(targetWeb.DocTemplates[counter].Name, "Web Part Page", true, CultureInfo.InvariantCulture) == 0)
                    {
                        webPartPageIndex = counter;
                        foundWebPartPage = true;
                    }
                    counter++;
                }
                if (foundWebPartPage)
                {
                    targetWeb.Lists.Add(libraryName, libraryDescription, targetWeb.ListTemplates["Document Library"], targetWeb.DocTemplates[webPartPageIndex]);
                }
            }
            catch
            {
                //DoSomething meaningful
            }
        }

Wednesday, July 04, 2007

Updating SharePoint List Items using the Web Services

We had a dumb bug today when trying to update List Items through the UpdateListItems web-service call.

Finally tracked the error down to the "Batch" element not being capitalised.

All that we got back was a SOAP exception, so if you are having trouble with the call, check the exact content of the update message....

Wednesday, June 27, 2007

Custom Field Editors

This is a great thread about creating editor controls for custom field types in MOSS/WSS 3.0

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1109290&SiteID=1

Technorati Tags: , , ,

Friday, June 15, 2007

MOSS Custom Field Types

Custom field types allow you specify properties for the new field, such as the BusinessDataType in the schema below:

<PropertySchema>
            <Fields>
                <Field Name="BusinessDataType" DisplayName="Business Data Type" Type="Choice">
                    <CHOICES>
                        <CHOICE>Customers</CHOICE>
                        <CHOICE>Partners</CHOICE>
                    </CHOICES>
                    <Default>Customers</Default>
                </Field>
            </Fields>
        </PropertySchema>

When attempting to retrieve values from this schema in a custom field control you need to use the Field.GetCustomProperty method, as there is no Fields collection exposed.

del.icio.us Tags: , , ,

Thursday, June 14, 2007

Adding Columns to a GridView

Working with the new GridView control, I was struggling for a while with the change from the DataGrid OM...

Using the BoundField object solved the problem..

BoundField newField = new BoundField();
newField.DataField = thisColumn.DataColumnName;
newField.HeaderText = thisColumn.DisplayName;
grdResults.Columns.Add(newField);

Friday, May 25, 2007

WSS 3.0 Cross List Query (Aggregation)

The following code walks recursively down through document libraries below a given web, returning all documents

static void Main(string[] args)
{
using (SPSite rootSite = new SPSite("http://wss30"))
{

using (SPWeb site = rootSite.OpenWeb())
{
SPSiteDataQuery query = new SPSiteDataQuery();

string strOrderBy = "<OrderBy><FieldRef Name="FileRef" /></OrderBy>";
query.Query = strOrderBy;
query.Lists = "<Lists ServerTemplate="101" />";
query.ViewFields = "<FieldRef Name="Title" />";
query.Webs = "<Webs Scope="Recursive" />";

DataTable dtResults = site.GetSiteData(query);
}
}

}