One can create Parent / Child (A.K.A. Master / Detail) relationships in SharePoint 2007 by using lookups to reference a parent list from a child list. I will discuss another way of creating a Parent / Child relationship by adding a content type inside a folder.
We will create a parent / child relationship between company and employees. Here are our sample entities:
Company Parent (CompanyId, CompanyName)
Employee Child (Name, EmployeeId, Branch)
The strategy will be to make the "Company Parent" entity a folder which contains "Employee Child" items. To accomplish this we will create two new content types for each entity.
The "Company Parent" content type:
1) Site Actions ==> Site Settings ==> Site Content Types
2) Create
• Name: Company Parent
• Select parent content type from: Folder Content Types
• Parent Content Type: Folder
• Existing group: Custom Content Types
• Click OK
3) Click on "Add from new site column" on the "Site Content Type: …" page under column.
• Column name: CompanyId of type Number
• Click OK
NOTE: We will reuse the "Title" field to be the CompanyName.
The "Employee Child" content type:
1) Site Actions ==> Site Settings ==> Site Content Types
2) Create
• Name: Employee Child
• Select parent content type from: List Content Types
• Parent Content Type: Item
• Existing group: Custom Content Types
• Click OK
3) Click on "Add from new site column" on the "Site Content Type: …" page under column.
• Column name: EmployeeId of type Number
• Click OK
4) Click on "Add from new site column" on the "Site Content Type: …" page under column.
• Column name: Branch of type "Single line of text"
• Click OK
NOTE: We will reuse the "Title" field to be the EmployeeName.
Now we can go about our normal business of creating a custom list and using our two newly created content types "Company Parent" and "Employee Child".
1) Site Settings ==> Create
2) Click on "Custom List" under the "Custom Lists" column.
• Name: CompanyEmployees
• Click OK
3) Settings ==-> List Settings
4) Click on "Advanced Settings" under the "General Settings" column
5) At the very top, change Allow management of content types?" to Yes.
6) Click on OK
7) Under "Content Types" click on "Add from existing site content types".
8) On the "Add Content Types:" page
• Select site content types from: Custom Content Types
• Add "Company Parent" and "Employee Child" content types.
• Click on OK
Let’s add some dummy data.
1. Click on the "CompanyEmployees" list
2. Click on the little arrow beside New. You should see this:
3. Select "Company Parent"
4. Add the following bogus company data:
• Name: ACME Corporation; CompanyId: 123
• Name: Bogus Enterprises: CompanyId: 456
5. Add bogus company employees to "ACME Corporation"
• Click on "ACME Corporation". This causes the folder to open.
• Add the following employees to the ACME Corporation by clicking on New ==-> Employee Child:
• Title: Jane Doe; EmployeeId: 111; Branch: Downtown
• Title: James White; EmployeeId: 222; Branch: Airport
• Click on "Bogus Enterprises". This causes the folder to open.
• Add the following employees to Bogus Enterprises by clicking on New ==-> Employee Child:
• Title: Judy Black; EmployeeId: 333; Branch: Main Street
• Title: Brandon Wiley; EmployeeId: 333; Branch: Riverside
• Add another employee to ACME:
This concludes configuration and data entry. Let us now use the SharePoint 2007 Object Model to get at this data.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
public class CompanyEmployees {
static void Main(string[] args) {
SPSite site = new SPSite("http://srvr/");
SPWeb web = site.AllWebs["/"];
SPList list = web.Lists["CompanyEmployees"];
foreach (SPListItem order in list.Folders) {
Console.WriteLine("Company ID : {0}", order["CompanyId"]);
Console.WriteLine("Company Name : {0}", order["Title"]);
SPQuery empItemsQuery = new SPQuery();
empItemsQuery.Folder = order.Folder;
SPListItemCollection empItems = list.GetItems(empItemsQuery);
foreach (SPListItem empItem in empItems) {
Console.WriteLine("\tEmployee ID {0}: {1} {2}",
empItem["EmployeeId"],
empItem["Title"],
empItem["Branch"]);
}
}
}
}
The above application will produce the following result:
Company ID : 123
Company Name : ACME Corporation
Employee ID 111: Jane Doe Downtown
Employee ID 222: James White Airport
Company ID : 456
Company Name : Bogus Enterprises
Employee ID 333: Judy Black Main Street
Employee ID 444: Brandon Wiley Riverside
Tuesday, October 30, 2007
Saturday, October 27, 2007
COMP-1536 & ACIT-1620 Fall 2007 week 09
Medhat Elmasry will be away attending a training course in downtown Vancouver. Here are some important notes on week 09:
Notes for COMP-1536 students
Notes for ACIT-1620 students
- Jason Harrison will be delivering the lectures on Tuesday October 30, 2007 at 10:30 AM and Friday November 2, 2007 at 12:30 PM. He will be introducing you to PHP.
- Medhat will not be present at the SET 1A lab on Monday October 29, 2007 at 1:30 PM. Students are expected to come to the lab session and use the time to work on assignment 3.
- Sets 1B, 1C, 1D, and 1E must attend labs with Jason Harrison as usual.
- You can post any questions as comments on my blog.
- There will be no lecture on Monday October 29, 2007 at 10:30 AM. Instead, Medhat will makeup this lecture in the labs during the following week.
- Brian Pidcock will be delivering the lecture on Friday November 2, 2007 at 1:30 PM on the topic of JavaScript functions.
- Medhat will not be present at SET 1A and SET 1B labs on Monday October 29, 2007 at 3:30 PM and Tuesday October 30, 2007 at 8:30 AM respectively. Students are expected to come to the lab session and use the time to work on assignment 3.
- You can post any questions as comments on my blog
Thursday, October 18, 2007
Creating "Calculated Field" columns in SharePoint 2007
You can pretty much use the same VBA syntax for calculated fields as in Excel. Here is a site that provides many examples of common formulas that can be used in SharePoint when defining "Calculated Field" columns.
Here is a formula that I created at work:
=IF(YEAR([Due Date])=1899,"No Due Date",TEXT([Due Date],"MM/dd/yyyy"))
Blank dates in SharePoint are assigned a date in year 1899. The above formula displays a message "No Due Date" for invalid dates or the valid date using format MM/dd/yyyy.
Here is a formula that I created at work:
=IF(YEAR([Due Date])=1899,"No Due Date",TEXT([Due Date],"MM/dd/yyyy"))
Blank dates in SharePoint are assigned a date in year 1899. The above formula displays a message "No Due Date" for invalid dates or the valid date using format MM/dd/yyyy.
Sunday, October 14, 2007
Speaking at DevTeach in late November 2007
I am scheduled to speak at the DevTeach conference in Vancouver on Wednesday, November 28, 2007 from 11:00 AM to 12:15 PM. The topic I will be presenting is the same topic I gave to the .netBC group on Wednesday September 12, 2007. That presention took 2 hours. Therefore, I must shave off about 45 minutes from that presentation.
The DevTeach conference is moving outside of Montreal for the first time. I attended it twice in spring 2005 and spring 2007. It is definately a very worthwhile conference. If you want to be on top of current and up-coming technologies in our very fast moving profession, it is a good use of three days.
Jean-Rene Roy, who is the owner of the DevTeach & SQLTeach shows, is organizing a very different type of conference in Vancouver. New to Vancouver will be an XNA track, a Halo-3 competition, and a free beer party with Palermo. It looks like it is going to be a lot of fun. Here is more on the various activities:
XNA contest: http://www.devteach.com/contest.aspx
Party with Palermo! Free beer: http://www.partywithpalermo.com/
For the first time a XNA track at a independent conference: http://www.devteach.com/Session.aspx#79
Three very good Pre-con Post-Con:
http://www.devteach.com/PreConference.aspx
http://www.devteach.com/PostConference.aspx
Key note by Ken Levy on VSX: http://www.devteach.com/Keynote.aspx
The DevTeach conference is moving outside of Montreal for the first time. I attended it twice in spring 2005 and spring 2007. It is definately a very worthwhile conference. If you want to be on top of current and up-coming technologies in our very fast moving profession, it is a good use of three days.
Jean-Rene Roy, who is the owner of the DevTeach & SQLTeach shows, is organizing a very different type of conference in Vancouver. New to Vancouver will be an XNA track, a Halo-3 competition, and a free beer party with Palermo. It looks like it is going to be a lot of fun. Here is more on the various activities:
XNA contest: http://www.devteach.com/contest.aspx
Party with Palermo! Free beer: http://www.partywithpalermo.com/
For the first time a XNA track at a independent conference: http://www.devteach.com/Session.aspx#79
Three very good Pre-con Post-Con:
http://www.devteach.com/PreConference.aspx
http://www.devteach.com/PostConference.aspx
Key note by Ken Levy on VSX: http://www.devteach.com/Keynote.aspx
How to hide "View All Site Content" link for anonymous users in SharePoint WSS 3.0?
This solution requires you to install Microsoft Office SharePoint Designer.
<div class="ms-quicklaunchheader">
<SharePoint:SPLinkButton id="idNavLinkViewAll" runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" Text="<%$Resources:wss,quiklnch_allcontent%>" AccessKey="<%$Resources:wss,quiklnch_allcontent_AK%>"/>
</div>
</SharePoint:SPSecurityTrimmedControl>
- Go to "Site Actions" ==> "Site Settings"
- Under Galleries, click on "Master Pages"
- Select default.master and select "Edit in Microsoft Office SharePoint Designer".
- In "Design" view locate "View All Site Content" on the left-hand-site navigation bar and click on it.
- Go to "Code" view. You will see the following code highlighted:
<div class="ms-quicklaunchheader">
<SharePoint:SPLinkButton id="idNavLinkViewAll" runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" Text="<%$Resources:wss,quiklnch_allcontent%>" AccessKey="<%$Resources:wss,quiklnch_allcontent_AK%>"/>
</div>
- Change the PermissionString attribute value of the Sharepoint:SPSecurityTrimmedControl XML element from ViewFormPages to BrowseDirectories.
- Save the default.master. If you login as an anonymous user you will not see the "View All Site Content" link. However when authenticated you will see this option.
Tuesday, October 9, 2007
Adding command prompt option to Windows Explorer in Windows 2003 server
1. Navigate in your Registry to
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called "Command Prompt" without the quotes.
2. Set the default string to whatever text you want to appear in the right-click menu
3. Create a new key within your newly created command prompt named "command" and set the default string to:
Cmd.exe /k pushd %L
4. The changes should take place immediately. Right click a folder and your new menu item should appear.
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called "Command Prompt" without the quotes.
2. Set the default string to whatever text you want to appear in the right-click menu
3. Create a new key within your newly created command prompt named "command" and set the default string to:
Cmd.exe /k pushd %L
4. The changes should take place immediately. Right click a folder and your new menu item should appear.
Friday, October 5, 2007
Making a SharePoint custom column visible in an edit list form
- Go to the list you are interested in
- Click Settings --> List Settings
- Under General Settings --> Click Advance Settings
- Click "Yes" for "Allow management of content types?"
- Click "OK"
- Click the list you are interested in under "Content Types"
- Now Click "Add from existing site or list columns"
- Click "Add >" to select the columns you want
- Click "OK"
- Go to the list you are interested in
- Click Settings --> List Settings
- Under General Settings --> Click Advance Settings
- Click "No" for "Allow management of content types?"
Thursday, October 4, 2007
How to get list and view GUIDs in WSS 3.0 or MOSS 2007?
List GUID
- Access the list with your browser
- Go to Settings->List Settings
- Copy the URL from your browser address line into a text editor. It should look something like this: http://something.com/_layouts/listedit.aspx?List=%7BB2FD569F%2D89B3%2D4150%2DA9BA%2D1D7F5F9437AA%7D
- Delete everything upto (and including) List=
- Replace %7B with {
- Replace %7D with }
- Replace %2D with -
- In the above example, the GUID would be {B2FD569F-89B3-4150-A9BA-1D7F5F9437AA}
View GUID
- Access the list with your browser
- Go to Settings->List Settings
- Copy the URL from your browser address line into a text editor. It should look something like this: http://something.com/_layouts/ViewEdit.aspx?List=%7BB2FD569F%2D89B3%2D4150%2DA9BA%2D1D7F5F9437AA%7D&View=%7B6E1DB03C%2D9083%2D45FD%2D9487%2DDCF420E4F245%7D&Source=%252Foperations%252Fskutracker%252F%255Flayouts%252Flistedit%252Easpx%253FList%253D%25257BB2FD569F%25252D89B3%25252D4150%25252DA9BA%25252D1D7F5F9437AA%25257D
- Copy the data between View= and &Source
- Perform the same replacements as explained for List GUIDs above
Wednesday, October 3, 2007
Finding out the SharePoint list ID (ListTemplateId)
SharePoint 2007 offers an enhanced ability to catch certain user events such as ItemDeleting (before the fact) and ItemDeleted (after the fact). The API targets specific lists identified by list IDs. Example:
You can find out the list ID of any other list as follows:
List template type | Template ID |
Custom List | 100 |
Document Library | 101 |
Survey | 102 |
Links List | 103 |
Announcement List | 104 |
Contacts List | 105 |
Events List | 106 |
Task List | 107 |
Discussion Board | 108 |
Picture Library | 109 |
- Go to your 12 hives FEATURES folder C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
- Find the folder for the list you are interested in and open it.
- Open the ListTemplates folder
- Open the XML file and read the value of the Type attribute.
- This information can also be found in the ONET.XML file in the appropriate site template directory under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates
Subscribe to:
Posts (Atom)