Another CRM -> Sharepoint integration

Here is my first blogpost in English since I received requests from non speaking
Swedes. The MSCRM team, Kjell-Sverre Jerijærvi
(Integrating
team-sites into MSCRM (part II)
) and allot of others has published different
ways of integrating MSCRM with Sharepoint. Guess what! Here is another solution
actually made back in 05’ as a Proof of concept solution… Each Account has its own
sharepoint library structured under an alphabetic label (dummy library). This is
done initial on setup of libraries A,B,C,D etc. A custom Sharepoint template is
used for MSCRM look and feel (not in scope of this blogpost)

For example Alfa Demo Account is stored as own library under letter A with it's
url stored on the MSCRM.

SPSite site = null;

try

{

site = new SPSite(wssServerUrl);

SPSite newSite = site.SelfServiceCreateSite(rootUrl, siteName,

description, 1053, "STS", @"custom\mscrm", "Admin",

"mscrm@custom.local", @"custom\mscrm", "Admin", "mscrm@custom.local");

SPWeb web = newSite.OpenWeb();

web.Webs.Add(nextLevelSiteName, nextLevelSiteName, description, language,
template, false, false);

}

catch (SPException err)

{

System.Diagnostics.Debug.WriteLine(err.Message);

throw;

}

catch (Exception err)

{

System.Diagnostics.Debug.WriteLine(err.Message);

throw;

}

finally

{

site.Dispose();

}

A new chrome remover file is stored under its own web.

MSCRM_iframe.aspx cleaner removes chromes
from library files

<%@ Page Language="C#" %>

<%string sUrl = Context.Request["url"];%>

<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>MSCRM
Integration</title>

<scriptlanguage="Jscript">

var iNavCount=0;var strValidPages="AllItems.aspx,Upload.aspx,Checkin.aspx,EditForm.aspx,DispForm.aspx,Versions.aspx,SubNew.aspx";var strOriginalUrl="<%=sUrl%>";function
evReadyStateChange()

{var oFrm=document.frames.mscrmShowPage;var
ofrmElement=event.srcElement;try{var sDoc=oFrm.location.pathname;sDoc=sDoc.substring(sDoc.lastIndexOf("/")+1);if(ofrmElement.readyState=='loading'){ofrmElement.style.display="none";oFrm.onerror=function(){return
true;}}else if(ofrmElement.readyState=='complete'){var
bValid=false;iNavCount++;var
arrTmp=strValidPages.split(",");for(var
s in arrTmp)if(arrTmp[s]==sDoc)bValid=true;if(!bValid){document.location.assign("MSCRM_error.aspx?rUrl="+location.href);}else{try{var
oTable=oFrm.document.all.tags("table")[0];oTable.rows(0).style.display="none";oTable.rows(1).style.display="none";oTable.rows(2).cells(0).style.display="none";oFrm.document.all("diidEditInGridButton")[0].parentNode.parentNode.style.display="none";oFrm.IMNShowOOUI=function(){return
false;};}catch(e){}

oFrm.document.body.insertAdjacentHTML("beforeEnd","<a href='#' onclick='window.open(location.href)'
class='ms-formdescription' style='position:absolute;top:10px;right:10px;color:blue'>In
new window</a>");ofrmElement.style.display="inline";}}}

catch(e)

{}}

</script>

</
head >

<
body style ="margin:0 0 0 0">

<%if (sUrl!=null) {%>

<iframeid="mscrmShowPage"frameborder="0"height="100%"width="100%"onreadystatechange="evReadyStateChange()"style="display:none"src="<%=sUrl%>"></iframe>

<%}%>

</
body >

</html>

On MSCRM server a new virtual directory
(or new web according to ISV rules) holds files to link it all to WSS or Sharepoint
side.

<divclass="tab"id="tabBody1"style="DISPLAY:
inline">

<tableid="Table0"style="TABLE-LAYOUT:
fixed"height="100%"cellSpacing="0"cellPadding="3"width="100%">

<tr>

<td>

<iframeid="Iframe0"frameborder="0"width="100%"height="100%"src="<%Response.Write(ConfigurationSettings.AppSettings["PathToMSCRM"].ToString());%>/SharePointConnector/_redirect.aspx?<%Response.Write(Request.QueryString);%>&Folder=1"></iframe>

</td>

</tr>

</table>

</div>

Clip from AccountCreateFrame.aspx .

I added 2 keys in MSCRM’s web.config
for dynamic settings

<appSettings>

<addkey="PathToMSCRM"value="http://crm/Beta.Crm.Sharepoint/"/>

<addkey="SharePointServerIframe"value="http://sharepoint/_layouts/CRM/MSCRM_iframe.aspx?url="/>

</appSettings>

I prefer to add everything on the leftside navigation
and that could be easily done by modification of ISV.config
or by injecting js script in from onLoad

Documents added in
ISV.config pointing <PathToMSCRM> Accountcreateframe.aspx

You can download all files here
and hopefully everything is clearer when you look at the code J

NOTE!!! You are required to
have licenses for SharePoint server

Not Supported example code.zip