Minimal adding pages to sharepoint

The following is the boo source to a utility that can be used to add pages to a SharePoint site.
No feature required!

=== addpage.boo ===
import Microsoft.SharePoint
import System.IO

def addPage(_site as string, _web as string, _page as string, _url as string):
    site = SPSite(_site)
    web = site.OpenWeb(_web)
    folder = web.GetFolder(“”)
    folder.Files.Add(_url, File.OpenRead(_page), true)
    
addPage(argv[0], argv[1], argv[2], argv[3])    

BDC Columns

This is another technique for adding BDC columns in a feature specific manner.

The BDC in SharePoint (which is only available in the paid-for MOSS edition of SharePoint) allows you to add external business data to a SharePoint list.  There are several catches:

  • The document that you need to enable this is complex and really requires an expensive tool (such as Bdc Metaman – which is useful but not ideal).
  • Normally you must add the BDC column to the site via a GUI (I have found a way to do this in code see another post for today).
  • The business data is cached in the sharepoint list until it is explicitly refreshed. The GUI refresh only provides an all the list refresh option (this can be done in code for a specific row).
  • You are limited to data sources that have a .Net 2.0 database driver (Sybase does not have one out of the box and the Data Direct one is very expensive).  Alternatively you can write a web service to fetch the data.
The BDC is powerful but needs a lot of work to get it going – possibly more than a custom solution would require…

Warmup script for sharepoint

I have seen a number of these around.  Most are copies of a broken script.  This one works.

The first component is a boo script:

This requires the Boo.Lang.Dll and needs to be compiled with the boo compiler booc (booc warmup.boo)

==== warmup.boo ======
import System.Net

def warmup(url as string):
    request = WebRequest.Create(url)
    request.Credentials = CredentialCache.DefaultCredentials
    request.Method = “GET”
    response = request.GetResponse()
    response.Close()

for url as string in argv:
    print(url)
    warmup(url)

The second component is a batch file:

==== Warmup.bat ====
@cscript iisapp.vbs /a MyAppPool /r
@Start /min warmup http://myurl:50002/page1.aspx http://myurl:50002/page2.aspx
@Start /min warmup http://myurl:50002/page3.aspx

These should save you hours of waiting around for SharePoint at the cost of a little bit of load.  Beware I am unable to test the first line of the script as I am not currently at a W2k3 box.  It recycles a given app pool.

SharePoint – Add a page directly to a sharepoint site

The following is the code from a feature receiver event.

This allows a page to be added to a sharepoint site without using a page library.

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

    SPWeb web = properties.Feature.Parent as SPWeb;

 

    FileStream fStream = File.OpenRead(properties.Definition.RootDirectory + \NewPage.aspx);

 

Web.AllowUnsafeUpdates = true;

 

SPFolder folder = web.GetFolder(“”);

 

Folder.Files.Add(“NewPage.aspx”, fStream);

 

fStream.Close();


}

Adding BDC Columns to a Sharepoint List

I am trying to add BDC columns to a sharepoint list programatically.

In fact the application that I am working on has 140 lists each potentially with a different set of BDC extension columns.

This is of course impossible – at least no-one is saying how to do so on the blogs.

You cannot use the simple field constructor as business data is not in the enumeration.

The trick is to extract the XmlSchema from the field and remove the offending gumph (that is the specific guids – which I now think may be the cause of my problems).

There are two methods that I have found useful:

SPField.AddFieldAsXml is the key method on the list to allow the xml to be added.

You need to tell the client which bdc provider to use:

SqlSessionProvider.Instance().SetSharedResourceProviderToUse(“myssp_id”)

This almost works (the fields are added, you get a cryptic error about looking in the logs yet the bdc column does not work).

I suspect that the guids that I removed are the problem.

Normally I only post working examples – this is not one of them.