Tuesday, December 28, 2010

SharePoint Web.Config: How to Show Full Errors

Enable display of error details and stack trace when an error occurs

Replace the following error messages with a more meaningful description of the cause of the error by disabling custom errors and enabling the track trace to be displayed as well.
An unexpected error has occurred
An error occurred during the processing of...
To display full errors and the stack trace of the error, you need to modify the web.config file for the Web Application which SharePoint is running on. There are a number of web.config files required to configure various components of SharePoint. For help finding the correct web.config file.

Enable Custom Errors: Set the customErrors mode to "Off"


Find:

<system.web> ...
<customErrors mode="On" />

Change To:

<system.web> ...
<customErrors mode="Off" />


Enable the Call Stack Trace: Set the CallStack value of the SafeMode element to "true"

Find:

<SharePoint>

<SafeMode ... CallStack="false" ... >

</SharePoint>

Change To:

<SharePoint>

<SafeMode ... CallStack="true" ... >

</SharePoint>


Enable Debugging Mode: Set batch and debug to "true"

Find: <compilation batch="false" debug="false">
Change To: <compilation batch="true" debug="true">


Enable the ASP.NET tracing feature:
Include the following line in the <system.web> element of the web.config file.

<system.web> ...

<trace enabled="true" pageOutput="true"/>



By default, SharePoint will only display a basic message to users when an error occurs. The message is virtually useless when trying to troubleshoot an issue, so by enabling more descriptive errors to display, including the stack trace which should help you find the cause of the error. You should not make changes to the web.config file in a production environment, or while in production. Back up your entire SharePoint environment, including all databases prior to commencing any major troubleshooting. You should attempt to replicate and resolve the problem in a non-production environment, and apply the necessary changes to the live environment when it is not in production. In many cases, the web.config will not need to be modified in the live environment as the cause of an error will be known after troubleshooting in a production environment.

Open a PDF document to a new browser in the Document Library

If you want only documents in one document library to open to new windows, you can edit the document library in SharePoint Designer.
1.      Open the site in SharePoint Designer and then open the document library allitems.aspx.
2.      Right-click the document library web part and select “Convert to XSLT data view”.
3.      Locate the name column, you will see this tag “<xsl:otherwise ><A onfocus="OnLink(this)"  HREF="{@FileRef}"….. </xsl:otherwise>”, 
    add “target="_blank"” in <A> tag.
After this, the documents will be opened in a new window.
Hope it can help you.

Opening PDFs in SharePoint 2010

If you have your nice SP2010 setup you may notice that when you go to open a PDF file it prompts you to save it rather than opening.

This is really annoying and would send everyone here at the school completely bananas! Not to mention the fact that we try to get everything on SharePoint only to force people to save it to their own area!
Never fear there is a solution. It’s in central admin.
Go there and click ‘Manage Web Applications’

Click on the web app you want to change, and go to ‘General Settings’

Scroll down the list until you reach ‘Browser File Handling’
Change the radio box from Strict to Permissive.

Click ok.



Tuesday, December 21, 2010

Page Processing Model in WSS3.0/MOSS 2007

The Page Processing Model

The following list gives a step-by-step breakdown of how ASP.NET 2.0 and Windows SharePoint Services 3.0 interact to render pages in a SharePoint site:
  1. The browser requests a Web page from Microsoft Internet Information Services (IIS).
  2. IIS passes the request to ASP.NET 2.0.
  3. An HttpApplication pipeline is created for the request.
  4. ASP.NET 2.0 fetches the page via the Windows SharePoint Services 3.03 file provider. ASP.NET passes the URL to the file provider, and the file provider fetches the page and returns the page stream. The Windows SharePoint Services file provider implements caching and reduces round-trips to the database.
  5. ASP.NET loads a Page class, parses the page stream, and finds a reference to the page layout upon which the page is based.
  6. The ASP.NET engine compiles the page stream and stores it in memory.
  7. ASP.NET queries the Windows SharePoint Services file provider for the page layout.
  8. ASP.NET loads the stream for the page layout associated with the current page.
  9. ASP.NET compiles the page layout and stores it in memory. ASP.NET can free this memory later if the system needs memory.
  10. ASP.NET determines the master page for the site and fetches the master page via the Windows SharePoint Services file provider.
  11. ASP.NET compiles the master page and writes to the disk so you never have to recompile the master page unless you modify it.
  12. The page layout runs each control on the page in the context of the page that was requested.
  13. ASP.NET updates the necessary caches.
  14. IIS returns the page to the browser.
The next time the page is requested by the same user or by a different user who has the same permissions to see the page as the first user, page processing is much more efficient:
  1. The browser requests a Web page from IIS.
  2. IIS passes the request to ASP.NET 2.0.
  3. An HTTPApplication pipeline is created for the request and hits the HandleRequest.
  4. ASP.NET uses all the internal caches.
  5. ASP.NET renders the HTML for the controls.
  6. IIS returns the page to the browser.


Note: Even though this process takes little time, ASP.NET renders the controls each time, and you may not want that. In such cases, you can turn on the ASP.NET 2.0 page output caching feature. 

Friday, December 17, 2010

Installing and configuring SMTP and POP3 e-mail for sharepoint 2010

Introduction
After having installed a development environment we can complete our installation by installing and configuring SMTP and POP 3 service on our Virtual machine.
Developer benefits (the "Why" part of the post)
It would be interesting to have a way to send and receive e-mails inside our development environement in order to:
  1. Configure and test incoming e-mail for SharePoint 2010
  2. Configure and test outgoing e-mail for SharePoint 2010
  3. Configure and test SharePoint 2010 alerts
  4. Configure and test SharePoint 2010 contribution with e-mail sending
This installation steps
To be able to test all these SharePoint 2010 functionalities, we are going to:
  1. install the windows mail application
  2. install the SMTP server feature
  3. configure the SMTP server
  4. install a third party free POP 3 service
  5. configure our POP 3 service
  6. configure the windows mail application
  7. test e-mail sending and receiving within a Windows 2008 server R2 development environemnt for SharePoint 2010
1 - Installing the windows mail application
Download the Windows Mail software, the successor of outlook express for Windows 7 and Windows server 2008.
Start the installation.

2 - Installing and the SMTP server feature
On your Windows 2008 server R2 development machine start the Server Manager:
Click the Add Features link
Check the SMTP Server feature check box
The Web Server IIS Feature Wizard is opening since as you will see later, the SMTP Server configuration has to be done within the old IIS 6.0 console.
On Select Role Services Windows, let the default option (while I was tempted to check WebDav to be able to navigate through my SharePoint 2010 folders using Front Page RPC and WebDav protocols after having added a network place for a SharePoint site. But I had the pleasant surprise to discover it was already working, and I think it is thanks to Visual Studio 2010 installation...)
Validate the page of Confirm Installation Selection
This is the screen you should have after the installation of your SMTP Server Feature on your Windows 2008 Server R2 environment

3 - Configuring the SMTP server
As said before, the SMTP Server is configured using the old IIS 6.0 Microsoft Management Console, so open it:
We are now going to create a domain alias for our machine.
Assume we call it contoso.com
That is the screen after having created the alias
Now, open the SMPT Server properties
On the Access tab click Relay
The Relay Restrictions dialog is opening
Click Add
Enter the local IP of your machine.
Confirm all this and close dialogs.
If you reopen the Relay Restrictions dialog you should obtain this:

4 - Installing a third party free POP 3 service
As posted by Chris Stinson, while SMTP is alive and well in the Features section of the Windows 2008 Server Manager, POP3 has been removed from Windows 2008 altogether. Fortunately, Chris has also given a reference to a third party free solution:
You will find the link to the 64 bits version, download it and start the installation

5 - Configuring our POP 3 service
To enable the Visendo SMTP (pop3) Extender for Windows 2008 Server do the following.
Assume we are wanting to create a mailbox for an account the e-mail address of which is administrator@contoso.com...
Start creating a folder at this location:
C:\inetpub\mailroot\Drop\administrator_contoso_com
Then, locate the visendosmtpextender.config and open it. It is located at:
c:\Users\All Users\ppedv\visendosmtpextender
And cofigure it as following:
<VISENDO>
<
POP3>
<
Outbound UseOutboundPop3="true" StoreFolder="C:\inetpub\mailroot\drop" ServerPort="110" ServerIP="127.0.0.1"/>
</
POP3>
<
accounts>
<
mailbox datadir="\administrator_contoso_com" destination="administrator@contoso.com" password="Passw0rd"/>
</
accounts></VISENDO>
Finally, restart the Visendo SMTP Extender Service
6 - Configuring the windows mail application
Open Windows mail,
and if there is no account created yet, the software will ask you to create one.
Type the previous administrator e-mail account information in the first dialog
and the server information linked to this account in the second dialog
Close the last dialog that confirms the successful creation of the administrator email account

7 - Testing e-mail sending and receiving
Now, we just have to test if all is working properly.
As you should be signed in within Windows Mail as administrator@contoso.com, try to send an e-mail to this account.
Start several sync operations. Do not worry, it can take few minutes until...
the e-mail finally arrives...
Well done!
We can now use all e-mail functionalities offered by SharePoint 2010 in our Windows server 2008 R2 development environment.
 8 - Configuring incoming e-mail settings (SharePoint 2010 - local service accounts)
Now is the time to configure incoming e-mail settings for our environment ie a development machine using local accounts. So the configuration  will be very easy since we will not have to manage with settings linked to Active Directory.
So open the SharePoint 2010 Central Administration and click on System Settings.
Then, on the System settings page, on the configure incoming e-mail settings link
Here, quite let all default options, 
just enable sites on this server to receive e-mails
settings mode --> automatic
DO NOT use SharePoint Directory Management Service (there is no Active Directory available in our case anyway)
complete E_mail server display address with our alias --> contoso.com
Accept mail from all e-mail servers
 9 - Configuring outgoing e-mail settings (SharePoint 2010 - local service accounts)
Go back using your browser to return to the system settings page and this time click the "Configure outgoing e-mail settings link"
Here is the proper configuration for our environment:

10 - Giving an e-mail address to the local users accounts
Now, we want to test what we have configured, but to do it, we need user accounts with an available e-mail address . Unfortunately, as we are using local accounts, when we have registered them in the SharePoint content databases, there were no way at this time to automatically obtain an e-mail address from an Active Directory or an LDAP. To do this, while we could use the SharePoint 2010 UI by editing each account properties, I will rather take advantage of this operation to show how easy it is to program a fast sharePoint 2010 configuration task using the SharePoint object model. By the way, imagine you have to do this operation for 1000 local service accounts...
So open Visual Studio and create an aspx file in the layouts directory under the 14 hive. Assume we call it setEmailAddress.aspx
Here is the code of our SharePoint 2010 application page:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" DynamicMasterPageFile="~masterurl/default.master"  %>
<%@ Import Namespace="Microsoft.SharePoint" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script runat="server">
   
    SPWeb myWeb = null;
    string message = string.Empty;
    string userName = string.Empty;
    public void Page_Load(object sender, EventArgs e)
    {
        myWeb = SPContext.Current.Web;
       
        message += "Welcome to " + myWeb.Title;
        message += "<br/><br/>This page was created with the minimal page directives required for SharePoint 2010 application pages...";
    }
    </script>
  
    <%
        message += "<br/><br/>Giving the users an e-mail address...<br/>";

        myWeb.AllowUnsafeUpdates = true;
       
        foreach (SPUser anUser in myWeb.AllUsers)
       {                      
            userName=anUser.Name.ToLower();
           
            if(!userName.Contains("system") && !userName.Contains("service")){                       
           
                userName=userName.Remove(0,userName.IndexOf(@"\")+1);
                anUser.Email = userName + "@contoso.com";             
                anUser.Update();       
                message += "<br>" + anUser.Email + " was sucessfully attributed";         
            }           
       }
          
           lblMessage.Text = message;
    %>

      <asp:Label id="lblMessage" runat="server" />
    
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Set Users e-mail address
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Set users e-mail address
</asp:Content>


This is the way of quickly configuring Sharepoint while programming against the SharePoint 2010 object model. A simple application page with two page directives, and here you are, you have the intellisense and can start driving your SharePoint 2010 environments by writting HTML and C#. You will notice by the way that this 2 page directives are also enough to obtain a SharePoint 2010 application page with all the required presentation elements. Let us call it the SharePoint 2010 minimal Application Page.
Now execute the page and you should obtain something like this:
We can now check that our users were actually provided with an e-mail adress:
11 - Testing Incoming e-mail settings for a SharePoint 2010 list with local accounts
Create a discussion list in a sharePoint 2010 site, assume we call it forum. As we have enabled incoming e-mail at the Farm level, a new configuration parameter appear in the list settings:
Now, if we provide the "forum" list with an incoming e-mail address, users will be able to contribute to the list by sending e-mail to this address, and the authentication will be based on their e-mail address.
And if a user send an e-mail to this SharePoint 2010 list address,
a new entry will appear within the list.
12 - Testing outgoing e-mail settings for a SharePoint 2010 list with local accounts
now assume we had configured an e-mail alert for our other account, the Administrator one, he should have received a message about the previous e-mailed contribution.
And it is done!

13 - Aknowledgements and useful links
Thanks to Glafkos Charalambous for his post about SMTP Configuration
And if you want to test mail receiving with telnet here are two useful links: