Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Updating DateTime column via Sharepoint Object model

9 views
Skip to first unread message

arduk

unread,
Jun 22, 2009, 8:20:01 PM6/22/09
to

NOTE: Reposted due to problems with managed newsgroups...my apologies for the
duplication....

I am trying to update a datetime field via the sharepoint object model. The
field is custom field which is used in a custom content type which is based
on the document content type.

The code that I am using to update the property is:
itemToUpdateAsAdmin.Properties["dateEditingBegan"] =
Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now);
itemToUpdateAsAdmin.UpdateOverwriteVersion();


Most of the time, the update works fine. On some files though, I get the
following error when it tries to update the datetime field:
"Specified data type does not match the current data type of the property"

I guess I have a number of questions around this which I need answers to:
Why does this work for some files and not for others?
How do I get it to work for all files (considering that they are all the
same content type, so the column should always be the same datatype)?
How do I find out the data type that Sharepoint is expecting (clearly it is
not the datatype that is defined in the content type)?

Any help on this would be greatly appreciated!

Thanks in advance!

Steven Cheng

unread,
Jul 2, 2009, 5:12:10 AM7/2/09
to
Hi Richard,

From your description, you're encountering some "Specified data type does
not match the current data type of the property" error when try update a
SPListItem(which belongs to a documentLibrary of custom contentType),
correct?

Based on the code you provided, I've performed some local tests with a list
with custom contentType(and datetime field). My code have tried both
string format Date value(via CreateISO8601DateTimeFromSystemDateTime) and
directly assign DateTime object. It seems the update can work correctly.

=======================
SPDocumentLibrary testdoclib1 = list as SPDocumentLibrary;

SPListItem item1 = testdoclib1.Items[0];

foreach (var key in item1.Properties.Keys)
{
Console.WriteLine("{0}, {1}",key,
item1.Properties[key]);
}

//item1.Properties["testdate"] =
DateTime.Now.AddDays(3);

item1.Properties["testdate"] =
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now.AddDays(5));

item1.UpdateOverwriteVersion();

Console.WriteLine("field updated.......");

list.Update();
=========================

As you mentioned that the error will occur occasionally, is it possible to
repro the problem with a for loop which update the item for multiple times?
Also, if we try the similar code on other list(such as a new created one
with similar setting), will this problem occur too?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

-----------------------------
From: =?Utf-8?B?YXJkdWs=?= <richard...@noemail.noemail>
Subject: Updating DateTime column via Sharepoint Object model
Date: Mon, 22 Jun 2009 17:20:01 -0700

0 new messages