Presentation is loading. Please wait.

Presentation is loading. Please wait.

PCT403 – SharePoint and WSS: Allowing Your Code to Work with Both Eugene Rosenfeld Black Blade Associates

Similar presentations


Presentation on theme: "PCT403 – SharePoint and WSS: Allowing Your Code to Work with Both Eugene Rosenfeld Black Blade Associates"— Presentation transcript:

1 PCT403 – SharePoint and WSS: Allowing Your Code to Work with Both Eugene Rosenfeld Black Blade Associates

2 Overview This session will focus on creating applications, web parts, and server controls that function in both a portal, WSS within portal, and WSS only environments. Topics will include Distinguishing between portal areas and WSS sites The use of reflection to dynamically load portal- specific assemblies when present Correctly handling the differing security models of the three scenarios. Application elements such as site navigation will be specifically targeted.

3 The Similarities Sites Lists Libraries

4 The Differences Object types Portal has many more object types than WSS Navigation Sub Areas vs. Sub Sites Area hierarchy is virtualized; sites hierarchy is physical Hidden Areas Explicit order vs. Alphabetical order Container Sites Sites Directory Security Sites support list level security; areas do not Audiences for web parts Portal Listings Portal Assemblies

5 Programming Frameworks SharePoint object model SharePoint web services Regardless of which framework we are using, we need to answer: Is the code accessing a server with SPS or just WSS? Is the site the code is accessing a site or an area?

6 SharePoint object model Distinguishing between portal areas and WSS sites Early binding to both WSS and SPS assemblies but detecting assembly load errors on SPS assembly Early binding to both WSS but late binding to SPS assemblies Using conditional compilation to create separate WSS and SPS version of the assembly

7 Assemblies – Early Binding Conditional compilation directives Pros: Compile time error checking Cons: Two different version of each assembly More complex deployment – deploy correct assembly for correct environment May need to deploy different assembly if environment changes More testing Code must run from a server in the farm Can only work against one server farm at a time

8 Early Binding - Code private void button1_Click(object sender, System.EventArgs e) { System.Reflection.Assembly asmWSS; try { //try to load the assembly asmWSS = System.Reflection.Assembly.Load("Microsoft.SharePoint, Version= , Culture=neutral, PublicKeyToken=71e9bce111e9429c"); } catch(Exception ex) { //the assembly could not load. we assume there is no WSS on this computer asmWSS = null; System.Diagnostics.Trace.WriteLine("Error detected: " + ex.Message + "\r\n" + ex.StackTrace, ex.GetType().Name); } if(asmWSS != null) UseWSS(); } private void UseWSS() { //we have a strong reference to an SPSite object Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite("http://localhost"); MessageBox.Show(site.GetType().Name.ToString(), "SPSite object created"); }

9 Assemblies – Late Binding Late Binding Through Reflection Pros: Single assembly for WSS or Portal Cons: Minimal compile time error checking More code to manage Code must run from a server in the farm Can only work against one server farm at a time

10 Late Binding - Code System.Reflection.Assembly asmWSS; try { //try to load the assembly asmWSS = System.Reflection.Assembly.Load("Microsoft.SharePoint, Version= , Culture=neutral, PublicKeyToken=71e9bce111e9429c"); } catch(Exception ex) { //the assembly could not load. we assume there is no WSS on this computer asmWSS = null; System.Diagnostics.Trace.WriteLine("Error detected: " + ex.Message + "\r\n" + ex.StackTrace, ex.GetType().Name); } if(asmWSS != null) { //the assembly has loaded //get a late bound reference to the SPSite type Type typSPSite = asmWSS.GetType("Microsoft.SharePoint.SPSite"); //get a reference to the constructor for SPSite that has this signature: // new Microsoft.SharePoint.SPSite("http://localhost") // and invoke the constructor object objSPSite = typSPSite.GetConstructor(new Type[]{ typeof(string) }).Invoke(new object[]{ "http://localhost" }); //we now have a late bound object reference to a SPSite object MessageBox.Show(objSPSite.GetType().Name.ToString(), "SPSite object created"); }

11 Unified Web Services Pros: Easily decide if connecting to Portal or WSS Connect to remote server farms from any client Cons: May not work properly when using client PKI certificates for authentication

12 Unified Web Services – Code // set up the web service calls SiteDataWS.SiteData siteDataWS = new WindowsApplication1.SiteDataWS.SiteData(); siteDataWS.Url = this.txtURL.Text + (this.txtURL.Text.EndsWith("/") ? "" : "/") + "_vti_bin/sitedata.asmx"; siteDataWS.Credentials = System.Net.CredentialCache.DefaultCredentials; siteDataWS.PreAuthenticate = true; AreaWS.AreaService areaWS = new AreaWS.AreaService(); areaWS.Url = this.txtURL.Text + (this.txtURL.Text.EndsWith("/") ? "" : "/") + "_vti_bin/areaservice.asmx"; areaWS.Credentials = System.Net.CredentialCache.DefaultCredentials; areaWS.PreAuthenticate = true; // set up the returns for the web methods SiteDataWS._sWebMetadata sWebMetadata; SiteDataWS._sWebWithTime[] sWebWithTime; SiteDataWS._sListWithTime[] sListWithTime; SiteDataWS._sFPUrl[] sFPUrl; string strRoles; string[] strvRoleUsers; string[] strvRoleGroups; // get the web meta data information for the site uint intRet = siteDataWS.GetWeb(out sWebMetadata, out sWebWithTime, out sListWithTime, out sFPUrl, out strRoles, out strvRoleUsers, out strvRoleGroups); AreaWS.AreaData adArea; try { // get the area information for the web id adArea = areaWS.GetAreaData(new Guid(sWebMetadata.WebID)); } catch { // we were unable to execute the area service. assume WSS only MessageBox.Show(this.txtURL.Text + " is a site. The server has WSS, not SPS."); return; } if(adArea.WebUrl == null) // a null web url means the web id does not correspond to an area MessageBox.Show(this.txtURL.Text + " is a site. The server has both WSS and SPS"); else // a valid web url means the web id does correspond to an area MessageBox.Show(this.txtURL.Text + " is an area.");

13 Questions Eugene Rosenfeld Black Blade Associates


Download ppt "PCT403 – SharePoint and WSS: Allowing Your Code to Work with Both Eugene Rosenfeld Black Blade Associates"

Similar presentations


Ads by Google