Monday, 25 July 2011

SharePoint Document List: Document Opens with New Browser Window

The Problem
When using a document list in SharePoint, there are three options for displaying the document name in a data view:
  1. Name (linked to document with edit menu)
  2. Name (linked to document)
  3. Name (for use in forms)
The problem lies with the first two options.  When using the first option, the data view is presented with a link to the document.  When the user clicks the link, a new browser window will open, and the document will be displayed in the new window, or in the native client - depending on the "Browser-enabled Documents" settings on the "Advanced Settings" page.  The link will open a new browser window regardless of the setting. 
When using the "Open in the client application" setting, the new browser window is opened, the user is challenged with the "Open/Save/Cancel" dialog and the client application is launched with the document presented.  When the user is done with the document and closes the client application, the new browser window is still open to a blank page.
This is not the case when using option #2.  When the user clicks the link on the data view, the user is immediately challenged with the "Open/Save/Cancel" dialog and the client application is opened with the document presented.
Using option number two removes the "Edit Menu" from the data view.
The Solution
To resolve this, I converted the data view to an XSLT data view and edited the XSL.
  1. Design your view using option #1, "Name (linked to document with edit menu)" 
  2. Open the data view in design mode using SharePoint Designer (The data views are listed in the forms folder for the list they belong to)
  3. Right click on the Data View webpart and select "Convert to XSLT Data View"
  4. When the process is complete, switch to code view
  5. Search for and remove the target="_new" attribute
  6. Save the form
Side Effect
There is one side effect to this.  The edit menu will be different after converting to XSLT.  The difference has very little impact.
<
Default Edit Menu   XSLT Edit Menu
 
The "Workflows" option is not on the XLST menu, but the "Add to my Links" option is.  The workflows are still available from the properties page for the document.  The addition of the "Add to my Links" option is just a bonus! (The "Manage Permissions" option is also gone.  This option only shows if you are an admin for the list.)
Misc
The other benefit to converting your data views to XSLT is that you have more control of the presentation of the data view.  You can specify column with, edit column heading labels or make any other presentation changes you little heart desires.

Source: http://cycogeek.fiesta25.com/blogs/cycogeek/post/2008/08/29/SharePoint-Document-List-Document-Opens-with-New-Browser-Window.aspx

No comments:

Post a Comment