Eric Maurer Copyright Keller Schroder 2008. Windows SharePoint Services 3.0 Tools: Visual Studio...

6
CUSTOM WEB PART BASICS Eric Maurer Copyright Keller Schroder 2008

Transcript of Eric Maurer Copyright Keller Schroder 2008. Windows SharePoint Services 3.0 Tools: Visual Studio...

Page 1: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

CUSTOM WEB PART BASICS

Eric Maurer

Copyright Keller Schroder 2008

VISUAL STUDIO ADD-INS Windows SharePoint Services 30 Tools

Visual Studio 2005 Extensions Version 11 Windows SharePoint Services 30 Tools

Visual Studio 2008 Extensions Version 12 Includes Projects For

Web Parts List Definition Site Definitions

Caveats Must run on a SharePoint server No visual designer Be careful when renaming web parts

IMPORTANT WEB PART METHODS Default constructor

Initialize variables and hook up event handlers here

Override Create Child ControlsAdd all controls to the web partrsquos controls

Override Render ContentsThis method can be overridden to write

content directly to the output

COMMON OBJECT MODEL CLASSES SPContext ndash Current context of the HTTP

request SPSite ndash Site Collection

SPContextCurrentSitenew SPSite(url)

SPWeb ndash SiteSpcontextCurrentWebsiteAllWebs[ldquonamerdquo]

SPUser ndash UserWebCurrentUser

WHEN DO I NEED TO USE DISPOSE Do not dispose if using SPContext

This is used internally by SharePoint and it will handle disposing of them when the page is closed

Use dispose if you are using the ldquonewrdquo methods SPSite site = new Site(http) you must dispose

of the SPSite and SPWeb if used to prevent memory leaks by using a using statement or a try catch finally block

Also sites or webs created in foreach statements must be disposedforeach(SPWeb web in siteAllWebs)

do something here

webDispose()

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment
Page 2: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

VISUAL STUDIO ADD-INS Windows SharePoint Services 30 Tools

Visual Studio 2005 Extensions Version 11 Windows SharePoint Services 30 Tools

Visual Studio 2008 Extensions Version 12 Includes Projects For

Web Parts List Definition Site Definitions

Caveats Must run on a SharePoint server No visual designer Be careful when renaming web parts

IMPORTANT WEB PART METHODS Default constructor

Initialize variables and hook up event handlers here

Override Create Child ControlsAdd all controls to the web partrsquos controls

Override Render ContentsThis method can be overridden to write

content directly to the output

COMMON OBJECT MODEL CLASSES SPContext ndash Current context of the HTTP

request SPSite ndash Site Collection

SPContextCurrentSitenew SPSite(url)

SPWeb ndash SiteSpcontextCurrentWebsiteAllWebs[ldquonamerdquo]

SPUser ndash UserWebCurrentUser

WHEN DO I NEED TO USE DISPOSE Do not dispose if using SPContext

This is used internally by SharePoint and it will handle disposing of them when the page is closed

Use dispose if you are using the ldquonewrdquo methods SPSite site = new Site(http) you must dispose

of the SPSite and SPWeb if used to prevent memory leaks by using a using statement or a try catch finally block

Also sites or webs created in foreach statements must be disposedforeach(SPWeb web in siteAllWebs)

do something here

webDispose()

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment
Page 3: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

IMPORTANT WEB PART METHODS Default constructor

Initialize variables and hook up event handlers here

Override Create Child ControlsAdd all controls to the web partrsquos controls

Override Render ContentsThis method can be overridden to write

content directly to the output

COMMON OBJECT MODEL CLASSES SPContext ndash Current context of the HTTP

request SPSite ndash Site Collection

SPContextCurrentSitenew SPSite(url)

SPWeb ndash SiteSpcontextCurrentWebsiteAllWebs[ldquonamerdquo]

SPUser ndash UserWebCurrentUser

WHEN DO I NEED TO USE DISPOSE Do not dispose if using SPContext

This is used internally by SharePoint and it will handle disposing of them when the page is closed

Use dispose if you are using the ldquonewrdquo methods SPSite site = new Site(http) you must dispose

of the SPSite and SPWeb if used to prevent memory leaks by using a using statement or a try catch finally block

Also sites or webs created in foreach statements must be disposedforeach(SPWeb web in siteAllWebs)

do something here

webDispose()

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment
Page 4: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

COMMON OBJECT MODEL CLASSES SPContext ndash Current context of the HTTP

request SPSite ndash Site Collection

SPContextCurrentSitenew SPSite(url)

SPWeb ndash SiteSpcontextCurrentWebsiteAllWebs[ldquonamerdquo]

SPUser ndash UserWebCurrentUser

WHEN DO I NEED TO USE DISPOSE Do not dispose if using SPContext

This is used internally by SharePoint and it will handle disposing of them when the page is closed

Use dispose if you are using the ldquonewrdquo methods SPSite site = new Site(http) you must dispose

of the SPSite and SPWeb if used to prevent memory leaks by using a using statement or a try catch finally block

Also sites or webs created in foreach statements must be disposedforeach(SPWeb web in siteAllWebs)

do something here

webDispose()

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment
Page 5: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

WHEN DO I NEED TO USE DISPOSE Do not dispose if using SPContext

This is used internally by SharePoint and it will handle disposing of them when the page is closed

Use dispose if you are using the ldquonewrdquo methods SPSite site = new Site(http) you must dispose

of the SPSite and SPWeb if used to prevent memory leaks by using a using statement or a try catch finally block

Also sites or webs created in foreach statements must be disposedforeach(SPWeb web in siteAllWebs)

do something here

webDispose()

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment
Page 6: Eric Maurer Copyright Keller Schroder 2008.  Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1  Windows SharePoint Services.

DEPLOYMENT Use the Visual Studio Tools to create a

Solution file Use a custom batch file to deploy the

web part a feature

stsadmexe -o addsolution -filename webpartpathwsp

stsadmexe -o deploysolution -immediate -allowGacDeployment -name webpartnamewsp -url httphellip -force

stsadmexe -o execadmsvcjobs

stsadmexe -o installfeature -filename webpartnamefeaturexml

stsadmexe -o activatefeature ndashname webpartname -url http

iisreset

  • Custom Web Part Basics
  • Visual Studio Add-Ins
  • Important web part methods
  • COMMON OBJECT MODEL classes
  • When Do I need to use dispose
  • Deployment