views:

266

answers:

1

Hi All,

I have an aspx page with inline code in which I am trying to update the view programatically by setting view's Query property to my CAML query. When I run with administrator user everything works perfect view get updated successfully but when I logged in with a user who belongs to visitor group and having read only access then I get an error on view.Update() line saying that "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack". I have already try to run this code block with ElevatedPrivileges but not get any luck...(

following is my code which make you more clear

SPUserToken token = CurrentSite.SystemAccount.UserToken;   
  using (SPSite st=new SPSite(SPContext.Current.Web.Url,token))
   {
     st.AllowUnsafeUpdates = true;
       using (SPWeb wb=st.OpenWeb())
        {
          wb.AllowUnsafeUpdates = true;

            vwSearchResult.Query = Query;
             vwSearchResult.Update();
        }   
       }

Thanks in advance for any help

+1  A: 
  1. What you are doing here, is modifying the definition of the view for ALL users of the website, not only the current rendering instance of the page. This is why simple visitors cannot change it (they do not have such permission in the web)
  2. If you want to do something, using the "SystemAccount" token, you have not only to do the "using SPSite, using SPWeb", but also find the list and the view using the "strong" SPWeb objects
  3. Instead of modifying a view definition at runtime, you might want to consider using ListViewByQuery class http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.listviewbyquery.aspx
naivists