Thursday, 26 February 2009
C#: Needed to automagically embed images into an email from a html source
http://www.codeproject.com/KB/IP/Mail_Webpage_with_images.aspx?display=Print
Friday, 20 February 2009
WSS3.0: Update WSS List via webservices
This was ripped from - blog.crowe.co.nz
Step/Step - An example of updating a Windows Sharepoint Server List from c#
1) Open Visual Studio.NET 2003
2) New Project (We will create a console application in this demo)
3) Name your project "GetListItems"
4) Right Click on "References" under the Project and select "Add Web Reference"
5) In the URL field type the path to your Windows SharePoint Services Site that contains the list you want to use.
Each site is different and only contains the lists for the particular child site.
For example the root site could be called "http://sharepoint.mysite.com" and you could have a sub site called "Test" which is accessible via "http://sharepoint.mysite.com/Test"
So type in your URL and append the following "_vti_bin/lists.asmx"
So if you were going to the "Test" child site your URL would be like this:
http://sharepoint.mysite.com/Test/_vti_bin/lists.asmx
You may be prompted to log onto your SharePoint site when do perform this action.
6) Click on "Go" and the Add Web Reference Dialog should display that it found one service and display you some available operations.
7) Click on "Add Reference"
8) Now you should end up with a new Web Reference Node in the Solution Explorer and your actual Web Reference which may have a funny name like "com.mysite.sharepoint"
9) Right click on the Web Reference and rename it to something simple like "SharePoint", this is what we will use to reference the web service in code.
10) Right click on the Web Reference and select "Properties" and change the "URL Behavior" to "dynamic"
This will add a "app.config" to the project and populate an appSettings item in the config file so that the URL is dynamically loaded from the "app.config" file and not hard coded into the source of the proxy stub that was created.
xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="GetListItems.Sharepoint.Lists" value="http://sharepoint.mysite.com/Test/_vti_bin/lists.asmx"/>
</appSettings>
</configuration>
11) Open the Class1.cs file in the editor and enter the following:
using System.Net;
using System.Xml;
namespace GetListItems
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string Username="UserName";
string Password="Password";
string Domain="Domain";
string ListName = "ListName";
Sharepoint.Lists ListsService = new Sharepoint.Lists();
ListsService.Credentials = new NetworkCredential(Username, Password, Domain);
// Create a new XML document to hold the updates we are going to perform
XmlDocument doc = new XmlDocument();
XmlElement updates = doc.CreateElement("Batch");
updates.SetAttribute("OnError", "Continue");
// We need to Create a Method Tag for each row we are going to update.
XmlElement UpdatesMethod = doc.CreateElement("Method");
UpdatesMethod.SetAttribute("ID", "1");
UpdatesMethod.SetAttribute("Cmd", "Update");
updates.AppendChild(UpdatesMethod);
// We need to update a particular row based on its internal ID.
XmlElement UpdatesField1 = doc.CreateElement("Field");
UpdatesField1.SetAttribute("Name", "ID"); // Which record to update
UpdatesField1.InnerText = "1"; // is defined here
UpdatesMethod.AppendChild(UpdatesField1);
// We are going to update the field called "Status"
XmlElement UpdatesField2 = doc.CreateElement("Field");
UpdatesField2.SetAttribute("Name", "Status"); // Which field to update
UpdatesField2.InnerText = "Status is OK"; // The actual new value
UpdatesMethod.AppendChild(UpdatesField2);
// Call the web service to update the list items
XmlNode Result = ListsService.UpdateListItems(ListName, updates);
ListsService.Dispose();
Console.WriteLine("The record has been updated!");
// Sleep for a moment so we can see the results
System.Threading.Thread.Sleep(5000);
}
}
}
Make sure you populate the Username, Password, Domain, and ListName variables above. You also need to make sure that the field “Status” exists in the particular list that you are updating. If it does not you will need to change it to a field that does exist.
For some sample code that will allow you to display the attribute names in a list see - /archive/2005/08/10/197.aspx
The XmlNode called Result should be parsed to locate errors that may have occurred during the update.
Tuesday, 17 February 2009
Javascript: Bubble Sorting
Very cool and works flawlessly.
http://www.the-art-of-web.com/javascript/oopsort/
Monday, 2 February 2009
WSS3.0: Deploy Master Pages to Subsite
But after further digging around, I found a nicely written solution by Stramit on codeplex.
If you download the non-source v1.1 release, there is a flaw in the batch install and i was scratching my head as to why i'm not seeing the link everyone else was under site settings.
Trick is to download the source version and then read the thread below to fill out the gaps.
http://www.codeplex.com/SPMasterPicker/Thread/View.aspx?ThreadId=43375
Once the install complete, the tool works a charm, thanks Stramit.