16.01.2013 Views

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

928 Part IX: Maintaining a Server in Windows SharePoint Services<br />

The bForce parameter can be set to true to overwrite an existing Web Part<br />

package with a new version.<br />

Finally, the logWriter parameter contains a System.IO.TextWriter object that is<br />

used to write an error log to the text stream.<br />

Before you can call the AddWPPack method, you should create an instance of<br />

the SPGlobalAdmin class. The following code example can be copied into a Web<br />

Part. Because this is just an example, the AllowUnsafeUpdates property of the<br />

SPGlobalAdmin class is set to true so that updates are allowed to the database as a<br />

result of a GET request. If you do not set this property, the AddWPPack method will<br />

fail after an HTTP GET request. This opens a security risk. In real world situations<br />

you would probably call the AddWPPack method in a non-HTTP context, from<br />

either a comm<strong>and</strong>-line executable or a Windows application. If you want to call the<br />

AddWPPack method in an HTTP context, you should send an HTTP POST request<br />

<strong>and</strong> add the AdminFormDigest control to the form body, which is discussed later in<br />

the “<strong>Microsoft</strong>.SharePoint.WebControls Namespace” section.<br />

SPGlobalAdmin myGlobalAdmin = new SPGlobalAdmin();<br />

myGlobalAdmin.AllowUnsafeUpdates = true;<br />

myGlobalAdmin.AddWPPack(@"C:\projects\Res<strong>Kit</strong>Cab\Debug\Res<strong>Kit</strong>Cab.cab", null, 1033,<br />

null, true, true, null);<br />

The EnumWPPack Method<br />

The following code example shows how to return a string containing all the Web Part<br />

packages installed on the virtual server. You can do this by using the EnumWPPack<br />

method of the SPGlobalAdmin class. The signature of the EnumWPPack method looks<br />

like this:<br />

public string EnumWPPacks(<br />

string strName,<br />

string strURL,<br />

bool bEntireFarm<br />

);<br />

The strName parameter contains the name of a Web Part package or null. The<br />

strURL parameter contains the URL for the virtual server or null. The bEntireFarm<br />

parameter has the value true when you want to list the Web Part packages currently<br />

installed on a server farm; otherwise, it contains false or null. The return value contains<br />

information about Web Part packages that are installed. The format of this<br />

string depends on which parameters are used.<br />

Before you can call the EnumWPPacks method, you should create an instance<br />

of the SPGlobalAdmin class. The code example shown here can be copied into a<br />

Web Part. This code example will return the host name, the name of the .cab file <strong>and</strong><br />

the locale, <strong>and</strong> the virtual server name.<br />

SPGlobalAdmin myGlobalAdmin = new SPGlobalAdmin();<br />

strReturn = myGlobalAdmin.EnumWPPacks(null, "http://woodgrove/", true);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!