08-23-2012 05:59 AM
Hello,
Does anyone have some example code that posts a date & time value to a Date & Time keyword type. When I have a string variable, I get an error... So I am stuck at figuring out the element type, and from there the proper format of the variable.
Thanks for any assistance!
Seth
08-23-2012 06:10 AM
Instead of passing a string variable you need to pass a DateTime object.
Take a look at http://msdn.microsoft.com/en-us/library/system.datetime.aspx for more information on creating DateTime objects.
08-23-2012 06:15 AM
Seth,
Here's the method I use to pass in a string and return a date. I'm sure someone else might have a better solution, but this one does work for us...
In this case, we're getting the date in the yyyyMMdd format. You can see more information about some of the settings on this function here: http://msdn.microsoft.com/en-us/library/ms131044
public DateTime FixDate(string date) {
CultureInfo enUS = new CultureInfo("en-US");
DateTime dt;
DateTime.TryParseExact(date.Trim(), "yyyyMMdd", enUS, DateTimeStyles.None, out dt);
return dt;
}
08-23-2012 06:40 AM
If your date string is in a more standard format like mm/dd/yyyy, you could just use DateTime.Parse
http://msdn.microsoft.com/en-us/library/1k1skd40.aspx
DateTime convertedDate = DateTime.Parse(dateString);
08-23-2012 08:00 AM
All good stuff! Thanks Guys! With tidbits from each, I've been able to craft the unity keyword update:
Dim keyModifier As KeywordModifier = document.CreateKeywordModifier()
Dim PostDate as DateTime = DateTime.Now()
PostDate.Kind = DateTimeKind.Local
' Add update keyword call to keyword modifier object
keyModifier.AddKeyword(KEYWORD_TYPE,PostDate)
' Apply keyword change to the document
keyModifier.ApplyChanges()
output =String.Format("Keyword Type: '{0}' Value: '{1}' added to Document {2}.", KEYWORD_TYPE, PostDate, DOCUMENT_ID)
Aside to the Communities Admin... I really dislike how this text window formats pasted text. and every [Enter] is a full paragraph.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.