Getting MultiChoice column value without unnecessary Symbols like ";#" from sharepoint library - c#

I am using Rad grid to display sharepoint library items. When i am displaying ChoiceWith CheckBox type columns, then the values are coming with additional symbols of ;# before and after each choice value.
How can i remove the ;# symbols from ChoiceWithCheckBox type columns ?
Thanks in Advance.

That's how SharePoint stores the values internally. It's basically a key/value pair.
You can manually parse the items to only return the value without the key.

A Lookup field/column in a SharePoint list is stored as a key#value pair internally.
Use SPFieldLookupValue to get either the value(Text) or the key(number) from the lookup field.
SPFieldLookupValue('column name').LookupValue gives you the VALUE in the key#value pair
SPFieldLookupValue('column name').LookupId gives you the KEY in the key#value pair
I guess you are directly binding the SPItemCollections object (List.items or CAML query results) to your telerik radGrid. I usually create a generic list(in memory object), populate the list with items in the format user wants to see and then bind the generic list to radGrid.
If you are working on a SharePoint 2010 list, see if SPRadGrid telerik webpart suits your need

Related

How to get the Install & Testing Note of a Task or Defect Item

I'm developing a win forms application using AxosoftAPI.NET. I've implemented functionality to search for Items like Tasks, Defects, Incidents and Projects.
I can also check whether an Item has attachments. Now I need to know how to check if an Item (Task or Defect) has an Install or Testing Note attached to it. I searched in Axosoft's developers website but couldn't find anything helpful. How can I achieve this in C# using AxosoftAPI.NET?
Install and Testing Notes are not standard fields in Axosoft so are most likely Custom Fields that were added by your team. All custom fields should be returned when getting items, however large text fields, are only returned when getting a single item, rather then getting lists of items.
From the developer.axosoft.com page regarding the GET multiple and specifying the columns parameter :
(comma seperated string) Containins the names of the columns to return for each item. Defaults to all columns. However, please note that for performance reasons long text fields (such as 'Description') are not returned by this API call. To get the values of long text fields, use the GET /defects/{id} call to retrieve a single item.

C# Linq - Elegant way to order a dataset by the maximum value between two columns?

To elaborate on what I'm asking here, I'm working in C# trying to order a list of data that is coming out of a database. A certain object (table) has two separate properties (columns) which can hold dates. I want to sort this list based on date, meaning for each data row, I want to take the maximum of the two dates and use that for the sort.
Is there an elegant way to do this? At the moment I'm thinking that I should just get the max time from each record, and store it as a key in a Dictionary, with the data row being the value, and then iterate through the Dictionary with the sorted keys. Although this wouldn't be terrible to code, I'm trying to see if there is a nicer way to do this using Linq. Any help would be appreciated. Thanks.
If you want an alternative for sorting your collection everytime, .NET contains a class called SortedList. Here is the link to the MSDN article: http://msdn.microsoft.com/en-us/library/system.collections.sortedlist(v=vs.110).aspx
MSDN states that a SortedList:
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
So if you want to sort by date you can declare your sorted list as:
SortedList<DateTime, YourData> mySortedList = new SortedList<DateTime, YourData>();
and when you add values to it, it will already be sorted. Or you can just go with LINQ and #Alexander answer.
Edit
I just understood what you want to do. You can do:
table.OrderBy(item => Math.Max(item.Date1.Ticks, item.Date2.Ticks));
Note: The linq query above will not be performant on a large collection.

using data binding to get input for a list of items of various types

In my application I am trying to follow the MVVM. But I am stuck with a problem.
User inputs name of a particular table(say tab_1) that exists in DB and contains any number of columns. Each column can be any of the following datatypes - int,varchar,bool. I can get the list of column names and their types.
Is there any way (that follows MVVM pattern) through which I can can take input for each of the columns using data binding and save the data in the table tab_1?
The tables are generated at run time. so only when user input the name of the table, it is possible to know the actual number of columns and their corresponding data types.
Please help.
If the variation of the tables is fixed (like there is 5 tables to choose from and they wont be changed in runtime) you can make viewmodels for each of the table. Then inside View prepare data templates for each of these ViewModels (with target type match the viewmodel type).
If you don't know what kind of tables there are, I think you need to generate ViewModels and corresponding datatemplates in the runtime based on the table members. It should be easy since as you posted, there is fixed variation of the member types.

How do I read LookUp fields with multiple values in SharePoint?

Hi and thanks for looking!
Background
I have inherited an old .NET project based on SharePoint 2007 and have designed and external core library which merely accesses SP data, therefore making SP just a backend. Yes, I know it would be better to migrate to SQL, but the client doesn't agree.
The previous developers used a simple read method to read the data in a SP list:
SPList list = CurrentRootWeb.Lists["SomeListName"];
And then they access list properties through a dictionary of sorts (i.e. for each item in list, get item["SomeValue"]).
I am not skilled in SharePoint, so I don't know if this is the most efficient manner to go about accessing it's data.
Problem
How do I read LookUp fields with multiple values in SharePoint?
Every property they request seems to want a string in return. So item[SomeString] is okay, but item[SomeList] makes everything barf! I would have thought that a multi-value lookup list column comes in as a serialized or delimited string holding the selected values (example: "red;blue;green"). What am I missing?
Thanks!
If you are specifically interested in LookUp fields with multiple values not just MultiChoice feilds, then following code should help:
item.Fields["LookFieldName"].Type == SPFieldType.Lookup;
SPFieldLookup LookUpField = item.Fields["LookFieldName"] as SPFieldLookup;
if (LookUpField.AllowMultipleValues)
{
SPFieldLookupValueCollection valueCollection = item[Field.Id] as SPFieldLookupValueCollection;
string[] arrLookupValues = (from SPFieldLookupValue val in valueCollection select val.LookupValue).ToArray<string>();
}
For each of the SPFields in the list's fields, you need to test the field's Type.
If the type is SPFieldType.MultiChoice, then you cast the SPField to SPFieldChoice and access the Choices collection, which is a StringCollection.

Latest data in the first row

Goal:
Have the latest data to be in the first row and not in the end of listview. The program is in WPF.
Problem:
Based on this source code, don't know how to recieve the latest data in the first row in the listview
For the sake of simplicity, that sample code is loading hard-coded data into the ListView. It isn't retrieving live data from a database, as you will presumably be doing.
If at all possible, you should sort the data when you retrieve it from the database. Then you'll have no problem just binding that sorted data to your ListView
Get the current date/time from your data source and sort on that, descending. For example, if you are reading the records from an SQL Server database, include a field GETDATE() AS date_time. If the data is from a file, use the built-in .NET date/time objects (Now in VB.NET) to add the timestamp.
You need to provide the data to the listview in a sorted fashion.
This example shows one way.
You could also expose the data through a viewmodel that would wrap some model (possibly whatever source list you're looking at), sort it (probably using a linq .orderyby method) and give the data to your view.

Categories

Resources