0
votes

I have some code that inserts a list item into a list...

I then have this code

  SPFolder folder = web.Folders["Lists"].SubFolders[list.RootFolder.Name].SubFolders["Attachments"].SubFolders[item.ID.ToString()];

                foreach (SPFile file in folder.Files)
                    {
                        string attachmentName = this.downloadedMessageID + ".xml";
                        if (file.Name == attachmentName)
                        {
                            SPFieldUrlValue value = new SPFieldUrlValue();
                            value.Description = this.downloadedMessageID + ".xml"; 
                            value.Url = this.SiteAddress + file.Url;
                            item["ZFO"] = value; 
                        }
                    }

this is fine except for one problem... before this code actually works... I need to call the item.update() method to save the item to SharePoint...

But as you can see there is more work to do ... after item.update is called...

So this means... I have

   work
   item.update();
   more work
   item.update(); 

The problem I am having is I really want just

  work
  item.update(); 

So that in any event of failure the whole thing will fail at once or pass at once.... (almost like a SQL transaction).

So whats preventing me from doing this is - I need to set a hyperlink to one of the fields in the list item, this will be to an attachment in the list attachments collection.

Is there any way I can predict this address without having saved the list item to MOSS?

1

1 Answers

3
votes

An attachment path depends on the item ID, and I don't believe your item will have an ID until you save it. Have you considered storing the attachments in a document library instead, linked by the field you're trying to set?

Transactional operation isn't exactly SharePoint's strong suit.