Sunday, January 15, 2012

Cannot read fields from a deleted object

The above error was causing me some grief, I did delete the object but for some reason a populate query was picking it up from the datastore.

I was able to check if the object was deleted with the following JDOHelper function: JDOHelper.isDeleted(item)

I used it as follows:


import javax.jdo.JDOHelper;
import javax.jdo.ObjectState;

public List getWatchList() {
List watchList = new ArrayList();
List result = ccs.myasxpager.datasource.WatchList.getWatchList();

for (ccs.myasxpager.persistence.schema.WatchList item : result) {
if (JDOHelper.isDeleted(item))
continue;
String[] watchListItem = {item.getAsxCode(), ccs.myasxpager.datasource.Company.getCompanyNameByCode(item.getAsxCode()), ccs.myasxpager.datasource.Company.getIndustryByCode(item.getAsxCode())};
watchList.add(watchListItem);
}
return watchList;
}


Monday, September 13, 2010

Using XmlReader to parse an XML file

using (XmlReader reader = XmlReader.Create(@"D:\Temp\XMLReader\XMLReader\ViewFields.xml"))
{
// Parse the XML document. ReadString is used to
// read the text content of the elements.
while(reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name.Equals("viewfield"))
{
reader.ReadStartElement("viewfield");
Console.WriteLine(reader.ReadString());
}
}
}
}
Console.Read();

Monday, July 5, 2010

Accessing the Content Fields of a SharePoint page

I needed to access the properties/content fields of a SharePoint page programatically and achieved this with the following code:

SPField field = SPContext.Current.List.GetField("Level 1 Group Summary");


string value = field.FieldRenderingControl.ListItemFieldValue.ToString();

Or
value = field.FieldRenderingControl.ItemFieldValue.ToString();

Wednesday, April 7, 2010

Decimal Regular Expression

The following regular expression checks for a number that can contain up to two decimal places.

^\d*(\.\d{1,2})?$

matches:

123
123.1
123.12

not matches:

123.
123.123

Monday, March 29, 2010

NSMailDelivery undeclared

I've been playing around with Objective C using the Cocoa framework ever since I got my Mac for Christmas.

I was following a dummies guide to sending emails using Cocoa and I came across the following show stopper compilation error :

"error: 'NSMailDelivery' undeclared (first use in this function)"

Not much joy online looking for a solution, seems everyone else who was inflicted with this error was advised to use some other mail class due to NSMailDelivery being dropped by Apple with no successor in Cocoa which seemed odd.

Anyway here's how I solved the problem. By default on my Mac Cocoa projects are targeted for a 64 bit architecture environment, when I changed the architecture to 32-bit universal the project compiled.

I changed the target architecture by clicking on the project name under "Groups & Files" to highlight it.
Then I clicked on the "Info" icon to open the project info dialog, next I clicked on the "Build" tab and changed the architecture value to "32-bit Universal".

I'm guessing switching to a 32 bit architecture will fix simular error messages with different classes I saw people enquiring about while I was looking into this problem.

Monday, December 21, 2009

Thursday, December 17, 2009

Accessing the values of a SPFieldChoice

I've got a sharepoint content page that needs to populate a drop down list with the choice values stored in a site column field of type choice.

The field is defined as follow:

Name="AgeOptions"
DisplayName="Age Options"
RichText="TRUE"
RichTextMode="FullHtml"
Required="FALSE"
Group="SIA Enquiry Form"
ID="{119EFAFF-63D3-4d61-A393-06DE18A91093}"
SourceID="http://schemas.microsoft.com/sharepoint/v3">

Select an option below
10-15
15-20
20-25
25-30
30-35
Over 35




I used the following code to access the field from the code behind of my page layout:
 
SPField field = SPContext.Current.Fields["Age Options"];

if (field != null)
{
Response.Write("Found the Age options field: " + field.InternalName + " Type: " + field.TypeAsString);

SPFieldChoice ageOptions = (SPFieldChoice) field;

StringCollection choices = ageOptions.Choices;

for (int i = 0; i < choices.Count; i++)
Response.Write("Choice ->> " + choices[i] + "
");

}
else
Response.Write("Age options not found.");