A SharePoint Site "CON" Returns "An unexpected error has occurred."


I tried to create a SharePoint site for contact records with CON as a site name, i.e. http://[server]/sites/CON. A site returned "An unexpected error has occurred." After contacting Microsoft product support service team, I found out that it is a product issue -- You can call it a bug or a feature by design.


This is a response from Microsoft product support service:
"MS-DOS device names are reserved words and cannot be used as folder or file names. When parsing a reference to a file or folder, Windows checks for the case in which a single MS-DOS device name is used in the path, and treats it as invalid."


The support team also provided this KB article - http://support.microsoft.com/kb/71843.


The following words are reserved in MS-DOS. You will not be able to use the following words as a sub site name or folder name:

CON, COM1 - COM4, PRN, AUX, LPT1

author: Jason Huh | posted @ Saturday, October 11, 2008 5:19 PM | Feedback (0)

How to Update Created, Created By, Modified and Modified By field?


I stumbled upon this Technet Forum post. Using the SPListItem.UpdateOverwriteVersion method, you can overwrite Created, Created By, Modified and Modified By fields. Here is a code snippet from this MSDN article:


      using (SPSite sps = new SPSite("http://server/"))

{
using (SPWeb spw = sps.OpenWeb())
{
SPList spSharedDocs = spw.Lists["Shared Documents"];
SPListItem spli = spSharedDocs.Items[0];
spli["Created"] = new DateTime(2007, 1, 1);
spli["Author"] = "-1;#domain\\user";
spli["Editor"] = "-1;#domain\\user";
spli["Modified"] = new DateTime(2007, 2, 1);
spli.UpdateOverwriteVersion();
}
}

author: Jason Huh | posted @ Wednesday, September 10, 2008 12:00 AM | Feedback (0)

How to Create a Login/Registration System Using FBA with Active Directory in a SharePoint Server 2007


To use the forms based authentication(FBA) against an Active Directory(AD) for a SharePoint Server 2007, you will need to use the ActiveDirectoryMembershipProvider in ASP.NET 2.0. I outlined key steps to enable FBA against an AD for a SharePoint Server 2007.

Step 1 - Edit the AD Schema
To suppport Password Reset (Password Recovery), you will need to edit the AD schema by running the following command: regsvr32.exe schmmgmt.dll. The detailed step to edit the AD is defined in Password Reset section of this article.

Step 2 - Set up Intranet and Extranet Zone
Once the AD schema has been edited, you will need to set up a SharePoint Site with Intranet and Extranet Zones. Here is a quick how-to:

2.1. Create the Web Application for the Extranet Zone
  1. On your SharePoint server, open up SharePoint Central Administration
  2. Click on the Application Management tab
  3. Click Create or Extend Web Application
  4. Click Create a new Web application
  5. Fill out the fields as appropriate for your web application and click OK
  6. After the operation completes, open up a command prompt and run iisreset /noforce command
  7. On the Application Created page, clik on the Create Site Collection link
  8. Fill out the fields as appropriate for your site collection and click OK
  9. After the operation completes, on the Application Management tab, click Authentication providers
  10. Make sure your newly-created web application is selected and click on the Default zone
  11. Select Forms as the Authentication Type
  12. Check the Enable anonymous access checkbox
  13. Type in the name of your membership provider name (i.e. PortalMembershipProvider) in the Membership provider name textbox
  14. Type in the name of your role manager name (i.e. PortalRoleManager) in the Role manager name textbox
  15. Select No for Enable Client Integration
  16. Click Save

2.2. Extend the Web Application to the Intranet Zone

  1. On your SharePoint server, open up SharePoint Central Administration
  2. Click on the Application Management tab
  3. Click Create or Extend Web Application
  4. Click Extend and existing web application
  5. Select your newly-created web application in the Web Application dropdown
  6. Fill out the fields are appropriate for your web application
  7. Select Intranet from the Zone dropdown
  8. Click OK
  9. Click on Authentication providers
  10. Click Intranet zone
  11. Make sure the Authentication Type is set to Windows
  12. Make sure Enable anonymous access is unchecked
  13. Click Save
Step 3 - Create Roles with AzMan

Windows Authorization Manager (AzMan) is a Windows tool for defining application roles and mapping them to Windows users/AD groups defined in your AD store. This article explains in details how to create roles with AzMan. I recommend to configure an AzMan policty store in an an xml file for quick development. For a test, staging and production environment, I recommend to configure an AzMan policy store in AD.

Step 4 - Edit SharePoint Web.config Files

You will need to mofidy the following three web.config files:

  • Exranet web.config
  • Intranet web.config
  • SharePoint Central Administration web.config.
Each web.config file needs to have different modifications made to it, depending on what each web application needs to be configured for.

4.1 Extranet web.config

The extranet web.config needs four modifications made to it: changes must be made to the <connectionstrings>, <membership>, <rolemanager>, and <authentication> sections.<connectionstrings><membership><rolemanager><authentication>
</authentication></rolemanager></membership></connectionstrings>

4.1.1 Connection Strings


In order to connect to the AD store for authentication and the AzMan-provided XML file for role definitions, the <connectionstrings> section of the extranet web.config must be modified to include connection string values that point to said resources. The connection string for the AD connection should be an LDAP string to your domain, and the AzMan connection string should be in the format “msxml:// ”.
The <connectionstrings> section is a child of the root <configuration> section.</configuration></connectionstrings></connectionstrings>



<connectionstrings>
<add name="PortalAdConnection" connectionstring="LDAP://portal.test.com ">
<add name="AzManConnection" connectionstring="msxml://c:/Roles/AzManRoles.xml">
</add></add></connectionstrings>



4.1.2 Membership Provider


The <membership> section needs to have a membership provider added to it that specifies that AD will be used as the membership store for the SharePoint portal site.
The <membership> section is under <configuration>/<system.web></system.web></configuration></membership></membership>


<membership defaultprovider="PortalMembershipProvider">
<providers>
<add name="PortalMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionstringname="PortalAdConnection" connectionusername="UserWithAppropriateRights" connectionpassword="PasswordForUser" connectionprotection="Secure" enablepasswordreset="true" enablesearchmethods="true" requiresquestionandanswer="true" applicationname="/" description="Default AD connection" requiresuniqueemail="true" clientsearchtimeout="30" serversearchtimeout="30" attributemappasswordquestion="department" attributemappasswordanswer="division" attributemapfailedpasswordanswercount="singleIntAttribute" attributemapfailedpasswordanswertime="singleLargeIntAttribute" attributemapfailedpasswordanswerlockouttime="singleLargeIntAttribute" attributemapemail="mail" attributemapusername="userPrincipalName" maxinvalidpasswordattemps="20" passwordattemptwindow="20" passwordanswerattemptlockoutduration="30"></add>
</providers></membership>



4.1.3 Login URL


The section needs to have a login URL specified. This will allow the SharePoint web application to know what web form will be used to authenticate the user with. When authenticated users attempt to access a resource they are not authorized for, they will be redirected to the specified login page and asked to sign in as a different user.
The section is under <configuration>/<system.web>/<authentication>

<authentication mode="Forms">
<forms loginurl="/_layouts/Portal/login.aspx">
</forms></authentication></authentication></system.web></configuration></forms></forms>


 


4.2 Intranet web.config


The Intranet web.config needs two modifications made to it: changes need to be made to the <connectionstrings> and <rolemanager> sections.</rolemanager></connectionstrings>


4.2.1 Connection Strings


In order to connect to the AzMan-provided XML file for role definitions, the <connectionstrings> section of the extranet web.config must be modified to include a connection string value that points to said resource. The connection string for the AzMan XML file should be in the format “msxml://<path>”.
The <connectionstrings> section is a child of the root <configuration> section.</configuration></connectionstrings></path></connectionstrings>


<connectionstrings>
<add name="AzManConnection" connectionstring="msxml://c:/Roles/AzManRoles.xml"></add></connectionstrings>



4.2.2 Role Provider


The <rolemanager> section needs to have a role provider added to it that specifies that the AzMan-created XML file will supply roles to the SharePoint web application.
The <rolemanager> section is under <configuration>/<system.web>
</system.web></configuration></rolemanager></rolemanager>


<rolemanager enabled="true" defaultprovider="PortalRoleProvider" cacherolesincookie="true" cookieprotection="All" cookietimeout="10" cookiename=".PortalRole">
<providers>
<clear>
<add connectionstringname="AzMan" applicationname="AzManPortal" name="PortalRoleProvider" type="System.Web.Security.AuthorizationStoreRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, publicKeyToken=b03f5f7f11d50a3a">
</add>
</clear></providers></rolemanager>



4.3 SharePoint Central Administration web.config


The SharePoint Central Administration web.config only needs a modification to the <rolemanager> </rolemanager>


4.3.1 Role Provider


The <rolemanager> section needs to be enabled and have its default provider set to the ASP.NET Windows token provider.
The <rolemanager> section is under <configuration>/<system.web>
<rolemanager enabled="true" defaultprovider="AspNetWindowsTokenProvider">
</rolemanager></system.web></configuration></rolemanager></rolemanager>


Step 5 - Map AzMan Roles to SharePoint Site Groups

Without performing this mapping, you may notice that users can authenticate against the AD store, but will not be authorized to view any restricted SharePoint content not configured for anonymous access. The reason for this is that the SharePoint web application can confirm the username/password combination against AD, but it cannot know the role(s) of the user without them being somehow mapped to security groups within SharePoint.

5.5 Mapping Application Roles to Site Groups

  1. As an administrator of the SharePoint portal site, open up the Intranet home page
  2. Click on Site Actions -> Site Settings
  3. Click on People and groups
  4. Click on one of your SharePoint site groups, i.e. Site Members
  5. Click New
  6. In the Users/Groups multi-line textbox, you should be able to add the roles that you defined with AzMan and successfully perform a check name operation against them.

You finished all the steps necessary to create a login/registration system. Now, using Microsoft Visual Studio, you can create a login, registration, password recovery, etc. by following this article.

 


Summary


In this post, I outlined key steps to create a login/registration system using FBA against AD in a SharePoint Server 2007. I did not necessary go through detailed steps, and refered to other articles instead for further details. Creating a login/registration system in a SharePoint Server 2007 is not a trivial task, but it is certainly possible to do it. Once it is implemented, a SharePoint Server 2007 can act as a great platform for an internet-facing web site or an extranet, supporting all necessary functionalties required for a login and registration process.


Other useful links:

author: Jason Huh | posted @ Tuesday, September 09, 2008 12:00 AM | Feedback (0)

Good SharePoint Server 2007 resources


Performance and Capacity Planning Resource Center for SharePoint Server 2007
This page contains resources to help you with performance and capacity planning for your SharePoint Server deployment—map your solution design to a farm size and set of hardware that supports your business goals.
It contains many technical articles organized By:
  • Planning
  • Recommendations
  • Estimate performance based on test results
  • Demos
  • Tools from Microsoft
  • Tools and Papers from Partners and the Community

Best Practices Resource Center for SharePoint Server 2007
To avoid common pitfalls and keep your Office SharePoint Server 2007 environment available and performing well, follow these best practices based on real-world experience from Microsoft Consulting Services and the product team.
It contains best practices for:
  • Operational Excellence
  • Team Collaboration Sites
  • Publishing Portals
  • Search
  • My Sites
  • Developing Custom Applications
  • Additional Resources

author: Jason Huh | posted @ Monday, September 08, 2008 12:00 AM | Feedback (0)

So you became a team lead? Here are books and podcast I recommend


Becoming a lead means becoming a manager. By definition, a manager is a person who makes things happen through others. A developer lead or team lead can make a project successful only if he can make his team members work effectively. I mentored many newbie leads who felt lost when they began to work as a lead. Here is a list of books that I recommend for young managers and leads:

* Leadership and Self Deception: Getting Out of the Box by The Arbinger Institute - You need to read this book if you ever blamed others or if you feel you work harder than your team members. I think the definition of a bad manager is a manager in the box.
* The Five Dysfunctions of a Team A Leadership Fable by Patrick M Lencioni - This is a best book which explains what the team is. A true team is based on trust and built on conflicts.
* Manager Tools - This is a podcast site. The podcast series guides you to become a good manager. I recommend to use an iTunes to download and listen to all podcasts.

The above three items will be a good starting point, and I am sure you will discover other great books on the course of reading or listening to the above books and podcasts.

author: Jason Huh | posted @ Sunday, September 07, 2008 12:00 AM | Feedback (0)

Microsoft and Cloud computing


Microsoft and Cloud computing

Cloud computing is here to stay. Amazon Elastic Compute Cloud (EC2), Google's recent release of Chrome and its internet-based applications, Salesforce.com, NetSuite, Apple's MobileMe, etc. are good examples of cloud computing services. Wikipedia has a good article on Cloud computing. Microsoft is providing Cloud computing services and executing its own vision of Cloud computing, software plus service(S+S). Here are several examples of Microsoft's S+S:
  • Red Dog: Microsoft is known to be working on a low-level "Cloud OS" that is code-named Red Dog.
  • Zurich: At the highest level, Zurich is Microsoft’s Software+Services platform.
  • Microsoft Volta : In a nutshell, Volta is Microsoft's version of Google Web Toolkit(GWT). GWT uses Java to generate JavaScript. Volta uses .Net language such as C# to generate JavaScript. As of today, Microsoft volta is technology preview (pre-beta).
  • Microsoft Dynamics CRM Online: Microsoft offers a CRM hosting service through Microsoft Dynamics CRM Online.
  • Microsoft SkyDrive - This is a storage in the Clouds. Once you sign up through Windows Live, you get 5GB of free storage.
  • Microsoft Popfly - It is a Microsoft mash-up tool similar to Yahoo's Pipes.

Useful links

author: Jason Huh | posted @ Sunday, September 07, 2008 12:00 AM | Feedback (0)

Sample code acceptance checklist for SharePoint from Microsoft


Microsoft recently released the following article: http://technet.microsoft.com/en-us/library/cc707802.aspx#Section2 It is a sample code acceptance checklist. I think it is a good checklist to start with for assuring the quality of your team's code. Just like any guidance and checklist, you will need to change the checklist by adding or removing checklist items.

author: Jason Huh | posted @ Sunday, August 31, 2008 12:00 AM | Feedback (0)

Useful SharePoint Utility methods


Microsoft.SharePoint.Utilities namespace [1] contains many useful classes such as SPUtility, SPEncode, SPUrlUtility, etc. As you can imagine, these classes contain many useful utility methods which can save developers lots of time as well as many line of code. In this article, I will introduce two methods in the SPUtility class as a starter. Until I update this article later, please take a look at the SharePoint SDK to see what kind of utility classes and methods the Microsoft.SharePoint.Utilities namespace contains.

 

SPUtility Class

Namespace: Microsoft.SharePoint.Utilities
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)

 

 

SPUtility.CreateISO8601DateTimeFromSystemDateTime

Description

Converts a system DateTime value to ISO8601 DateTime format (yyyy-mm-ddThh:mm:ssZ).

 

User Scenario

When you need to use a CAML query against a field with DateTime type, you will need to format a date to be ISO 8601 compliant. SharePoint provides a SPUtility.CreateISO8601DateTimeFromSystemDateTime method which converts a regular System.DateTime object to a datetime string which follows the ISO 8601 format.

 

C# Code Sample

The following code will return all past due items.

 

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Tasks"];

DateTime nextWeek = DateTime.Today.AddDays(-1);

string nextWeekDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(nextWeek);
string querystring = String.Format("<Where><Lt><FieldRef Name=\"DueDate\"/><Value Type=\"DateTime\">{0}</Value></Lt></Where>", nextWeekDate);
SPQuery query = new SPQuery();
query.Query = querystring;
SPListItemCollections items = list.GetItems(query);

 

 

 

SPUtility.SendEmail

Description

Sends an email. The key benefit of using this method instead of using the System.Web.Mail.SmtpMail.SendMail the less maintenance -- Since this API uses an outgoing email setting which is configured on the SharePoint central admin, unlike SmtpMail.SendMail, you don't need to store information of SMTP server in a web.config file. The downside of the SPUtility.SendEmail is that it does not support file attachments to emails. If you need a file attachment functionality, you will need to use the SmtpMail.SendMail method.

User Scenario

This method can be used in a variety of scenarios. You may use this method to notify a user by email when a user changes a user profile in an extranet SharePoint site. You may use this method inside a custom SharePoint TimerJob to email users friendly reminders when their assigned tasks are due, etc.

C# Code Sample

SPWeb web = SPContext.Current.Web;

string to = "[recipient's email address]";

string subject = "Test Message";

string body = "Message sent from SharePoint";

bool appendHtmlTag = true;

bool encodeHtml = true;

bool success = SPUtility.SendEmail(web, appendHtmlTag, encodeHtml, to, subject, body);

 

[1] - http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.utilities.aspx

author: Jason Huh | posted @ Sunday, April 27, 2008 11:08 PM | Feedback (0)

General guideline for troubleshooting SharePoint issues


This is the list of steps to follow for troubleshooting general SharePoint issues.

1. Turn on the debug flag from SharePoint web.config

    Note: Enabling debugging is not recommended on a production environment.

a. Locate the SharePoint web.config file which is typically located under one of the virtual directories in C:\Inetpub\wwwroot\wss\VirtualDirectories.
b. Make a backup of the web.config just in case.
c. Open the SharePoint web.config using a Visual Studio or a text editor such as notepad.
d. Find “CallStack”
e. Change the value of CallStack to “true”
f. Find “CustomErrors”
g. Change the value of CustomErrors mode to ”off”
h. Save the web.config.

2. Reproduce an issue you're having i.e. by refreshing the broken web page

3. Examine the error from EventLog. In most cases, you will find no useful information from EventLog since SharePoint does a poor job leaving a trace on the EventLog.

4. Go to SharePoint logs folder (c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Logs). SharePoint dumps all logs in this folder, and so you should be able to find clues by examining logs in this folder.

a. Sort items by Date Modified
b. Open the latest log file using a notepad or other text editors.
c. Scroll down to the bottom
d. Examine the latest log

5. Analyze error messages found from Step 2, 3 and 4.

6. Investigate issue for 10 minutes

a. Examine the system account used for an application pool of a SharePoint application. Does the account have proper permissions?

7. If you’re stuck for more than 10 minutes, stop what you’re doing.

8. Search for the clues from Internet -- Many times, we forget how useful Internet is and that somebody else typically had the same problem before.

9. If no clues have been found, ask for help.

a. Describe detailed steps how to reproduce the issues
b. Ask colleagues or reach out communities such as the MSDN SharePoint Forums [1]

10. Iterate the step 1 to step 5 until an issue is resolved.

[1] - http://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=328&SiteID=1

author: Jason Huh | posted @ Sunday, April 27, 2008 5:59 PM | Feedback (0)

Programmatically creating a Gannt view from SharePoint


I came across couple of questions from Internet about how to programmatically create a Gannt view on a custom SharePoint list. So, here is an answer to these questions.



1. First of all, create a custom list from a SharePoint UI.

2. On the menu of the newly created custom list, click Settings->Create Column.

3. Create a column for Start Date with "Date and Time" type with Date Only as a format (see the picture below). The column name doesn't need to be exactly same.

 



4. Create a column for End Date with "Date and Time" type with Date Olnly as a format.
5.
Create a column for PercentComplete with "Number" type. Set Min to 0 and Max to 100. Set number of decimal place to 0, and check the "Show as percentage (for example, 50%)" option. See the picture below.



Now, run the following code to create a Gannt view.


using System;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using(SPSite site = new SPSite("[site url]"))
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["CustomList"];
SPViewCollection views = list.Views;
System.Collections.Specialized.StringCollection viewFields =
new System.Collections.Specialized.StringCollection();
          viewFields.Add("Title");
          SPView view = views.Add("Gannt Test", 
viewFields, String.Empty, 100, true, false,
SPViewCollection.SPViewType.Gantt, false);
view.ViewData = @"<FieldRef Name=""StartDate"" Type=""GanttStartDate"" />
<FieldRef Name=""DueDate"" Type=""GanttEndDate"" />
<FieldRef Name=""Title"" Type=""GanttTitle"" />
<FieldRef Name=""PercentComplete""
Type=""GanttPercentComplete"" />";

view.Update();
}
}
}
}

The key point on the code is that you need to use GanttStartDate, GanntEndDate, GanntDueDate and GanntPercentComplete as types of FieldRefs for ViewData.


author: Jason Huh | posted @ Wednesday, April 23, 2008 12:25 PM | Feedback (0)