DCSIMG
SPMetal – Missing Created By/Modified By fields - Updated - itaysk

SPMetal – Missing Created By/Modified By fields - Updated

Posted Wednesday, September 22, 2010 11:30 AM by Itay Shakury

In a previous post of mine, I have talked about the fact that SPMetal does not generate properties for the “Created By” and “Modified By” fields. This was back in the beta phase of SharePoint 2010 and the workaround that I have suggested was to manually add the desired fields into the generated code file.
Since then we have come to know SharePoint 2010 better, and RTM has brought some fixes. So here is how it should be done now.

SPMetal command line can accept parameters specified in an XML file. You can use this XML file to modify the way SPMetal generates classes. On of the things you can specify is the “Column” element, which tells SPMetal to specifically include a column, even if it’s hidden. We will use this to force SPMetal to include our fields.

For detailed explanation about passing parameters to SPMetal, see: http://msdn.microsoft.com/en-us/library/ee535056.aspx

Here is an example of a parameters file that forces the inclusion of “Modified By” and “Created By” columns to the “Contact” content type.

<?xml version="1.0" encoding="utf-8"?>

<Web xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">

<ContentType Name="Contact">

<Column Name="CreatedBy" />

<Column Name="ModifiedBy" />

</ContentType>

</Web>

 

To use this parameters file, run SPMetal like so:

SPMETAL /web:http://serveraddress /code:codefilename.cs /parameters:params.xml

תגים:,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: