This project is read-only.

Is it possible to work with Attachments in task forms

May 29, 2009 at 3:09 PM

How can I work with attachmetns inside:

protected override TaskData SaveData(object commandArgument)

or maybe I can get SPListItem to do it? 

I've tried to get Item Id using to somehow identify task item... but failed

taskData["ID"] doesn't work(((

Is there solution?

thx.

Jun 2, 2009 at 1:23 AM

Are you trying to attach to the task or the actual item the workflow is running on?

Chris

Jun 2, 2009 at 7:47 AM

I have to attach file to task not to item workflow is running.

In my workflow user have to attach results of his work (file) when mark task completed. For one workflow there is several tasks to several users... so superviser must have ability to see connection betwen reports from users and tasks not workflow items.

Coordinator
Jun 7, 2009 at 11:08 PM

You can access the task using SPContext.Current.ListItem.

Jun 8, 2009 at 8:28 AM

That's right, thx... I can access item... But there comes another problem: 

I can't save item with attachments: I get exception, that item being locked by workflow.

I found workaround - good old trick: Get item by ID and than work with it, also write folowing string:

item[SPBuiltInFieldId.WorkflowVersion] = 1;

everything works, data is updating, attachments are saving, but user get error, that item changed by another user... thats logical but not OK for me.

 

Has any ideas what to do?

 

 

My code:

 

My code:

 

 protected override TaskData SaveData(object commandArgument)

    {

        TaskData taskData = new TaskData();

        taskData["CustomTaskWorkflowReviewComments"] = MyTaskField.Text;

        taskData["CustomTaskWorkflowReviewStatus"] = commandArgument;     

        SPListItem item = SPContext.Current.ListItem.ParentList.GetItemById(SPContext.Current.ListItem.ID);

        item.Web.AllowUnsafeUpdates = true;

 

        item[SPBuiltInFieldId.WorkflowVersion] = 1;

        item.Update();

 

        if (fileAttachment.PostedFile != null && fileAttachment.HasFile)

        {

            System.IO.Stream fStream = fileAttachment.PostedFile.InputStream;

            byte[] contents = new byte[fStream.Length];

            fStream.Read(contents, 0, (int)fStream.Length);

            fStream.Close();

            fStream.Dispose();

            SPAttachmentCollection attachments = item.Attachments;

            string fileName = System.IO.Path.GetFileName(fileAttachment.PostedFile.FileName);

            attachments.Add(fileName, contents);

        }

        item.Update();            

        return taskData;       

    }  

 

Coordinator
Jun 8, 2009 at 9:08 AM
You should probably use the IListItemService to update the list item.

Workflow caches list item changes and updates them in bulk. Hence the locking issue. Common to workflows.

________________________________

Van: serrnovik [mailto:notifications@codeplex.com]
Verzonden: ma 8-6-2009 9:28
Aan: Wouter van Vugt
Onderwerp: Re: Is it possible to work with Attachments in task forms [wss3workflow:57886]



From: serrnovik

That's right, thx... I can access item... But there comes another problem:

I can't save item with attachments: I get exception, that item being locked by workflow.

I found workaround - good old trick: Get item by ID and than work with it, also write folowing string:

item[SPBuiltInFieldId.WorkflowVersion] = 1;

everything works, data is updating, attachments are saving, but user get error, that item changed by another user... thats logical but not OK for me.



Has any ideas what to do?





My code:



My code:



protected override TaskData SaveData(object commandArgument)

{

TaskData taskData = new TaskData();

taskData["CustomTaskWorkflowReviewComments"] = MyTaskField.Text;

taskData["CustomTaskWorkflowReviewStatus"] = commandArgument;

SPListItem item = SPContext.Current.ListItem.ParentList.GetItemById(SPContext.Current.ListItem.ID);

item.Web.AllowUnsafeUpdates = true;



item[SPBuiltInFieldId.WorkflowVersion] = 1;

item.Update();



if (fileAttachment.PostedFile != null && fileAttachment.HasFile)

{

System.IO.Stream fStream = fileAttachment.PostedFile.InputStream;

byte[] contents = new byte[fStream.Length];

fStream.Read(contents, 0, (int)fStream.Length);

fStream.Close();

fStream.Dispose();

SPAttachmentCollection attachments = item.Attachments;

string fileName = System.IO.Path.GetFileName(fileAttachment.PostedFile.FileName);

attachments.Add(fileName, contents);

}

item.Update();

return taskData;

}



Read the full discussion online <http://wss3workflow.codeplex.com/Thread/View.aspx?ThreadId=57886&ANCHOR#Post198890> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[wss3workflow:57886]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings <http://www.codeplex.com/site/discussions/project/unsubscribe/wss3workflow> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com
Jun 8, 2009 at 11:08 AM

May be it'll solve my problem, but I haven't found any documentation how to work with attachment in IListItemService

Method, that update elment accept hashtable of properties,not attachment collection.

[CorrelationInitializerAttribute]

void UpdateListItem ( Guid id, Guid listId, int itemId, Hashtable itemProperties )

Does anybody have some piece of documentation or examples for IListItemService (msdn is very poor on this topic) or how to work with attachments in this case?

 

 

 

Coordinator
Jun 8, 2009 at 11:19 AM
Not sure if IListItemService has support for attachments. I'll try and research a little later.

________________________________

Van: serrnovik [mailto:notifications@codeplex.com]
Verzonden: ma 8-6-2009 12:08
Aan: Wouter van Vugt
Onderwerp: Re: Is it possible to work with Attachments in task forms [wss3workflow:57886]



From: serrnovik

May be it'll solve my problem, but I haven't found any documentation how to work with attachment in IListItemService

Method, that update elment accept hashtable of properties,not attachment collection.

[CorrelationInitializerAttribute]

void UpdateListItem ( Guid id, Guid listId, int itemId, Hashtable itemProperties )

Does anybody have some piece of documentation or examples for IListItemService (msdn is very poor on this topic) or how to work with attachments in this case?







Read the full discussion online <http://wss3workflow.codeplex.com/Thread/View.aspx?ThreadId=57886&ANCHOR#Post198947> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[wss3workflow:57886]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings <http://www.codeplex.com/site/discussions/project/unsubscribe/wss3workflow> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com