Welcome to weblogs.com.pk Sign in | Join | Help

Sharepoint Lists and Visual Studio 2008 Extensions for Windows Sharepoint Services

From the BB13 video you must have learned that you can create Sharepoint Custom Lists from Visual Studio is quite easy. The experience over all is not very great; as you have to edit the XML files. The easiest way however is that you create your Custom List using the Sharepoint web interface; and once the list is well established; script it out to Visual Studio Extensions for Windows Sharepoint Services (VSeWSS) format using the VseWss’ Solution Generator.

image

Through this; you will get a VseWss PROJ file and if you open it side by side with your main project; you can copy/paste the Meta Data portion in schema.xml file of List to your project List’ schema.xml

image

  • Use some source control to track the changes being made in the schema.xml; always check from the previous before committing to ensure some field is not accidentally deleted. The Solution Generator sometime gets screwed and don't include all the fields.
  • Watch out for the “Version” attribute of the Fields\Field; if you already have deployed your project to the production server and you have change something like column type; don't forget to increment the version number.

 

image

  • The solution generator also don't include any Lookup field; the reason is quite logical; as the list instance gets generated later and at the time of design/development you don't know the GUID of the list instance; if you google/bing around you will find reason details and how people have proposed to use Feature Activation event to fix the lookup field source id. My suggestion will be to simply uncomment the lookup field xml and let it create with wrong source/field id when the feature gets activated or list instance gets generated from your list definition, and create a simple ASPX file with some code behind having the code that fixes the lookup field source/field ids; a sample code is given below

image

public class FixExpenseQueueListPage : Page
{
    protected override void OnLoad(EventArgs e)
    {
        SPWeb web = SPContext.Current.Web;
        bool previousValue = web.AllowUnsafeUpdates;
        try
        {
            web.AllowUnsafeUpdates = true;
            SPList lookupList = web.Lists["Expense Queue"];
            SPList mainList = web.Lists["Expense Groups"];
            string fieldName = "Expense Group";

            /*
             * <Field Type="Lookup" DisplayName="Expense Group" Required="TRUE" List="%LIST%" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE" ID="{299e9129-cd4c-4f4f-bfe6-00f895ab5a99}" StaticName="Expense_x0020_Group" Name="Expense_x0020_Group" ColName="int1" RowOrdinal="0" SourceID="%FIELD%" Version="1" Group="" />
             */
            lookupList.Fields[fieldName].SchemaXml = @"<Field Type=""Lookup"" DisplayName=""Expense Group"" Required=""TRUE"" List=""{0}"" ShowField=""Title"" UnlimitedLengthInDocumentLibrary=""FALSE"" ID=""{299e9129-cd4c-4f4f-bfe6-00f895ab5a99}"" StaticName=""Expense_x0020_Group"" Name=""Expense_x0020_Group"" ColName=""int1"" RowOrdinal=""0"" SourceID=""{1}"" Version=""1"" Group="""" />".Replace(
                "{0}", mainList.ID.ToString()).Replace("{1}", mainList.Fields["Title"].Id.ToString());
            this.Response.Write("Lookup Field Fixed..<br />");

        }
        catch (Exception ex)
        {
            this.Response.Write(ex.ToString());
        }
        finally
        {
            web.AllowUnsafeUpdates = previousValue;
        }
    }
}
Published Saturday, December 12, 2009 4:02 PM by khurram

Comments

# VSeWSS – Sharepoint Event Receivers

Monday, December 14, 2009 1:10 PM by Khurram Aziz

Coding Event Receivers with Visual Studio Extensions for Windows Sharepoint Services (VSeWSS) is easy;

New Comments to this post are disabled