Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
 ItemFileConverted Method

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPItemEventReceiver.ItemFileConverted Method (Microsoft.SharePoint)

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Overridable Sub ItemFileConverted ( _
    properties As SPItemEventProperties _
)
Visual Basic (Usage)
Dim instance As SPItemEventReceiver
Dim properties As SPItemEventProperties

instance.ItemFileConverted(properties)
C#
public virtual void ItemFileConverted (
    SPItemEventProperties properties
)

Parameters

properties
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
SPItemEventReceiver.ItemFileConverted Method      Content Master Ltd   |   Edit   |   Show History

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
SPItemEventReceiver.ItemFileConverted Method      Michel Capdevila Toulouse   |   Edit   |   Show History

This does not work in this event because there is a bug in SPItemEventProperties.RelativeWebUrl that return the full url instead of the relative one, so OpenWeb() will failed.

Write code like this to bypass.


SPWeb currentWeb = null;
if (SPUrlUtility.IsUrlRelative(properties.RelativeWebUrl))
{
currentWeb = properties.OpenWeb();
}
else
{
using (SPSite currentSite = new SPSite(properties.SiteId))
{
// remove the SPSite URL from the buggy SPItemEventProperties.RelativeWebUrl
string trueRelativeWebUrl = properties.RelativeWebUrl.Substring(currentSite.Url.Length );
currentWeb = currentSite.OpenWeb(trueRelativeWebUrl);
}
}
return currentWeb;

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker