Topic
Writing / Creating Sharepoint WebPart with Elevated Privilege and Editor Part
( Hello World SharePoint WebPart )
( Hello World SharePoint WebPart )
Prerequisites
- Microsoft Visual Studio 2005
- SharePoint 2007 Farm
Occasionally your code calls restricted methods within the Windows SharePoint Services(WSS/MOSS) object model.
This code will throw error, access denied in the event logs if not called properly. To make the code run even though the request is initiated by a nonprivileged user, you must be able to elevate the privilege of your code as it executes on the Web server. This blogs exactly shows you how to achieve this.
What is Editor Part
Basically the Properties of a Web Part.
These properties can be edited in the webpart page edit mode as shown below:
Tools used in the demo solution
* VeWss for Visual Studio
i.e. Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions, Version 1.1
Download: link
* Deployment Tool
Download link SharePoint Solution Installer
WebPart Development Steps
* Download the source code for the demo
* Open in VS 2005 and you will see a folder hierarchy as shown in the diagram
Files / Components involved
* WebPart Code
* Custom Editor Part
* Cab.ddf
* Manifest.xml
* Element.xml
* Feature.xml
* Mango.webpart
* Build the downloaded Project Solution File in VS 2005
* Edit Setup.exe.config as/if required
SafeControl Assembly="Mango, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="Mango" TypeName="*" Safe="True" />
* Use the setup.exe to install the solution
* To make sure everything work as expected, execute the following from command prompt
stsadm -o execadmsvcjobs
* Activate WebPart, and then Add WebPart to the page.
Download Link source code
* Mango.webpart
* Run "CreateSolutionPackage.cmd" (under package directory of source code)
* Build the downloaded Project Solution File in VS 2005
* Drag and drop the assembly in the GAC
* Modify the web.config to add assembly as safe control
<* Edit Setup.exe.config as/if required
SafeControl Assembly="Mango, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="Mango" TypeName="*" Safe="True" />
* Use the setup.exe to install the solution
* To make sure everything work as expected, execute the following from command prompt
stsadm -o execadmsvcjobs
* Activate WebPart, and then Add WebPart to the page.
Download Link source code
Enjoy Coding!
1 comment:
Keep up the good work.
Post a Comment