unable to update listitem external data column sharepoint 2010 - sharepoint-2010

I try update Extenal data column but it doesn't work, new value is not stored. (new value is visible on details form but not on list, rehreshing external data type does not return related external column values)
using (SPSite oSiteCollection = new SPSite("site.com"))
{
using (SPWeb oWebsite = oSiteCollection.OpenWeb("site.com"))
{
using (SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
{
SPList docLib = oWebsiteRoot.Lists["list name"];
SPListItemCollection items = docLib.Items;
foreach (SPListItem item in items)
{
//item["n"] is external column data field
item["n"] = item["notice"].ToString();
item.UpdateOverwriteVersion();
}
}
}
}

Check using item.Update() insted of item.UpdateOverwriteVersion()

This has to do with the field type and is quite complicated to get right.
There is a free external data field migration/copy tool here:
http://rrfreeman.blogspot.com/2013/06/bcs-bdc-external-data-lookup-field.html
I included source code and links to relevant articles.

Related

Searching for href values with Lucene (Examine in Umbraco)?

I want to search for a href value with lucene/examine - more precise the 'locallink' value. Examine is straight out-of-the-box standard config.
I have the following snippet which does not return any results;
string searchQuery = "localLink:" + id;
UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
foreach (var result in helper.Search(searchQuery, false))
{
// Do something
}
Upon inspection of the index via Developer > Examine Management (in Umbraco backend), I can see that the index does contain the value I am trying to search for but under a "_Raw" property. So I guess the question is, how I can make my search, search in these fields also?
You made search with UmbracoHelper.
Try to use Examine Searcher as described in docs :
var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
var searchResults = searcher.Search(query);
http://our.umbraco.org/documentation/Reference/Searching/Examine/
http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx

how to read Data context parameter from a crm to silverlight webresource

i have a silverlight webresource in my crm 2011.
now my task is to append a data parameter in url like
https://www.............../data=1234
now in silverlight application i need to read this data parameter.
i have tried to read the data
if (App.Current.Host.InitParams["data"] != string.Empty)
{
string CallerNumber = App.Current.Host.InitParams["data"];
...
and
i tried filtering the code to like
string url = System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString();
var uri = new Uri(url);
var CallerNumber = uri.Query;
callernumber will have the ?data=1234
but still i am not able to get the data parameter. Do help
I believe that you will find those in the query string. You can access it like this
foreach (var item in HtmlPage.Document.QueryString)
{
//Do something like the data
}

Sharepoint 2010 add a choice field

I have to add a choice field (dropdown) to a sharepoint list. I'm using the SharePoint API in Visual Studio.
Here is me code. I have tried to run this and there are no errors but it doesn't work.
private void addChoiceField(SPFeatureReceiverProperties properties, String _listName, String _fieldName)
{
using (SPWeb _web = properties.Feature.Parent as SPWeb)
{
SPList _list = _web.Lists.TryGetList(_listName);
writeLog(properties, "list name:" + _listName);
SPFieldChoice _fieldDD = (SPFieldChoice)_list.Fields[_fieldName];
writeLog(properties, "fieldname:" + _fieldName);
if (_fieldName == "State")
{
_fieldDD.Choices.Clear();
_fieldDD.Choices.Add("Gesloten-Verloren");
_fieldDD.Choices.Add("Analyse nodig");
_fieldDD.Choices.Add("Onderhandeling of revise");
_fieldDD.Choices.Add("Presentatie of demo");
_fieldDD.Choices.Add("Voorstel voor prijsofferte");
_fieldDD.Choices.Add("Prospect");
_fieldDD.Choices.Add("Waardevol");
_fieldDD.Choices.Add("Gesloten-Gewonnen");
_fieldDD.Update();
}
}
}
Does anyone knows what's wrong or how to add a choicefield in a different way using the API?
You need to call
_list.Fields.CreateNewField
to actually add it to the list instead of trying to pull an existing field from the list.
Here is a link to the method description: http://msdn.microsoft.com/en-us/library/microsoft.harepoint.spfieldcollection.createnewfield.aspx

Get List Item by GUID

I am working on sharepoint-2010 and I am new to sharepoint.
I want to access List Item by Guid. So, how can I access.
Please provide some reference or some class file to access that.
Thanks in advance.
Use the SPList.GetItemByUniqueId method:
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listTitle];
SPListItem item = list.GetItemByUniqueId(itemGuid);
}
}

Add item to Sharepoint Survey list

I have a survey list in sharepoint and I'd like to add an answer to the survey using c# code, this I think could be interpreted as add an item to the list so I tried the next but is not working.
How can this be done?
using (SPSite site = new SPSite("http://user-pc"))
{
using (SPWeb web = site.RootWeb)
{
try
{
SPList olist = web.Lists["JobSchedulle"]; //<- Name of the survey in sharepoint 2010
SPListItem item = olist.Items.Add();
item[5] = "good";// <- this survey only has one question, and is a text option ..
item.Update();
}
catch {
Console.ReadLine();
}
}
}
I found the error - the code works, but I was accessing item[5] (with the wrong index).