Event Receiver to create a List based on a custom template and on lookup field

Hi
I would like to have an Event Receiver who is firing by addItem in a list calls Seminarliste and is creating each time a new list based on three columns for add.Lists("Title of the list", "Description of the list", "Custom List
Template")
I have a Problem to get the LookupField Title and I am getting a Problem to create a list.
If I debug the code the bold line creates an exception ;(
The following code I have produced:
        public override void ItemAdding(SPItemEventProperties properties)
            base.ItemAdding(properties);
            SPWeb spCurrentSite = properties.OpenWeb();
            SPSite siteCollection = new SPSite("http://win-ue32d37ap2n");
            SPWeb web = siteCollection.OpenWeb();
            SPListCollection lists = web.Lists;
            String curListName = properties.ListTitle;
            if(curListName == "Seminarliste")
                SPListItem curItem = properties.ListItem;
                String curItemListName = properties.AfterProperties["Title"].ToString();
                String curItemDescription = properties.AfterProperties["Beschreibung"].ToString();
                // Lookup field with Option to Chose a template name
                String curItemTemplate = properties.AfterProperties["Template"].ToString();
                SPListTemplateCollection listTemplates = siteCollection.GetCustomListTemplates(web);
                //Error by following line ...
SPListTemplate myTemplate = listTemplates[curItemTemplate];
                web.Lists.Add(curItemListName, curItemDescription, myTemplate);
If somebody had a similar problem in the past and could advice it would be most appreciated ;-)
Thanks in advance ;-)
Kind regards Michael Damaschke

If I understand correctly, the field you use to select the template name is a lookup field? If so, then the problem is the lookup field value is not the name of the template. It is an SPFieldLookupValue, which contains the ID and the string of the lookup.
So you want to separate the template name, like this:
if (item["LookupField"] !=
null)
     string fieldValue = item["LookupField"].ToString();
     SPFieldLookupValue value =
new SPFieldLookupValue(fieldValue);
     int lookupListItemID = value.LookupId;
     string lookupListValue = value.LookupValue;
IF you look at the fieldValue above, you will see it is something like an integer, followed by delimiter ;# and then your template name. you can always just parse the string at the ;# as well if you were so inclined.

Similar Messages

  • [svn:fx-trunk] 8271: Change the event type of List-based component's change , changing and caretChange events to a new event class: spark.events. IndexChangeEvent.

    Revision: 8271
    Author:   [email protected]
    Date:     2009-06-25 16:25:28 -0700 (Thu, 25 Jun 2009)
    Log Message:
    Change the event type of List-based component's change, changing and caretChange events to a new event class: spark.events.IndexChangeEvent.
    QA: Yes
    Doc: Yes
    Checkintests: Pass
    Mustella: List/DDL/ButtonBar tests pass
    Reviewers: Hans & Jason
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/events/IndexChangedEvent.as
        flex/sdk/trunk/frameworks/projects/spark/asdoc/en_US/spark/components/examples/ButtonBarE xample.mxml
        flex/sdk/trunk/frameworks/projects/spark/asdoc/en_US/spark/components/examples/DropDownLi stExample.mxml
        flex/sdk/trunk/frameworks/projects/spark/asdoc/en_US/spark/components/examples/ListExampl e.mxml
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/ButtonBar.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/ListBase.as
    Added Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/events/IndexChangeEvent.as

    Are those components in a SWC?  I would expect them to also have a namespace
    that looks more like http://.....
    Otherwise, make sure the path to the components are correct.

  • Unable to create a subsite based on the generic template - save site as a template

    hi,
    am using a  save site as a template functionality to create a sub site. when i select the custom template, and click on ok button,am  getting server error in appln.
    in the site template i have
    1) 2 document libraries with permissions broken[ stop inheritance]
    2) 4  Groups created L1, L2,L3,L4
    am stuck with ,  how to proceed/  create a  subsite based on the  template  site
    note i have uploaded the  wsp file in the new site collection and activated it . ma getting the custom site template name in the tab.
    would like to get clarification  about the  custom permissions:
    if i break the permissions on the document libraries, will this sec.permissions be intact, [ not changed] as the orginal ? i mean if i broke the permissions, in the newly created subsite also, will the permissions be broken? i need this broken functionality
    as per my requirement.
    help is  highly appreciated!
    Das

    hi,
     am not bale to get the correlation id. am getting server error in application. yellow page error!!
    and regarding the permissions i have checked this blog
    http://sergeluca.wordpress.com/2011/06/02/sharepoint-2010-save-as-template-what-is-saved-what-is-not-saved/
    Serge says that, if i am not wrong,
    we cant perform stop inherit the permissions  for the doc lib and create a  sub site based on this site template.
    also if i  stop inheriting from site permissions  also.
    can anyone from MSFT, pls confirm this. or any msd doc says about this.
    Das

  • I have Pages 09.  I have created custom templates and want to delete them.  How do I delete a template I have created in Pages 09?

    I have Pages 09.  I have created custom templates and want to delete them.  How do I delete a template I have created in Pages 09?

    Pages stores those you created & saved as templates in (your account) > Library > Application Support > iWork > Pages > Templates > My Templates. The door to the user's Library is hidden in Lion but it is easy to open. In Finder, hold down the Option key while clicking on the Go menu & your users Library will appear about halfway down the list.

  • How to create a list based on a value in multiple sheets

    I am trying to create a list in numbers that references a common value among multiple sheets.  I have 4 sheets created for a fantasy football league (1 sheet for QB, 1 for Running Back, 1 for Wide Receiver and 1 for Tight End).  I have assigned a value to each player listed on each individual sheet.  I would like to create a 5th sheet that lists the players in order from highest to lowest value as they are marked on their position sheet.  How would this be done in Numbers?
    Thanks for the help!

    Here is one possible solution:
    I named the four data tables "QB", "RB", "TE", and "WR", and the 5th table, for lack of a better name "Summary".
    NOTE:  The first row OF EVERY TABLE is a header.
    In the summary table:
    A2=OFFSET(INDIRECT(A$1&" :: $A$1"), MATCH(LARGE(INDIRECT(A$1&" :: B"), ROW()-1), INDIRECT(A$1&" :: B"))-1, 0, 1, 1)
    select A2 and fill to the right, then select A2 thru D2 and fill down as needed

  • Read contents of excel and create new List based on excel

    HI,
    I have a excel file, which is uploaded in a document library. I am using C# and VS 2010.
    The excel file contains multiple sheets. I want to read the contents of the excel file and create a new List based on the contents of the excel file.
    How to achieve this programmatically?
    Thanks

    Hi.
    You can user OpenXML SDK to read excel Data.
    http://msdn.microsoft.com/en-us/library/office/bb448854.aspx
    Here an example of use.
    http://zsvipullo.blogspot.it/2011/08/excel-helper-leggere-un-file-xlsx.html
    Regards,
    Bubu
    http://zsvipullo.blogspot.it
    Please mark my answer if it helped you, I would greatly appreciate it.

  • Need Help to create access-list based on traffic logs

    Hello,
    We didn't have any Firewall in our network, we recently implemented  Cisco ASA (Context) firewall in our network with any  any permit rule .
    Our intension is to collect the source, destination, protocol & ports based on the traffic logs and then implement the access-lists , once we confirmed all the rule will added to the firewall we want remove any any permit rule .
    I need some suggestion regarding this how we can proceed on this plan, any suggestions appreciated
    Rajkumar

    Hi Rajkumar,
    That is not the ideal way of doing... this will lead to a provisioning an unauthorized person to access for something he is not authorized to.
    How many users do you have in your network? Try to categorize users based on their present authorization level of access.... say Team A users need to access everything... then you need to group them and provide full access..... Team B users need to be provided with only restricted access.... then group them and provide restricted access....
    If your case is something like this.... all users need unrestricted intranet access and certain users alone requires internet acceess... then you can define rules accordingly....
    Regards
    Karthik
    Regards
    Karthik

  • Document created in a workflow based on a custom template is empty

    Hello,
    we have a big issue creating a document based on a defined custom template in a workflow. The following steps were made to achieve that:
    1. Adding a custom document type in Website Settings
    2. Creating an Excel file and uploading it as a template
    3. Allowing custom types for document list
    4. Adding the type to my document list as default
    Site Wokflow:
    1. Create Action: Create list item with the created document type and Name "test"
    When i run the workflow, SharePoint creates the document but the document is empty. If I create a document manually in the same document list, the document is created fine.
    These steps were performed in several tutorials with older SP Versions. So what happened in SP 2013?
    Thank you for help

    Hi Victoria Xia,
    I checked them again, the Template is specified in the content type of the document library, the workflow is creating a document using that content type, and will bring all the metadata as mapped in the workflow.
    but when I open the document created by the workflow it will be blank document, and the content type name is the correct content type (my custom content type) it is like its not using the template specified.
    when I click new document inside the library itself directly, it is opening a new document with the specified template.
    where could be the issue here?
    Thanks

  • Can I create a report based on Non-Oracle template?

    Hi:
    I have a Microsoft Word document that contains the entire layout of a report I need to create with Oracle Report 6i. I know that I can create a report based on a template, but as I understand it, I am limited to using Oracle Reports templates. Does Reports support using foreign templates? Thanks for any word in this manner.
    Thomas Morgan
    :)

    oracle reports does not support using ms word documents as templates. there is a product in the oracle applications stack, XML publisher, that allows you to inject data into a word template.
    thanks,
    ph.

  • Create a document based on specific document template using JavaScript (ECMA Script/REST API/SP Services)

    Hi,
    I have requirement to create a new document based on specific document template available in document library. Able to set the specific content type but the respective document template not being applied. I am trying with ECMAScript, REST API and SPServices
    but no luck for now. Please help me.
    Thanks,
    JP

    Hello,
    I have already tried your solution, however in that case I get the error - "UncaughtSys.ArgumentNullException: Sys.ArgumentNullException:
    Value cannot be null.Parameter name: context"...
    Also, I tried removing SP.SOD.executeFunc
    from my code, but no success :(
    Kindly suggest !!!
    Vipul Jain

  • I am creating a list.  Page 1 is full and I can't figure out how to get to page 2.

    I am creating a list.  Page 1 is full but I can't figure out how to get to page 2.

    It would help if you told us which ages version you use? Are you still on MacOs 10.6.8?
    Did you use text boxes?

  • Help with creating a list, adding to it, calling it and putting it in a combobox with c#

    I have been making a word RPG game with the windows form in c#, and I have encountered some problems along the way. Right now I have a character creation screen, and a screen that displays all of the stats, and gear equipment. I was thinking about adding
    some basic/starting items and put the list into a combobox. I created a separate class and named it HeadItems.cs, and put all of the possible stats, as well as ID and string name. I set a constructor with many parameters, so I can simply input this code, and
    have it generate a head item.
    HeadItems.Add(new HeadItem("Test Head", 0,2,0,0,1));
    Then I was trying to make the combobox, called cboHeadItems, and put its DataSource as HeadItems. Though I am not sure how to get it so it displays the first array, or the string name in the combobox. I am also not sure if I should create the list in the
    player entity class or its own class. From there I am not sure how to call the list on other forms/classes or how to make the name appear in the combobox for people to select.

    Hiya!
    It isn't that simple I'm afraid! You cant make the datasource of a combobox a 'HeadItem' because it doesn't know what that is and it won't know how to handle it.
    There are a few different ways to do it. You can pass it an array, a dataset, a datatable to mention just a few.
    Probably the simplest way is this:
    foreach(HeadItem hi in HeadItems){
    comboBox1.Items.Add(hi[0]); //Depends on your setup
    Antony
    :D

  • Help with Creating a list based on conditions

    Hi, im doing a project in java at college, and this is what the project says;
    Every November, on the last Wednesday of the month, Salchester Primary School holds its annual school games competition. The school is very small and pupils from all classes belong to Houses which compete for the House Cup. Each pupil belongs to either the Green or Yellow House. The names of pupils and numbers in each class are provided for you, together with their House.
    The games that are played during the day are:
    " Snap
    " Cribbage
    " Spillikins
    " Junior Scrabble.
    The structure of the competition is as follows:
    " the Yellow and Green Houses compete against each other in a series of
    matches
    " each match is best of three single games of one type of game
    " pupils cannot play other pupils from the same class
    " pupils can only play another pupil once
    " each pupil will take part in one match for each type of game.
    To allow results to be entered, the aim of the program is to
    " prepare a list of matches for the games competition
    " identify the winners of each match on the schedule
    " calculate the points awarded to each House.so far i have created the following classes;
    the student class which outlines all of the methods that i think are needed in the programme
    public class student
        private String name;
        private int c_lass;
        private int []game;
        private int [] oponent;
    public student(String n, int c)
            oponent=new int [18];
            game = new int [4];
            game[0] = -1;
            game[1] = -1;
            game [2] = -1;
            game[3] = -1;
            c_lass = c;
            name = n;
    public String getName()
          return name;     
    public int getC_lass()
          return c_lass;   
    public int getGame(int y)
          return game [y];     
    public int getOponent(int y)
          return oponent [y];     
    public void changeName (String y)
          name = y;     
    public void changeC_lass (int y)
          c_lass = y;     
    public void changeGame (int gindex, int oponent)
         game [gindex] = oponent;      
    public void eraseGame (int y)
         game [y] = -1;      
    public void eraseOponent (int y)
         oponent [y] = 0;      
    public void changeOponent (int y)
         oponent [y] = 1;      
      }and the student details, this class holds all of the ifnormation about the students, for example their name what colour their house is and the class number
    public class studentdetails
        private student [] gh = new student [18];
        private student [] yh = new student [18];
        public studentdetails()
    public void createstudentdetails ()
            //Class 1 Green house
        gh[0]=new student("Arnold",1);
        gh[1]=new student("Bertha",1);
        gh[2]=new student("Bella",1);
            //Class 2 Green house
        gh[3]=new student("Charles",2);
        gh[4]=new student("Denise",2);
            //Class 3 Green house
        gh[5]=new student("Edward",3);
        gh[6]=new student("Earl",3);
        gh[7]=new student("Freeda",3);
            //Class 4 Green house   
        gh[8]=new student("Genorge",4);
        gh[9]=new student("Gerry",4);
        gh[10]=new student("Hrriet",4);
        gh[11]=new student("Helen",4);
             //Class 5 Green house
        gh[12]=new student("Ian",5);
        gh[13]=new student("Issac",5);
        gh[14]=new student("Gerry",5);
            //Class 6 Green house
        gh[15]=new student("Keith",6); 
        gh[16]=new student("Kevin",6);
        gh[17]=new student("Leila",6);
            //Class 1 Yellow house
        yh[0]=new student("Albert",1);
        yh[1]=new student("Aswan",1);
        yh[2]=new student("Betty",1);
            //Class 2 Yellow house
        yh[3]=new student("Colin",2);
        yh[4]=new student("Debra",2);
            //Class 3 Yellow house
        yh[5]=new student("Elias",3);
        yh[6]=new student("Felicity",3);
        yh[7]=new student("Fiona",3);
            //Class 4 Yellow house
        yh[8]=new student("Gilbert",4);
        yh[9]=new student("Gwyn",4);
        yh[10]=new student("Hebe",4);
        yh[11]=new student("Hillary",4);
            //Class 5 Yellow house
        yh[12]=new student("Idris",5);
        yh[13]=new student("Jane",5);
        yh[14]=new student("Jasmine",5);
            //Class 6 Yellow house
        yh[15]=new student("Kenny",1);
        yh[16]=new student("Laura",2);
        yh[17]=new student("Linda",3);
    public void printstudentdetails()
    for(int i=0;i<18;i++)
            System.out.println (gh .getName () + " Class " + gh [i].getC_lass() + " Green House" );
    System.out.println (yh [i].getName () + " Class " + yh [i].getC_lass() + " Yellow House" );
    the problem is now in creating the match list. The match list is really hard and so far ive done the following but i cant get it to work, could anyone point me in the right direction.public class ListOfMatch
    private studentdetails SB=new studentdetails();
    public ListOfMatch()
    public void CreateMatch()
    SB.createstudentdetails();
    for (int g=0;g<1;g++){
    for (int i=0;i<18;i++){
    if (SB.getsy (i).getGame(g)==-1){
    for(int j=0;j<18;j++){
    if (SB.getsy(i).getC_lass()!=SB.getsg(j).getC_lass()){
    SB.getsy(i).changeGame(g,j);
    SB.getsg(j).changeGame(g,i);
    SB.getsy(i).changeOponent(j);
    SB.getsg(j).changeOponent(i);
    System.out.println(SB.getyh(i).getName()+SB.getgh(j).getName());

    IMO you are doing it wrong and not really OO
    Also please use Standard Java Coding Conventions ( and try use correct spelling)
    You should declare a Game class, a House class a classGroup class and a Student class
    To create the matchups you then can pick student from each classGroup.

  • Creating a web based book publication with front and back covers

    I have created a book in Indesign which is 12 pages inclusive of front and back covers, the problem I'm having is that when I convert the file into an SWF file the front cover has an extra page to the left of it and the back cover has an extra page to the right of it (these pages are not in my Indesign layots) I don't want these pages as I want the document to look like a book when I send it out.  I'm assuming I haven't set the document up correctly?  I have been on a number of tutorials but none of them seem to go into this.  Some pointers would be really helpful.
    Thank you.

    You can do this in Elements. It will require planning for the layout, viz. height, and width of front & back covers, and space allocation in between for the spine area. Be sure that your printer can handle the document size.Once you have figured this out, you need to open a new, blank file of appropriate size and resolution.
    There is available a grid which I find very helpful  to facilitate alignment.
    Each of your pictures, and the blank file (#1 above), should have a resolution of 240--300px/in for good result with printing.
    The text can be produced with the type tool - optionally horizontal or vertical.
    The pictures and text will each be on their own layers, and the move tool can be used to position these components

  • Creating a document library with a custom template

    What I want is basically a good solution for people to be able to fill out a form on the web and then save it in the online library.
    You need to be able to automatically create a document from a template in just one or two clicks from the page and then automatically save it to the online-library.
    When this is done, the admin of the site will get a notification (this i think i know how to fix thought) so he can examine the new document instantly.
    How can this be done?

    That's more or less out of the box behaviour. Create a content type on a list or library depending on what your template is (word doc, InfoPath form, list item with styling etc.), then create an alert for your admin on the list.
    Your users can then create new items and save them in the list/library. The process is simpler with list items or InfoPath forms as they don't give you the wide choice of actions that you get in word docs etc..

Maybe you are looking for

  • Neo2 Mixing Memory Question

    Currently running 2x512 Crucial Ballistix in slot 1&2 stock speed 2.2.2.5 - stable. I'm desperate for 2 gigs of ram but thanks to a nagging wife and lack of funds this isn't possible yet, but i do however have 2x512 Corsair value sticks (2,5.3.3.8) i

  • Generating pdf from RoboHelp gives "macro disabled" error

    I'm using RoboHelp 8 -> RoboHelp HTML, and I have MS Word 2007 and "Adobe PDF Creation Add-On 9" installed. To generate a pdf, I navigated to "Single Source Layouts" and double-clicked "Printed Documentation" (File -> Generate -> PDF should be the sa

  • Moving Power Query from Excel to SSAS

    We are using Excel 2013 Power Query and PowerPivot to build data models that will be moved to SSAS Tabular. Are there any gotchas that will not import? I have seen in testing that we have to be careful about importing files. Excel likes drive letters

  • HR Master Data Enhancement using BAdi RSU5_SAPI_BADI.

    Hi Experts,    I am trying to use first time BAdi 'RSU5_SAPI_BADI' instead of RSAP0001 for enhancing HR Master data.  I have enhanced the structure and I have created implemention method for BAdi and activated fine. Then I am not sure about the next

  • Can not take pictures off dvd+r

    I can not open a dvd to take the pictures off. The dvd does run on my macbook so I know there is nothing wrong with it. When I put the dvd in nothing happens on my Imac