SP Dev part 1 : Sharepoint 2007 Development model {Features}

Sharepoint A new feature in the Sharepoint 2007 is the "Feature" development style which means that every tiny and huge development task in the sharepoint is considered a "Feature".

Features can be activated or deactivated through a site administrator, which enables the very simple turn on/off of anything in the site.

Features are used for developing anything starting from a small button to a full site definition and tons of files and functions including webparts, workflows, lists, pages, content types, document libraries and others. I will try to include the development of all these topics in this series wish me luck and provide feedback. [more]

For a start I will show here in this part how to get started with the feature development and the basic elements and files needed for a developing and deploying a sharepoint feature.

Before opening the Visual Studio and starting to code, knowing what the files and where will they be deployed on the server will be mandatory. A very basic feature will include 2 xml files one named feature.xml and the other will hold the elements of this feature usually named elements.xml or elementsManifest.xml, consider that the files for any feature must be deployed in their own special directory inside the WSS system directory named FEATURES. The FEATURES directory is located inside another WSS system directory named TEMPLATE.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

In our Hello sharepoint feature we will make a very basic feature named HelloSharepoint that when activated will add menu item in the SiteActions menu that will redirect to google.

Feature.xml

<Feature
Id="{INSERT-GUID-HERE}"
Title="Hello Sharepoint Feature"
Description="This is a custom feature which adds a custom item to link to google"
Scope="Web"
Hidden="FALSE"
ImageUrl="google.gif"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ElementsManifest.xml" />
</ElementManifests>
</Feature>

As shown above the feature.xml looks very simple, only Id and Scope are the two required attributes and all the others are optional and a full list can be found here.

ElementsManifest.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="SiteActionsToolbar"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Title="Hello Sharepoint"
Sequence="100"
Description="A custom menu item links to google"
ImageUrl="_layouts/images/google.gif" >
<UrlAction Url="http://www.google.com"/>
</CustomAction>
</Elements>

And the elementsManifest.xml here describes the elements to be installed with the feature and we only define one element (a CustomAction) you find a bunch of types of elements to be added here.

That's all we are done with building our very first feature inside the WSS/MOSS world, I know some of the attributes here seem vague and other seem simple anyway I will try to put a part or two for only discussing these files with their various options.

 

Deploying the feature

 

  1. Copying the feature files (feature.xml and elementsManifest.xml) in the Features server path
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES , and the google.gif in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\images
  2. Running STSADM.EXE operation to install the feature with WSS/MOSS "stsadm -o InstallFeature -filename HelloSharepoint\feature.xml -force"
  3. Restarting IIS
  4. Finally, activating the features within the site administration

SPpart1.zip (6.74 kb)

Posted in Sharepoint | 1 Comment

Upgraded to BlogEngine 1.4.5

Finally working with fully featured BlogEngine on godaddy the BlogEngine v 1.4.5 has been released and I had the time to update my blog, and finally works as a charm with godaddy shared hosting.

Some features that didn't work with the 1.4 version was the whole new widget system, Profiles and anything that used the BinaryFormatter at the end, which needed a high or full trust while godaddy shared hosting only allows meduim trust.

In version 1.4.5 Mads and the team removed all the BinaryFormatters references and used normal xml serializers save the widget and extension settings.

For all blogengine users using shared hosting, go ahead v 1.4.5 works out of the box, and also check the new features released in the latest version.

Posted in BlogEngineDotNet | 2 Comments

Beginning Sharepoint 2007 Development

I mentioned a long while ago that I will work on some sharepoint and workflow foundation in order to enlarge my development knowledge base, I learned some stuff on the way may be all sharepoint and workflows beginners already know them but I love to share them for others.

I will start another series for sharepoint development (for beginners as myself) so If anyone out there finds out a better approach for anything I write or correction welcome for commenting on the posts so all can benefit too.

This series will start with introductory posts that are needed to understand the architecture and object model of sharepoint, these introduction points are all over the web and blogs of sharepoint pros, I will write them again in my wa, then proceed with some basic development then advanced, I don't have an outline for the posts I am gonna write I have some ideas any reader is welcome to add in comments any topic related to sharepoint development wants me to write about, hoping this series be useful like my older one Design Time Support of Custom Controls, so wish me luck.

 

Posted in Sharepoint | 1 Comment

Have been tagged

This blog has been idle for some while, I was very busy, out of mood, studying for my masters and reading new technologies (for me like workflow and sharepoint development and some WCF). I didn't know what time my blogging mood will be back, until my friend Moses insisted to get me back and tagged me in the how I got started in software development, that started a while ago by Michel Eaton. So here we go.

How old were you when you started programming?

10 years old (12 years ago).

How did you get started in programming?

My father used to make simple programs using C that showed dots and stuff I dont get till now Smile, he used to let me write for him some code. Few years more my sister joined computer science and had assignments to program C++ application thats when I really got involved and started to read.(16 years old)

What was your first language?

By that time it was C. 

What was the first real program you wrote? 

My very first own program I wrote was the famous star pyramid using C++, My first windows application and favourite is the MineSweeper, which is my helloworld application that I used for many languages, I used to have the following minesweeper versions (WinForms, WPF, Assembly, Silverlight, OpenGL, DirectX, javascript).

What languages have you used since you started programming?

C, C++, VisualBasic.Net, C#, Java, Assembly, Prolog, Javascript, HTML/XHTML, XAML and lot of other technologies related to development not considered programming language.

What was your first professional programming gig?

Was 4 years ago, I used C# for building winforms applications connecting to databases in my summer training that time.

If you knew then what you know now, would you have started programming? 

OfCourse. I code with passion, love blogging and exploring new technologies around the block. I could have never imagined myself anything other than what am I in now.

What is the one thing you would tell new developers?

Code for fun not for money. Have a life. Don't forget to lie to girls &  Buy your RayBan as Mads said I already got mineCool thank you Mads.

What's the most fun you've ever had … programming?

Building my very first Minesweeper and talking about it to my very best friend that time.

Now what ..?

First, I'd like to thank my friend Moses for not only tagging me but for making me get back to the blogging mood, I hope to continue blogging regularly like old days.

Second, I'd like to pass this to my favourite bloggers, most of them already have been tagged, I recommend you reading them too, Dave, Matt, Mads, Moses, Joe and Keyvan. And now I tag Bashmohandes to write his story.

Anyone reading this and wants to write about his story just head straight to Michel's post and write him a comment.

Posted in My Site | 2 Comments

Moving to Sharepoint and Workflow

My blog has been quiet for a long time now, I had a crowded month I didn't get the time to write anything but I am back to writing I hope so.

Last month I had some working tasks on new technologies (for me) , a new course to study for and of course all my PreMasters studies in my university.

So, I think my focus next blog post will be on the new stuff I learned about Sharepoint 2007 and workflow foundation hope I can write something useful.

By the way I have just passed the 70-631 Exam TS: Configuring Windows SharePoint Services 3.0. So I have a new MCTS in my transcript.

Posted in Uncategorized | 4 Comments

Yet another BlogEngine.NET feature that I love

A while ago, Al Nyveldt wrote a post on 5 things he loves about BlogEngine.Net  and I totally agree with him on all the 5 and more coming in the future releases,  Mads Kristensen too wrote and made a video on a the widget framework on a nice feature coming up in the next version of blogengine.net.

BlogEngine.Net is built to take advantage of standards, one standard I loved that is implemented in BlogEngine is the OpenSearch 
standard.[more]

The cool thing about this standard is that modern browsers are able to detect it and have the option to add the search through the blog.

Internet explorer 7  firefox 2

The opensearch standard is an xml document written in a special format you can see mine here.

And when I search through the browser I am sent to this :

search

So to implement opensearch in your site, (should have something to search in) you need to do these 2 steps.

  1. Build an opensearch format xml file.
  2. Attach the file from your homepage using the appropriate tag in the head section, like the following.
<link title="Amr Elsehemy's Weblog" type="application/opensearchdescription+xml" 
href="http://www.amrelsehemy/opensearch.axd" rel="search"/>

Thats All.

Posted in BlogEngineDotNet | 5 Comments

ASP.NET Security : 2- More Basics

In my previous post I showed that ASP.NET application goes through 3 security context levels and discussed the first one :

  1. IIS Level
  2. ASP.NET worker process level
  3. ASP.NET pipeline level

In this post, I will talk a little on ASP.NET worker process level, before starting I would like to point out the development environment we use, the development machines run windows XP and IIS 5.1, the server runs windows server 2003 on IIS 6 of course, so I need to point out the differences. [more]

2- The Worker Process Context :

IIS 5

After IIS authentication, if the request is for ASP.NET (.aspx, .ashx, ….etc. ) the IIS thread sends the request to aspnet_isapi.dll which starts the aspnet_wp worker process. This worker process runs under the ASPNET account. ASPNET account is a local account created when the .NET Framework is installed. ASPNET has minimum privileges to be able to run an ASP.NET application which you can know in this article :
from http://www.microsoft.com/technet…..mspx
You can change the identity from ASPNET to other one using the section in machine.config

	<processModel userName="xxx" password="XXX"/>
	
IIS 6

In IIS 6, the model is changed where the incoming request in first queued to the application pool that the website is hosted in, then the w3wp.exe worker process servers it.
This time rather than the ASPNET account a new one was introduced named NETWORK SERVICE with the same minimum privileges. To change the this account from the IIS manager, the Application Pool properties > Identity Tab as shown in figure, Read More on Application Pools.

iis pool identity

Next in the worker process, one of the pooled threads picks the request. This thread will by default inherit the identity of the worker process itself defined before, this happens when impersonation is disabled, while if it is enabled the thread will take the identity handed by the IIS, shown in the previous post.

To enable impersonation use this section in web.config

<identity impersonate="true"/>

read more about it on How to implement impersonation in an ASP.NET application

Note: If the impersonation is enabled, the worker process account doesn't change, but impersonation is only used with the code executed in the page, where any database access or file access uses the impersonated account.

Next the last security context level is handled the request and executes, next post I will show preliminary information on the ASP.NET pipeline level.

Posted in ASP.NET | Leave a comment

ASP.NET Security : 1- Basics

Lately at SCS I have been assigned to build up the security module and related tasks in the Real Estate Management System we are building. So I decided to share what I have learned in this past period and of course to hear from the community to find optimal solutions for the scenarios I worked with, all what I write here might be repeated but I will share it anyway. [more]

In this part, I will show some important basic points that should be clear to everyone before implementing asp.net security tasks.

Looking at any web application, the security is a matter of users/passwords/roles/groups… etc. While ASP.NET provides more mechanisms for authentication and authorization that work with the Operating system,IIS and .NET framework classes. So the ASP.NET application runs through these 3 levels.

  • IIS Level
  • ASP.NET worker process level
  • ASP.NET pipeline level

So, the Big Question, What is the Identity that runs my application ?

First, When an IIS web server machine receives an ASP.NET request, the IIS assigns it to one of the threads pooled in it, IIS runs under the SYSTEM account which has all the powers in a Microsoft Windows operating system. You can read extra information in the ASP.NET Application Life Cycle Overview article on the msdn.

Next, the 3 security levels run on the request one after the other.

1- The IIS thread context : the identity of this thread is determined according to the settings of the website in the IIS which has one of the following settings:

  1. Basic authentication prompts the user for a user name and a password, also called credentials, which are sent unencrypted over the network.
  2. Integrated Windows authentication uses hashing technology to scramble user names and password before sending them over the network.
  3. Digest authentication operates much like Basic authentication, except that passwords are sent across the network as a hash value. Digest authentication is only available on domains with domain controllers running Windows Server operating systems.
  4. Anonymous authentication allows everyone access to the public areas of the Web sites, without asking for a user name or password. When this is set, the identity impersonates the identity set in the textboxes, with the default user name IUSR_MACHINENAME. Like shown in the figure down below.

Further more, IIS provides SSL (Secure Socket Layer) authentication mode that is based on certificates, to authenticate users requesting/providing secret information on the server, two trusted certificate providers (which I know but never used) are http://www.thawte.com/ and http://www.verisign.com/.

AuthenticationMethods IIS 5

After authentication, the thread sends the request to the appropriate external module.

Next part I will talk about the 2 next security level contexts.

Posted in ASP.NET | 4 Comments

Exploring GDI+ : Using the Pen

In my tour in exploring GDI+ I explored the Brush object, now its time for some Pen stuff.

While the Brush classes are used to fill shapes, the Pen class is used to frame shapes. However, Pens are not only used for simple frames. Here in this post I show some advanced uses for the Pen. [more]

Some interesting members are :

sealed class Pen : MarshalByRefObject, ICloneable,  IDisposable 
{  
// Constructors
public Pen(Brush brush);
public Pen(Brush brush, float width);
public Pen(Color color);
public Pen(Color color, float width);
// Properties
public Color Color { get; set; }
public CustomLineCap CustomEndCap { get; set; }
public CustomLineCap CustomStartCap { get; set; }
public DashCap DashCap { get; set; }
public float DashOffset { get; set; }
public float[] DashPattern { get; set; }
public DashStyle DashStyle { get; set; }
public LineCap EndCap { get; set; }
public LineJoin LineJoin { get; set; }
public LineCap StartCap { get; set; }
public float Width { get; set;
}
//Other members removed here.}

As you can see, the pen can be instantiated with a Color or with a defined Brush that means the pen can be one of the Brush TypesI previously wrote about.

In addition to their brushlike behavior, pens have behavior at starting and ending along their length that brushes don’t have. For example, each end can have a different style, as determined by the LineCap enumeration shown next.

Line Caps

1

You can set different LineCaps for pens in the StartCap and EndCap properties of the Pen, there are predefined caps and custom caps are allowed too.

        private void RenderPens1(Graphics g)
{
using (Pen p = new Pen(Color.Black, 10))
{
p.EndCap = LineCap.ArrowAnchor;
g.DrawLine(p, new Point(10, 20), new Point(300, 20));
//other pens
p.EndCap = LineCap.Custom;
// width and height of 3 and unfilled arrow head
p.CustomEndCap = new AdjustableArrowCap(3, 3, false);
g.DrawLine(p, new Point(10, 260), new Point(300, 260));
}

Dashes

In addition to the ends having special styles the starts can have as well, further more a line can have a dash style, as defined by the DashStyle enumeration.

Dash Style of Pen

        private void RenderPens2(Graphics g)
{
using (Pen p = new Pen(Color.Black, 10))
{ p.DashStyle = DashStyle.Dash;
g.DrawLine(p, new Point(10, 20), new Point(300, 20));
//other DashStyles
p.DashStyle = DashStyle.Custom;
p.DashPattern = new float[] { 1f, .5f, 2f, .5f, 3f, .5f, 4f };
g.DrawLine(p, new Point(10, 170), new Point(300, 170)); } }

As you can notice in the members of the Pen, the DashCap property which also accepts a LineCap enumeration, so you can take more control over the line that appears.
Thats all for this part. Happy Coding.

PensForm.cs (2.86 kb)


							
Posted in GDI + | 3 Comments

Enabling Design Time Template Editing

Few days ago, I blogged about how to enable auto formats in the design time smart tag by overriding simple property, this post will describe how to enable design time template editing in a similar simple way.

Template Editing 

[more]

The following steps will show how to do this in your template controls, assuming you already have a template control ( template controls are web server controls that have one or many properties of type ITemplate ).

So, this is how it works :

  1. Implement a custom designer that inherits from System.Web.UI.Design.ControlDesigner
  2. Override the TemplateGroups Collection.
  3. In the get define your template group collection and return it.
  4. Don't forget to enable TemplateEditing flag.

The Sample I introduce here contains a template control having 4 templates which I divide them into 2 template groups.

The SampleControl

[ToolboxData("<{0}:SampleControl runat=server></{0}:SampleControl>")]
[Designer(typeof(SampleControlDesigner))]
public class SampleControl : TemplateControl
{
private ITemplate _firstTemplateX;
 private ITemplate _firstTemplateY;
 private ITemplate _secondTemplateX;
 private ITemplate _secondTemplateY;
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate FirstTemplateX
{
 get { return _firstTemplateX; }
 set { _firstTemplateX = value;
}
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate FirstTemplateY
{
 get { return _firstTemplateY; }
 set { _firstTemplateY = value; }
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate SecondTemplateX
{
 get { return _secondTemplateX; }
 set { _secondTemplateX = value; }
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate SecondTemplateY
{
 get { return _secondTemplateY; }
 set { _secondTemplateY = value; }
}
}

The Control Desginer

class SampleControlDesigner : ControlDesigner
{
 public override void Initialize(IComponent component)
 {
base.Initialize(component);
  SetViewFlags(ViewFlags.TemplateEditing, true);
 }
 private TemplateGroupCollection _templateGroups;
 public override TemplateGroupCollection TemplateGroups
 {
  get{
  if (_templateGroups == null)
  {
   _templateGroups = new TemplateGroupCollection();
   TemplateGroup tempGroup1, tempGroup2;
   TemplateDefinition tempDef1, tempDef2, tempDef3, tempDef4;
   SampleControl ctl;
   ctl = (SampleControl)this.Component;
   tempGroup1 = new TemplateGroup("FirstTemplateGroup");
   tempGroup2 = new TemplateGroup("SecondTemplateGroup");
   tempDef1 = new TemplateDefinition(this, "TemplateX", ctl, "FirstTemplateX", true);
   tempDef2 = new TemplateDefinition(this, "TemplateY", ctl, "FirstTemplateY", true);
   tempDef3 = new TemplateDefinition(this, "TemplateX", ctl, "SecondTemplateX", true);
   tempDef4 = new TemplateDefinition(this, "TemplateY", ctl, "SecondTemplateY", true);
   tempGroup1.AddTemplateDefinition(tempDef1);
   tempGroup1.AddTemplateDefinition(tempDef2);
   tempGroup2.AddTemplateDefinition(tempDef3);
   tempGroup2.AddTemplateDefinition(tempDef4);
   _templateGroups.Add(tempGroup1);
   _templateGroups.Add(tempGroup2);
  }
  return _templateGroups;
 }
}
}

The final output of the sample looks like this

Final output of sample

Here's the code so have fun.

SampleControl.cs (3.32 kb)

Posted in Design Time Support | 1 Comment