locked
Allowing alternate protocols to be entered in link fields RRS feed

  • Question

  • I would like to configure SharePoint 2007 to allow alternate protocols / links to be entered in a number of placed:

    Hyperlink fields
    Rich text editor (highlight text and create a hyperlink)
    etc.

    An example protocol would be notes:// (for Domino databases).  I've also heard people having issues with using onenote:// and mms:// but haven't confirmed this.

    Here's a discussion on this topic that seems to be going down the right path:

    http://www.eggheadcafe.com/software/aspnet/29711508/how-to-insert-notes-li.aspx

    However, I've been unable to configure SharePoint to accept the new protocols.  It continues to give errors like:

    Hyperlinks must begin with http://, https://, mailto:, news:, ftp://, file://, or \\.  Check the address and try again. (when trying to create a link in the rich text editor)

    or

    Invalid URL: notes://server/mydb.nsf (when typed into a URL list field)

    Any help would be appreciated.

    Thanks.

    Monday, October 20, 2008 8:59 PM

Answers

  • Yes, the custom field option would only work for specific columns that have been associated to that new field type.  It has no effect on OOB RichText or Hyperlink fields.  It's unfortunate that you'd have to hack all these changes into the built in JS files.  Obviously back up these files, and it's probable this change would be overwritten when you upggrade or install the next service pack.

    The custom field option would work something like this.  Here is the field class:
    public class CustomLink : SPFieldText  
    {  
        public CustomLink (SPFieldCollection fields, string fieldName)  
            : base(fields, fieldName)  
        {  
        }  
          
        public CustomLink (SPFieldCollection fields, string typeName, string displayName)  
            : base(fields, typeName, displayName)  
        {  
        }  
     
        public override string DefaultValue  
        {  
            get 
            {  
                return this.GetCustomProperty("ValidPrefix").ToString();  
            }  
            set 
            {  
            }  
        }  
     
        //add validation code here if desired  
        public override string GetValidatedString(object value)  
        {  
        }  

    The FldTypes file would be like this:

    <?xml version="1.0" encoding="utf-8"?>  
    <FieldTypes> 
      <FieldType> 
        <Field Name="TypeName">NotesHyperlink</Field> 
        <Field Name="TypeDisplayName">Notes Hyperlink</Field> 
        <Field Name="TypeShortDescription">Notes Hyperlink</Field> 
        <Field Name="ParentType">Text</Field> 
        <Field Name="UserCreatable">TRUE</Field> 
        <Field Name="FieldTypeClass">b8421582-2450-44b9-90de-32bbb41f8eea</Field> 
        <RenderPattern Name="DisplayPattern">  
          <HTML><![CDATA[<href="]]></HTML>  
          <Column HTMLEncode="TRUE" /> 
          <HTML><![CDATA[">]]></HTML>  
          <Column HTMLEncode="TRUE" /> 
          <HTML><![CDATA[</a>]]></HTML>  
        </RenderPattern> 
        <PropertySchema> 
              <Fields> 
                  <Field Name="ValidPrefix" DisplayName="Valid Prefixes" 
                         Type="Note">  
                      <Default>notes://</Default> 
                  </Field> 
              </Fields> 
          </PropertySchema> 
      </FieldType> 
    </FieldTypes> 



    Randy - http://sharepointhawaii.com/randywilliams
    Monday, October 20, 2008 10:33 PM
  •  Now I might be "misinformed" but I don't believe that changing the JS files works.  The reason being is that that same list of available extensions is hard-coded in one of the validations in the code behind.  This might only be for the MOSS Links webpart.

    We had a similar request where we wanted to allow users to input Notes protcols (Notes:\\).  The work around was to create a application page (in the layouts) folder that redirected to the notes:\\ protocol since IE itself can handle the calls just fine.  The downside is that users have to know how to add the "special" link. 

    Just my thoughts...
    Eli
    Eli Van Eenwyk
    Tuesday, October 21, 2008 1:28 AM

All replies

  • Hi,

    The only way I have addressed this issue is through a custom field type.  You can base it on the hyperlink field and if you wanted, it could validate alternate Url formats such as notes://.

    I've been thinking about blogging on this as it seems to be a common problem.  If I do, I would provide all the code to get it to work.

    Randy - http://sharepointhawaii.com/randywilliams
    Monday, October 20, 2008 9:02 PM
  • Hi Randy,

    That might solve the field for lists, but I'm not sure if it would resolve the issue of entering URLs via the rich text editor.  It would be great to see what you had in mind for the custom field code.  Anyone else have ideas?

    Here are two sections from the default core.js file of SharePoint 2007 (I added line 9 in the first code snippet to try to get notes:// to work):

    1 function IsSafeHref(  
    2     href)  
    3 {  
    4     return (href.match(new RegExp("^http://", "i")) ||  
    5             href.match(new RegExp("^https://", "i")) ||  
    6             href.match(new RegExp("^ftp://", "i")) ||  
    7             href.match(new RegExp("^file://", "i")) ||  
    8             href.match(new RegExp("^ftp://", "i")) ||  
    9             href.match(new RegExp("^notes://", "i")) ||  
    10             href.match(new RegExp("^mailto:", "i")) ||  
    11             href.match(new RegExp("^news:", "i")) ||  
    12             href.match(new RegExp("^/", "i")) ||  
    13             href.match(new RegExp("^\\\\\\\\", "i")));  
    14

    1 function HasValidUrlPrefix(url)  
    2 {  
    3     var urlurlLower=url.toLowerCase();  
    4     if (-1==urlLower.search("^http://") &&  
    5         -1==urlLower.search("^https://"))  
    6         return false;  
    7     return true;  
    8

    I found references to the issafeurl function in the following files:  bform.js, core.js, form.js, htmleditor.js, and ows.js.

    Monday, October 20, 2008 9:12 PM
  • Yes, the custom field option would only work for specific columns that have been associated to that new field type.  It has no effect on OOB RichText or Hyperlink fields.  It's unfortunate that you'd have to hack all these changes into the built in JS files.  Obviously back up these files, and it's probable this change would be overwritten when you upggrade or install the next service pack.

    The custom field option would work something like this.  Here is the field class:
    public class CustomLink : SPFieldText  
    {  
        public CustomLink (SPFieldCollection fields, string fieldName)  
            : base(fields, fieldName)  
        {  
        }  
          
        public CustomLink (SPFieldCollection fields, string typeName, string displayName)  
            : base(fields, typeName, displayName)  
        {  
        }  
     
        public override string DefaultValue  
        {  
            get 
            {  
                return this.GetCustomProperty("ValidPrefix").ToString();  
            }  
            set 
            {  
            }  
        }  
     
        //add validation code here if desired  
        public override string GetValidatedString(object value)  
        {  
        }  

    The FldTypes file would be like this:

    <?xml version="1.0" encoding="utf-8"?>  
    <FieldTypes> 
      <FieldType> 
        <Field Name="TypeName">NotesHyperlink</Field> 
        <Field Name="TypeDisplayName">Notes Hyperlink</Field> 
        <Field Name="TypeShortDescription">Notes Hyperlink</Field> 
        <Field Name="ParentType">Text</Field> 
        <Field Name="UserCreatable">TRUE</Field> 
        <Field Name="FieldTypeClass">b8421582-2450-44b9-90de-32bbb41f8eea</Field> 
        <RenderPattern Name="DisplayPattern">  
          <HTML><![CDATA[<href="]]></HTML>  
          <Column HTMLEncode="TRUE" /> 
          <HTML><![CDATA[">]]></HTML>  
          <Column HTMLEncode="TRUE" /> 
          <HTML><![CDATA[</a>]]></HTML>  
        </RenderPattern> 
        <PropertySchema> 
              <Fields> 
                  <Field Name="ValidPrefix" DisplayName="Valid Prefixes" 
                         Type="Note">  
                      <Default>notes://</Default> 
                  </Field> 
              </Fields> 
          </PropertySchema> 
      </FieldType> 
    </FieldTypes> 



    Randy - http://sharepointhawaii.com/randywilliams
    Monday, October 20, 2008 10:33 PM
  •  Now I might be "misinformed" but I don't believe that changing the JS files works.  The reason being is that that same list of available extensions is hard-coded in one of the validations in the code behind.  This might only be for the MOSS Links webpart.

    We had a similar request where we wanted to allow users to input Notes protcols (Notes:\\).  The work around was to create a application page (in the layouts) folder that redirected to the notes:\\ protocol since IE itself can handle the calls just fine.  The downside is that users have to know how to add the "special" link. 

    Just my thoughts...
    Eli
    Eli Van Eenwyk
    Tuesday, October 21, 2008 1:28 AM
  • This post is a few years old, but I found my way to it while facing this same issue so I figured I'd help make it more complete.  I agree with you Eli.  I live by the rule that you never hack the OOTB files.

    I ended up creating an application page to solve this.  It's not entirely straight forward to get this all working nice though so I figured I'd share what I've come up with.

    Note that this works in IE and FF but I haven't tested other browsers.

    1. Create a page in the Layouts directory called launch.aspx

    Code for launch.aspx:

    <%@ Page Language="C#" %>
    
    <script type="text/c#" runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
       string sUrl = "";
    
       try{
       	sUrl = Request.QueryString["url"];
            if(sUrl == "" || sUrl == null) throw new Exception("Error occured: The 'url' parameter is required.");
       	pScript.Controls.Add(new LiteralControl("<a id='rLink' href='" + sUrl + "'>here</a>"));
       }
       catch(Exception ex)
       {
         pError.Controls.Add(new LiteralControl(ex.Message));
       }
    
      
    }
    
    </script>
    
    <script type="text/javascript">
      function reDirect()
      {
        setTimeout('launchApp()',1000);
        setTimeout('closeMe()',2000);
      }
    
      function launchApp()
      {
        window.location = document.getElementById('rLink').href;
      }
    
      function closeMe(){
        window.open('','_self');
        window.close();
      }
    </script>
    
    <body onLoad="reDirect();">
    <asp:Panel id="pError" runat="server" style="font-weight:bold; color:#FF0000;" />
    <div style="font-weight:bold; font-size:14px;">Launching... Please wait.</div>
    <div style="font-weight;bold; font-size:12px;">If the application has not launched within 5 seconds, click <asp:Panel id="pScript" runat="server" style="display:inline;"/> to launch it manually.</div>
    </body>
    

    2. To launch notes:// links, use this syntax on your SharePoint pages, etc..

    href syntax: /_layouts/launch.aspx?url=notes://notes_server/

    • Proposed as answer by Jason Steeves Tuesday, December 13, 2011 7:22 PM
    Tuesday, December 13, 2011 6:32 PM
  • Hi Jason,

    I tried to use the solution mentioned by you, it looked promising to me but its not working for me.

    After following your steps the link is like this:

    http://Severnames:port_number/sites/SiteDefDemo/_layouts/Launch.aspx?url=notes://lotus_notes_server

    But this does not launches the app. It gives SharePoint 2010 error.

    Can you please help!


    Friday, September 28, 2012 1:38 PM