Description
This method can be used to run code when a document conversion has completed. Microsoft Office SharePoint Server 2007 includes document converters that, for example, convert a Word 2003 XML document into a Web page. Custom document converters can also be added.
Usage Scenarios
Use the methods in the SPItemEventReceiver class to run code that responds to events on items in SharePoint lists and document libraries. You use the ItemFileConverted method to respond when a SharePoint document converter has converted a document from one format to another.
You do not instantiate the SPItemEventReceiver class itself in order to use these methods. Instead you create a custom event handler with an event receiver class that derives from SPItemEventReceiver. The following code examples illustrate how to create a new list item in response to a document conversion.
C# Code Example
using System;
using Microsoft.SharePoint;
namespace MyNameSpace
{
//Inherit from SPItemEventReceiver
public class MyEventReceiver : SPItemEventReceiver
{
//Override the ItemFileConverted method
public override void ItemFileConverted(SPItemEventProperties properties)
{
//Find out about the list where the document conversion occurred
using(SPSite SiteCollectionEvent = new SPSite(properties.SiteId))
{
SPWeb SiteOfEvent = SiteCollectionEvent.OpenWeb(properties.RelativeWebUrl);
SPListItemCollection ItemsOfEvent = SiteOfEvent.Lists[properties.ListTitle].Items;
}
//Create an item in another list to record the conversion
using(SPSite SiteCollection = new SPSite("http://My_Site"))
{
SPWeb myWebsite = SiteCollection.OpenWeb("MyWebSite");
SPList AnnoucementsList = myWebsite.Lists["Announcements"];
SPListItemCollection AnnouncementsListItems = AnnouncementsList.Items;
SPListItem NewItem = AnnouncementsListItems.Add();
NewItem["Title"] = properties.UserDisplayName + " added an attachment to " +
ItemsOfEvent[properties.ListItemId].Title + " in list " + properties.ListTitle + " at " +
properties.WebUrl;
NewItem.Update();
}
}
}
}
Visual Basic.NET Code Example
Imports System
Imports Microsoft.SharePoint
Namepace MyNameSpace
'Inherit from SPItemEventReceiver
Public Class MyEventReceiver
Inherits SPItemEventReceiver
'Override the ItemFileConverted method
Overrides Public Sub ItemFileConverted(ByVal properties As SPItemEventProperties)
'Find out about the list where the document conversion occurred
Dim SiteCollectionEvent As SPSite = New SPSite(properties.SiteId)
Dim SiteOfEvent As SPWeb = SiteCollectionEvent.OpenWeb(properties.RelativeWebUrl)
Dim ItemsOfEvent As SPListItemCollection = SiteOfEvent.Lists(properties.ListTitle).Items
SiteCollectionEvent.Dispose()
'Create an item in another list to record the conversion
Dim SiteCollection As SPSite = New SPSite("http://My_Site")
Dim myWebsite As SPWeb = SiteCollection.OpenWeb("MyWebSite")
Dim AnnoucementsList As SPList = myWebsite.Lists("Announcements")
Dim AnnouncementsListItems As SPListItemCollection = AnnouncementsList.Items
Dim NewItem As SPListItem = AnnouncementsListItems.Add()
NewItem("Title") = properties.UserDisplayName & " added an attachment to " & _
ItemsOfEvent(properties.ListItemId).Title & " in list " & properties.ListTitle & _
" at " & properties.WebUrl
NewItem.Update()
SiteCollection.Dispose()
End Sub
End Class
End Namespace