Share point 2010_overview-day4-code

20
Presented by Narayana Reddy

Transcript of Share point 2010_overview-day4-code

Page 1: Share point 2010_overview-day4-code

Presented byNarayana Reddy

Page 2: Share point 2010_overview-day4-code

Agenda

• Architecture • Client Installation• Debugging the Server• Web Parts• Application pages• Custom fields• Controls• Questions

Page 3: Share point 2010_overview-day4-code

SharePoint 2010 Architecture

Page 4: Share point 2010_overview-day4-code

SharePoint 2010 Client Installation

Start with the SharePoint.exe file for SharePoint Foundation or SharePoint Server 2010. Extract the files from SharePoint.exe with the following command line. A user account control (UAC) prompt might appear at this point.

SharePoint.exe /extract:c:\SharePointFilesThis extracts all of the installation files to your hard drive. Use a folder you can recognize easily later, such as c:\SharePointFiles. This allows you

to repeat the installation steps without extracting the package again and enables access to the configuration file that needs tweaking, to permit installation on Windows Vista or Windows 7:

c:\SharePointFiles\Files\Setup\config.xmlAdd the following line to the end of the config.xml file:

<Setting Id="AllowWindowsClientInstall" Value="True"/>The complete file should now look like this:

<Configuration><Package Id="sts">

<Setting Id="SETUPTYPE" Value="CLEAN_INSTALL" /></Package><DATADIR Value="%CommonProgramFiles%\Microsoft SharedXWeb Server

Extensions\14\Data" /><Logging Type="verbose" Path="%temp%" Template="Microsoft Windows

SharePoint Services 4.0 Setup *.log" /><Setting Id="UsingUIInstallMode" Value="1" /><Setting Id="SETUP_REBOOT" Value="Never" /><Setting Id="AllowWindowsClientInstall" Value="True"/>

</Configuration>

Page 5: Share point 2010_overview-day4-code

Debugging the Server A web application consists of several parts. IIS plays a significant role—each request and

response passes through IIS. Debugging the server includes a way to debug IIS to see what data is transmitted from the browser to the server and back. Despite debugging, performance issues often arise. To test your SharePoint application under load, a stress test tool is essential.

If your SharePoint server does not respond as expected and the debugger does not reveal useful results—probably because an internal module beyond your access scope fails—you need more tools. SharePoint hides error message and replaces stack traces, exception messages, and logs with almost useless information. It's primarily designed for end users, and they might get frightened when a NullReferenceException is displayed (e.g., "Did I lose all my data now?"). In your development environment, you can turn on developer-friendly (and therefore user-unfriendly) error messages by setting the appropriate parameters in the web.configfile:<configuration>

<SharePoint><SafeMode CallStack="true" ... />

...</SharePoint><system.web><customErrors mode="off" />

...</system.web>

</configuration>

Page 6: Share point 2010_overview-day4-code

How to Check Errors Look into the event log for SharePoint.

Look into the SharePoint logs.

Attach a debugger to the working process and watch for exceptions.

Look into the IIS logs.

Add tracing to your code and watch the traces.

Consider remote debugging if the target machine has no debugger installed.

Let's consider each of these alternatives in more detail.

Looking into the Event Log for SharePoin

Page 7: Share point 2010_overview-day4-code

Looking into the SharePoint and IIS LogsSharePoint itself writes a lot of data into the logs if it is enabled in Central Administration. During the development and test cycle, we strongly recommend activating the logs. You can find the logging files in

<%CommonProgramFiles%>\Microsoft Shared\Web Server Extensions\14\L0GS

The IIS logs are found here:

<%SystemRoot%>\System32\LogFiles Ex:(C:\Windows\System32\LogFiles)The IIS logs contain information about each request and the response. If you match certain reactions of SharePoint with the event of a specific request, there is a good chance of Unding the reason for some unexpected behavior.If you suspect that your code is causing the miss-behaviour and the debugger disturbs the data flow, a private trace is a good option. Just write useful information from your code to a trace provider. You can turn tracing on and off by setting the appropriate options in the application's web.config file:

<configuration><system.web><trace enabled="true" requestLimit="40" localOnly="false"/></system.web></configuration>t

Page 8: Share point 2010_overview-day4-code

Activate the Developer Dashboard

$level="On"[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoi

nt")[void][System.Reflection.Assembly]::LoadWithPartialName

("Microsoft.SharePoint.Administration")$contentSvc=[Microsoft.SharePoint.Administration.SPWebService]::ContentSer

vice$contentSvc.DeveloperDashboardSettings.DisplayLevel=

([Enum]::Parse([Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel],$level))

$contentSvc.DeveloperDashboardSettings.Update()Write-Host("Current Level: " +

$contentSvc.DeveloperDashboardSettings.DisplayLevel)

“On”: Activate the Developer Dashboard “Off”: DeactivateOn and Off are Case Sensitive.

Page 9: Share point 2010_overview-day4-code
Page 10: Share point 2010_overview-day4-code

SharePoint Request Pipeline

Page 11: Share point 2010_overview-day4-code

Application Pool The application pool was introduced with IIS 6 to allow the

complete isolation of applications from each other. This means that IIS is able to completely separate things happening in one application from those in another. Keeping applications together in one pool can still make sense, because another pool creates its own worker process, and will use more resources.

Separate applications make the web server more reliable. If one application hangs, consumes too much CPU time, or behaves unpredictably, it affects its entire pool. Other application pools (and the applications within them) will continue to run. In addition, the application pools are highly configurable.

Page 12: Share point 2010_overview-day4-code

Data Base in Sharepoint

Page 13: Share point 2010_overview-day4-code

GHOSTING AND UNGHOSTING In SharePoint, most of the site pages derive from templates. The custom pages only

store the difference between the custom page and the associated template. The template is loaded in memory and applied to the custom pages on the fly. Holding the template in the memory is like having it in a cache. This adds performance and flexibility. The flexibility is achieved when you change the template page—all the associated custom pages are updated with the new appearance. Custom pages are loaded from the file system. Such pages are called ghosted pages.

When page data is loaded from the content database, it's called an unghosted page. That's normally the default way you treat custom pages. Internally, the unghostedpages are supported by two tables. The page requires an entry in the document table because pages are elements within a document library. The content table contains the actual source code of the ASPX page required to execute the page.

When a page is requested, SharePoint first checks in the document table and then goes to the content table to load the page. If it does not find data for the page, it goes to the file directory to load the page. This entire page-loading process is performed by the ASP.NET runtime using the SPVirtualPathProvider mentioned earlier. This ensures flexible access as well as full control over the loading procedure.

Page 14: Share point 2010_overview-day4-code

SPList

Page 15: Share point 2010_overview-day4-code

SPField

%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\XML

Page 16: Share point 2010_overview-day4-code

Web Part Create Visual Web Parts for SharePoint 20101. Start Visual Studio 2010, click File, point to New, and then click Project.

2. Navigate to the Visual C# node in the Installed Templates section, click SharePoint, and then click 2010.

3. Select the Visual Web Part project template, provide a name, a location for your project, and then click OK.

4. Select the Deploy as a farm solution option and then click Finish.

5. Check Features and Package

6. Add a Label and Button, write button click event.

7. Deploy web part.

8. Add Web part in a any page.

9. Attach Debugger.

Page 17: Share point 2010_overview-day4-code

SharePoint 2010 Development Open Visual Studio 201o

Create a blank SharePoint 2010 Solution.

Create a Sample Visual WebPart and Check Properties F4

Deploy Web part.

Show how to add new item to a project.

Show WSP file.

Deploy using VS 2010.

Page 18: Share point 2010_overview-day4-code

using System;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using Microsoft.SharePoint;using Microsoft.SharePoint.Utilities;using System.Web;using System.Data;using Microsoft.SharePoint.Administration;

namespace Group.VisualWebPart1{

public partial class VisualWebPart1UserControl : UserControl{

protected void Page_Load(object sender, EventArgs e){

DataTable table = new DataTable();table.Columns.Add("Site", typeof(string));table.Columns.Add("Web", typeof(string));table.Columns.Add("List", typeof(string));table.Columns.Add("ItemURL", typeof(string));table.Columns.Add("ItemTitle", typeof(string));table.Columns.Add("Size", typeof(string));

#region Only Root WebSPSecurity.RunWithElevatedPrivileges(delegate{

SPSiteCollection siteCollections = SPContext.Current.Web.Site.WebApplication.Sites; //oSPWeb.WebApplication.Sites;

foreach (SPSite objSPSite in siteCollections){

SPWeb objSPWeb = objSPSite.RootWeb;

//Shared Documents should be available in all sites including sub sites.SPList spDocument = objSPWeb.Lists["News"];foreach (SPListItem objItem in spDocument.Items){

try{

//table.Rows.Add(objSPSite.Url, objSPWeb.Title, spDocument.Title, objItem.Url, objItem.Title, objItem.File.Length);table.Rows.Add(objSPSite.Url, objSPWeb.Title, spDocument.Title, objItem.Title);

}catch (Exception ec) { }

}objSPWeb.Close();

}});#endregion

#region All Sites

//SPSecurity.RunWithElevatedPrivileges(delegate//{// SPSiteCollection siteCollections = SPContext.Current.Web.Site.WebApplication.Sites; //oSPWeb.WebApplication.Sites;

// foreach (SPSite objSPSite in siteCollections)

News WebPart

Page 19: Share point 2010_overview-day4-code

Simple Visual Web Partusing System;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using Microsoft.SharePoint;using Microsoft.SharePoint.Utilities;

namespace VisualWebPartDashboard.VisualWebPart1{

public partial class VisualWebPart1UserControl : UserControl{

protected void Page_Load(object sender, EventArgs e){

using (SPMonitoredScope scope = new SPMonitoredScope(this.GetType().Name)){

Button b = new Button();b.Text = "Click me!";Controls.Add(b);using (SPMonitoredScope scopeInner = new SPMonitoredScope("Inner Scope")){

System.Threading.Thread.Sleep(5); // lengthy operation}

}

}}

}Chapter 6.Using Fiddler to Understand What's Going on the Wire

Page 20: Share point 2010_overview-day4-code

Q & A