1

I have a SharePoint site page with a document library web part on it, once a document is uploaded to this library, some of the library fields need to be updated according to a parameter of the page url.

I tried doing this with Event Receiver binding on the library, only to find that I cannot get the page url, or rather the parameter, in the Event Receiver. Then Session occurred to my mind, but after asking around and searching a lot, I can only get HttpContext in itemAdding but not itemAdded, what's worse, HttpContext.Current.Session always give me nulll and I'm sure I have put some value into session earlier in somewhere else.

Can someone shed some light on this, any help or advise is deeply appreciated.

S.831
  • 113
  • 1
  • 10

3 Answers3

1

SharePoint allows synchronous and asynchronous event receivers. You can get access to HttpContext and SPContext in synchronous receiver, as it runs in worker thread. Read more for accessing HttpContext and how to bind synchronous receiver programmatically.

Oleg Savelyev
  • 968
  • 2
  • 8
  • 12
  • thank you for your input, I've read this before and now I can get HttpContext in single file upload, but still not in multiple files upload, even after I set synchronization specifically to synchronous in event receiver element.xml, any thoughts? – S.831 Sep 27 '12 at 10:41
  • Multiple files upload feature works only on IE and it limits the scope of browsers for your product. Moreover it looks like the multiple upload window (Upload.aspx application page) works like a proxy and file upload from it to library performed on server side. – Oleg Savelyev Sep 27 '12 at 12:55
  • yes, multiple files upload does work in IE(8), it's just HttpContext is somehow unavailable in multiple files upload, which can be gotten in single file upload – S.831 Sep 28 '12 at 01:04
1

It's a bit late but for reference I've just seen solution on this page.

It leverages custom control in master page and stores the information into HttpRuntime.Cache. Then access it from within the synchronous event.

eXavier
  • 4,821
  • 4
  • 35
  • 57
0

The event receiver is not called in the page context. Therefor you can't access the page information. The only approach to this that I can see is to write custom code that prefills the values of the page before you save the item.

KoenVosters
  • 431
  • 3
  • 9
  • thank you for your suggestion. Actually I've got Session working in ItemAdding event in single file upload, a remaining issue is HttpContext.Current is somehow unavailable in multiple files upload, this is very frustrating. – S.831 Sep 27 '12 at 07:41