I have a sharepoint 2010 workflow builded in VS2010, not by me, but some colleage. This workflow need to start manual by the user if he would like to copy a document from list X to list y. In list x there is a manual created content type with the field start date. This field is a date picker, where the user can select a date. Only the date will be selected, not the time. If you select the date from today you will see 10-1-2013 in this field.
If you start the workflow this document and content type field values will be copied to list y. In list y there is another content type.
The problem is that the start date field value is copied to a date time value, and also inclusive the time. You see now 1-10-2013 0:00:00. 2 problems!
- Problem 1: format is not the same
- Problem 2: you see now the date and time. I only selected the date in the first list.
- Problem 3: i see in the manual created content type of list y, the start date field is a text field and not a date time field like in the content type from list x. This is not my biggest problem, because I only want to see the same date like I selected in list x.
Following code which copied the fields from list x to list y:
private void CopyItemToConcepten_Invoked(object sender, EventArgs e)
{
SPWeb web = workflowProperties.Web;
SPListItem item = workflowProperties.Item;
SPList targetList = web.Lists[Lists.Concepten];
if (targetList == null)
{
throw new Exception("Workflow error: The list '" + Lists.Concepten + "' does not exist on the current web.");
}
SPFile targetFile = targetList.RootFolder.Files.Add(item.File.Name, item.File.OpenBinary(), false);
foreach (SPField field in item.Fields)
{
if (!field.ReadOnlyField && field.InternalName != "Attachments")
{
targetFile.Item[field.InternalName] = item[field.InternalName];
}
}
targetFile.Item.Properties["SourceUrl"] = item.Url;
targetFile.Item.SystemUpdate();
targetFileUrl = web.Url.EndsWith("/") ? workflowProperties.Web.Url + workflowProperties.Item.Url : workflowProperties.Web.Url + "/" + workflowProperties.Item.Url;
}
Do I need explicit check if the field is a date field, and then do something with date format?? Or is there some better solution??
