I have scenario where I am adding a document to a document library which has an external data column on it. My goal for this column is to have it automatically populated with an appropriate value based on original query string to the page. The general idea is that I am on a custom page that has various webparts on it including a view of my document library that is context sensative based on the query string, and I want to use that context sensitivity not just to filter the list but also when adding documents.
I have been searching around for solutions to this problem all day and have gotten this far:
I have an event receiver attached to my document library that handles the ItemAdded event syncronously (as such I have the new list item available to me). In that event receiver I am able to set the column values as required. Where I am stuck is on getting the value from the query string that I need to actually set as the column value.
Based on: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/8cfcb299-9a55-4139-86ec-0b53b2922a54 and several similar articles/posts I have been able to get the original source Url with the query string I want via the following code in my event receiver:
private HttpContext context;public EventReceiver1() { context = HttpContext.Current; }publicoverridevoid ItemAdded(SPItemEventProperties properties) {var originalQueryString = context.Request.QueryString["Source"];// Parse the query string and use the value ... }
The problem is that this solution breaks down if the dialogs are turned on under the advanced settings for the list. The reason the solution fails is because the "Source" query string parameter goes away and is replaced by "IsDlg" set to a value of "1".
Does anyone know how to get past this hurdle? Any help would be greatly appreciated.