kamagra how much to take

Building SharePoint WebParts in Chrome and Delphi

Before you read this post, my code highlighter, GeSHi, doesn’t support Pascal highlighting. So, it is highlighted in generic syntax. I am 100% interested in getting community contributions on this subject. If you want to contribute to this subject, regarding SharePoint development outside of C# or VB.NET, please contact me at my personal email through the feedback page on the main site. I am most likely going to start a new article thread on the main sharepointsecurity.com site, or create a step-by-step downloadable guide for, that I will give interested people complete access to for posting hints, tips, and tricks with full credit, because this subject is sorely missing for people bridging into SharePoint development.

Anyways, here is my first attempt…

You might be a Delphi developer, or maybe a Chrome developer, sitting in your organization, sneaking in a game of WarCraft or something else, and just got charged by management with doing an obscene amount of SharePoint WebPart development for your organization.

No problem you think, I can handle this, it all comes out to the same MSIL doesn’t it? When starting to get your project going through, you may find that researching how to build a simple example SharePoint WebPart done in Delphi, or any other language outside of VB.NET or C#, is only mildly more frustrating than trying to figure out the cure for world hunger.

I was in the same situation. Before switching to C#, I primarily did VC++ development (I still program a majority of my web service code in VC++ too, as well as my entire shared class library for SAML is in VC++). If you are doing your SharePoint programming in your native language of choice, you are going to be up a creek sans paddle when trying to start out coding a simple WebPart.

This is, to me, is one of the primary reasons that developers get turned off to SharePoint development. So, being one that likes to use other programming languages (ok, maybe it is just VC++ but whatever), I decided to write up how to code a simple WebPart in a variety of other languages. There are so many tools to use languages like Pascal and Delphi within .NET applications, such as Hydra, and entirely too much to cover in just one post. I will expand this concept further with a more complex sample WebPart for other .NET compatible languages when I think of a suitable example. Probably something that interacts with the SharePoint Object Model heavily like SharePoint list displays or the likes.

Anyways, out of the two pieces in this article, I only know Delphi a little bit, have dabbled in Chrome, and found the example WebPart upon compilation worked fine for rendering out text that is manageable directly from a WebPart persistent property. I won’t reveal how long it took me to figure out the proper compilation sequences, because frankly it’s embrassing. This also doesn’t mean it is the right or the best practice code, so please contact me if I can correct or expand this content, as it would be a fun subject to contribute to.

If you are completely new to SharePoint development, I would encourage you to read this article on the main sharepointsecurity.com site in order to gain an understanding of the standard class inheritance, method overrides, and other things that go on with the WebPart. If you use some other .NET compliant language in your organization that I haven’t covered, shoot me an email and I will add to these examples. I would like to improve the amount of documentation that is available for all types of developers, and I think this is a good start.

In these examples, I am going to show you how to render out a string that is entered via a WebPart property, demonstrated through two different methods. Here is a screenshot of the final product (yeah, its not very impressive, but hey, its a start on this subject):

Both of these WebParts regardless of methods will be inheriting from the ASP.NET 2.0 WebPart base class (System.Web.UI.WebControls.WebPart) as opposed to the SharePoint WebPart (Microsoft.SharePoint.WebPartPages.WebPart) base class as a better practice.

The first method that will be demonstrated directly writes to the control stream using the property defined text in the overridden Render Method. The second method that will be shown will use a literal control declared in the CreateChildControls method and then the RenderChildern method to output the stream within the Render method.

Building a Simple SharePoint WebPart in Chrome

Method 1: Directly Output in Render Method

  1. namespace  Example_WebPart;
  2. interface
  3. type
  4. Example_WebPart = public class(WebPart)
  5.  
  6. { WebPart Fields }
  7. private _exampleText: String;
  8.  
  9. { WebPart Methods }
  10. method Example_WebPart.Render(writer: HtmlTextWriter);
  11. begin
  12. writer.&Write(self._exampleText)
  13. end;
  14.  
  15. { WebPart Properties }
  16. [Category('Example Properties'), Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDescription('Adam''s Example Text'), WebDisplayName('Adam''s Example Text For Output')]
  17. property exampleText: String read get_exampleText write set_exampleText;
  18. end;

Method 2: Render Out Literal Control in CreateChildControls and Call RenderChildern

  1. namespace  Example_WebPart;
  2. interface
  3. type
  4. Example_WebPart = public class(WebPart)
  5.  
  6. { WebPart Fields }
  7. private _exampleText: String;
  8.  
  9. { WebPart Methods }
  10. method Example_WebPart.CreateChildControls;
  11. begin
  12. inherited CreateChildControls;
  13. self.Controls.&Add(new LiteralControl(self._exampleText))
  14. end;
  15.  
  16. method Example_WebPart.Render(writer: HtmlTextWriter);
  17. begin
  18. self.RenderChildren(writer)
  19. end;
  20.  
  21. { WebPart Properties }
  22. [Category('Example Properties'), Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDescription('Adam''s Example Text'), WebDisplayName('Adam''s Example Text For Output')]
  23. property exampleText: String read get_exampleText write set_exampleText;
  24. end;

Building a Simple SharePoint WebPart in Delphi

Method 1: Directly Output in Render Method

[Delphi]
unit  Example_WebPart;
interface
type
public Example_WebPart = class(WebPart)

// WebPart Fields
strict private _exampleText: string;

// WebPart Properties
[Category(‘Example Properties’), Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDescription(‘Adam”s Example Text’), WebDisplayName(‘Adam”s Example Text For Output’)]
public property exampleText: string read get_exampleText write set_exampleText;

// WebPart Methods
procedure Example_WebPart.Render(writer: HtmlTextWriter);
begin
writer.Write(self._exampleText)
end;

end;
[/Delphi]

Method 2: Render Out Literal Control in CreateChildControls and Call RenderChildern

[Delphi]
unit  Example_WebPart;
interface
type
public Example_WebPart = class(WebPart)

// WebPart Fields
strict private _exampleText: string;

// WebPart Properties
[Category(‘Example Properties’), Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDescription(‘Adam”s Example Text’), WebDisplayName(‘Adam”s Example Text For Output’)]
public property exampleText: string read get_exampleText write set_exampleText;

// WebPart Methods
procedure Example_WebPart.CreateChildControls;
begin
inherited CreateChildControls;
self.Controls.Add(LiteralControl.Create(self._exampleText))
end;

procedure Example_WebPart.Render(writer: HtmlTextWriter);
begin
self.RenderChildren(writer)
end;

end;
[/Delphi]

Once you have your WebPart compiled into an executable binary, you can exploit 4 other files to deploy and manage your new WebPart: a .WebPart file, a solution manifest, a Feature file, and an elementManifest file.

The first XML file that you will use to deploy your WebPart is the WebPart file which provides all the descriptive elements relating to your WebPart:

[XML]




Cannot import Example_WebPart Web Part.

Example_WebPart


[/xml]

The next two files are the Feature.xml file and the elementManifest.xml file. This will be used to deploy the WebPart as a SharePoint feature. You will see that in the Feature.XML file, the elementManfiest.xml file as well as the .webpart file are both referenced within the ElementManifest element.

Feature.XML

  1. <Feature  Title="Example_WebPart" Id="6fde9076-989e-4acc-9b3d-ad5364f4d2c0" Description="" Version="1.0.0.0" Scope="Site" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">
  2. <ElementManifests>
  3. <ElementManifest Location="elementManifest.xml" />
  4. <ElementFile Location="Example_WebPart.webpart" />
  5. </ElementManifests>
  6. </Feature>

elementManifest.XML

  1. <Elements  xmlns="http://schemas.microsoft.com/sharepoint/">
  2. <Module Name="WebParts" List="113" Url="_catalogs/wp" >
  3. <File Url="Example_WebPart.webpart" Type="GhostableInLibrary" />
  4. </Module>
  5. </Elements>

The last file to consider is the solution manifest, which allows you to wrap your SharePoint WebPart within a deployable SharePoint solution file. The SharePoint solution file will reference objects such as your SharePoint feature and the executing assemblies that should be included with your WebPart deployment.

  1. <Solution SolutionId="4062e5bb-4492-492d-a41d-2fbe5eb7e41b" xmlns="http://schemas.microsoft.com/sharepoint/" >
  2. <FeatureManifests>
  3. <FeatureManifest Location="Example_WebPart_6fde9076-989e-4acc-9b3d-ad5364f4d2c0\feature.xml" />
  4. </FeatureManifests>
  5. <Assemblies>
  6. <Assembly Location="Example.dll" DeploymentTarget="GlobalAssemblyCache" >
  7. <SafeControls>
  8. <SafeControl Assembly="Example, Version=1.0.0.0, Culture=neutral, PublicKeyToken=your_key_if_assembly_is_strongly_named_(signed)" Namespace="Example_WebPart" TypeName="Example_WebPart" Safe="True" />
  9. </SafeControls>
  10. </Assembly>
  11. </Assemblies>
  12. </Solution>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>