Razor Generator – one or more types required to compile a dynamic expression cannot be found

Having a MVC4 project with Razor Generator view engine installed, I got the following error when trying to compile a view:

One or more types required to compile a dynamic expression cannot be found

Also it happens that helper methods using lambda syntax cannot be used, as well as dynamic types, like the ViewBag.

To solve this problem, I have added Microsoft.CSharp.dll to the project, and set it to Copy Local = true.

Invoking a web service using Windows authentication in C#

Loading content of a MVC view delayed using Ajax and jQuery

Data View WebPart Filter on a MultiLookup field in DispForm with Sharepoint 2007

Add a FieldValue control to the page that is bound to the MultiLookup field by the FieldName attribute:

<SharePoint:FieldValue ID=”fldValMyContacts” FieldName=”MyContacts” runat=”server” Visible=”false”></SharePoint:FieldValue>

Add a parameter:

<ParameterBinding Name=”MyContacts” Location=”Control(fldValMyContacts, ItemFieldValue)” DefaultValue=”0″/>

Create a xsl filter:

<xsl:variable name=”Rows” select=”/dsQueryResponse/Rows/Row[contains(concat('#',$MyContacts),concat('#',@ID,';'))]“/>

Optimize MS SQL Database

I just was researching how to optimize a MS SQL database and humbled over this post.

Summary:

  • Do not run “Shrink Database Task”
  • Turn off “Auto Shrink” property (Right click on the database in SQL Manager – Settings – Options – Set Auto shrink┬áto False)
  • Run EXEC sp_MSforeachtable “dbcc dbreindex(‘?’, ”, 90)”
  • Then run “EXEC sp_updatestats

Deploy custom SharePoint timer job with site url in property bag

As you don’t have a SPContext in your timer job and don’t want to hard code the site url (or simply don’t know it yet) it will be hard to get on a specific site programmatically.

Therefore the best solution will be to save the url to which the timer job has been deployed to the property bag of your timer job. To do this you can use the FeatureActivated event of your timer job feature.

Now that you have the site url in your timer job’s property bag you can easily optain it from your code:

Found on / credits to: ADI CODES

Force to execute a SharePoint timer job programmatically

If you want to execute a timer job and don’t want to wait for the intervall you can start it programmatically like this:

Solution found on this nice blog entry.

No postback possible after file download in Sharepoint

If you provide a custom response on a button click event, like a download within a WebPart you may find out that no more submits are possible after the button has clicked.

The reason for this behaviour is that Sharepoint sets the _spFormOnSubmitCalled to true and allows no more submits unless it is set back to false (Which is usually done automatically on a post back).

So setting the OnClientClick event to “_spFormOnSubmitCalled = false;” should help ti get around this. However, to be sure the assignment is not overwritten we add a little timeout as you can see in the following example which I found in this very helpfull post on stackoverflow.

 

 

Deploying custom DispForm.aspx – How to remove the automatically created ListFormWebPart

If you want to deploy a custom DispForm.aspx in your WSP package you will have to fix the file after deploying in the Sharepoint Designer, as there are still the list ids from the dev system, the DispForm.aspx is copied from. Also you will find that Sharepoint has automatically created a second ListFormWebPart on the page as it didn’t recognize your’s with the old list id.

If you want to go the easy way, hide the automatically created ListFormWebPart by setting its IsVisible element’s value to false and simply replace the ListName (which contains the List ID) in the original ListFormWebPart with the new List Id.

If you want a clean conscience and remove the second ListFormWebPart you have to do the following steps:

NOTE If you simply remove the second ListFormWebPart, the page will crash, so be sure to follow all the steps below to be safe

  • Remove the ID from ListFormWebPart
  • Find the automatically created ListFormWebPart and obtain the following data from it: the __WebPartId attribute’s value, the ListName element’s value, the ViewFlag element’s value, the ID element’s value
  • Replace the old ListName (which is actually the ListID) with the new one from the second ListFormWebPart in the ListName element
  • Replace the ViewFlag element’s value with the one found in the second ListFormWebPart
  • Replace the __WebPartId attribute’s value with the one found in the second ListFormWebPart
  • Replace the ID element’s value with the one found in the second ListFormWebPart
  • Remove the automatically created ListFormWebPart

Actually I didn’t figure out whether each step is required to get it working, but this way it works.