Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 25, 2011 @ 09:43
    Sherry Ann Hernandez
    0

    importing dictionary items from excel

    Hi,

    Does anybody have an idea how to import the dictionary items that we have in excel to the database. I try the import tool of sql server but I'm having a problem with the data because the uniqueId is being read as varchar in excel and it can't convert to uniqueidentifier which is the datatype in sql server.

    Thanks,

    Sherry

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 01:08
    Lee Kelleher
    0

    Hi Sherry,

    My approach to this would be to deal with the APIs rather than going to the database directly.

    I haven't had much experience with accessing/reading data from Excel in C#/.NET, but it is definitely possible. Then once you have got access to the data, you can add new dictionary items via the API.

    umbraco.cms.businesslogic.Dictionary.DictionaryItem.addKey(string key, string defaultValue, string parentKey)

    Cheers,  Lee.

  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 26, 2011 @ 06:35
    Sherry Ann Hernandez
    0

    Hi Lee,

    My mistakes but I already have the dictionary item but what I meant is to upload the text in other language which I think will use the cmsLanguageText table. Is there any api for that?

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 11:40
    Lee Kelleher
    0

    Hi Sherry,

    No problem if the dictionary item already exists, just need to know the "languageId", then you can call...

    var item = new Dictionary.DictionaryItem(key);
    item.setValue(languageId, value);

    The 'setValue' method will handle the insert/update database calls.

    Cheers, Lee.

  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 26, 2011 @ 13:01
    Sherry Ann Hernandez
    0

    Hi Lee,

    Currently I use the SQL directly to insert the language item. I was able to insert it in the table but when I try to check the Dictionary in the backoffice it's not populating the textboxes for the other language. It seems that it didn't read the recently inserted languaget text.

    This is my code.

    SqlCommand dCmd = newSqlCommand("INSERT INTO cmsLanguageText(languageId,UniqueId,[value]) values (@languageId, @key, @value)"

    );

     

    dCmd.CommandType =

    CommandType

    .Text;

    dCmd.Connection = conn;

    dCmd.Parameters.AddWithValue(

    "@languageId"

    , languageID);

    dCmd.Parameters.AddWithValue(

    "@key"

    , key);

    dCmd.Parameters.AddWithValue(

    "@value"

    , value);

    dCmd.ExecuteNonQuery();

    dCmd.Dispose();

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 13:14
    Lee Kelleher
    0

    Hi Sherry,

    With the SqlCommand, what value are you passing through as the "@key" parameter? It should be the Guid for the DictionaryItem (which is the "id" from the "cmsDictionary" table).

    I'd still recommend doing this via the appropriate API. :-)

    Cheers, Lee.

  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 26, 2011 @ 13:34
    Sherry Ann Hernandez
    0

    Yes it is a GUID

    This is my code for that

    key =

    newGuid(reader["UniqueID"

    ].ToString());

     

    But I'm having a problem using the api. I'm getting a stack overflow error in this line

    var

     

    item = newDictionary.DictionaryItem

    (key);

     

    It is not giving me any error so I can't pinpoint which went wrong.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 13:37
    Lee Kelleher
    0

    Not sure if you've copy-n-paste the code... but add a space between "newDictionary" ... "new Dictionary"?

  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 26, 2011 @ 13:42
    Sherry Ann Hernandez
    0

    There is a space on my code. :)

    I'm just having problem pasting code in here.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 13:50
    Lee Kelleher
    0

    If you want to use the API, what was the exception message? From looking at the core code, it should only throw an "ArgumentException" if the dictionary key doesn't exist.

    Otherwise, going down the direct database route, you'd need to investigate further - check if the Guid differs, etc. Also the Umbraco back-office caches the DictionaryItems, so remember to touch the web.config (or restart app-pool).

    Cheers, Lee.

  • Sherry Ann Hernandez 320 posts 344 karma points
    Sep 26, 2011 @ 13:55
    Sherry Ann Hernandez
    0

    No other exception message besides the stack overflow message which makes it difficult also for me to debug. Probably i'll go first with the direct database route.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Sep 26, 2011 @ 13:57
    Lee Kelleher
    0

    No worries. Good luck with it. (Not sure what else to suggest, sorry).

    Let us know how it goes.

    Cheers, Lee.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies