tags:

views:

94

answers:

1

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?

+3  A: 

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.

dahlbyk
I need to have 1 all emcompassing object. But thanks... and you're right, the item ID is key to the puzzle. Is there some way to probe what this item id might be?
JL
There really isn't. You could guess based on the current max ID and just hope that the most recently-added item hasn't been deleted (and you don't have simultaneous operations), but I wouldn't recommend it. I would just use two updates and attempt a manual rollback if second update fails.
dahlbyk
Another reason why I "love SharePoint"
JL