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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 33: The Windows SharePoint Services Object Model 937<br />

Note When performing global administration operations, you will need a different<br />

control for performing security validation: the AdminFormDigest control.<br />

To add a FormDigest Control to a Web Application<br />

This procedure shows how to add a FormDigest control to the Visual Studio .NET<br />

toolbox <strong>and</strong> add it to a Web form.<br />

1. Open your Web application in Visual Studio.NET.<br />

2. Go to the design view of a Web form, right-click the toolbox, <strong>and</strong> select<br />

Add/Remove Items.<br />

3. In the Customize Toolbox dialog, click Browse.<br />

4. Browse to the <strong>Microsoft</strong>.SharePoint.dll, which is located by default in<br />

:\Program Files\Common Files\<strong>Microsoft</strong> Shared\Web Server<br />

Extensions\60\ISAPI\<strong>Microsoft</strong>.SharePoint.dll. Click Open.<br />

5. Under the .NET Framework Components tab, locate FormDigest, select the check<br />

box, <strong>and</strong> click OK.<br />

6. Now you will find the FormDigest control added to the toolbox. Drag the<br />

FormDigest control on the Web form.<br />

If you switch to HTML view, you will notice a new page directive which<br />

registers the FormDigest control to the page.<br />

<br />

You will also notice a FormDigest control which is included in the form.<br />

<br />

Now you are ready to make posts from the Web application to modify the<br />

contents of the content database.<br />

Adding a FormDigest Control Programmatically<br />

You can also add a FormDigest control programmatically. This example shows how<br />

to add a FormDigest control to a Web Part. The first step is to create a new instance<br />

of the FormDigest control. Next you should call the Render method of the Form-<br />

Digest control to send the content of the control to an HtmlTextWriter object, which<br />

is responsible for writing the content that is rendered on the client. The following<br />

code can be copied into the RenderWebPart method of your Web Part:<br />

FormDigest myDigest = new FormDigest();<br />

myDigest.RenderControl(output);

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

Saved successfully!

Ooh no, something went wrong!