locked
URL Path RRS feed

  • Question

  • Hi i have created a linked data source so i can merge about 6 libraries, i have created a view on a web part page and want to be able to open the edit form for each document, i have been using <a href="{@FileRef}/Forms/EditForm.aspx?ID={@ID}">Edit Document</a> to try and open the edit form but it brings back the path plus the file name, how can i remove the file name from the url so it opens the edit form for that particular document.

    Thanks

    Rik


    • Edited by Rikmj Wednesday, September 14, 2016 2:28 PM
    Wednesday, September 14, 2016 2:27 PM

Answers

  • Hi Rikmj,

    We can get the library name using JavaScript Client Object Model like below:

    var ctx = new SP.ClientContext(siteUrl);
     var items = ctx.get_web().get_lists().getByTitle('Pages').getItems(new SP.CamlQuery());
     ctx.load(items, "Include(Id, Title, Author, EncodedAbsUrl, FileDirRef, FileRef)");
     ctx.executeQueryAsync(function () {
          var listEnumerator = items.getEnumerator();
          while(listEnumerator.moveNext()) {
              var page = listEnumerator.get_current();
              var library =page.get_item('FileDirRef');
          }
     });

    The FileDirRef will return the library name like /LibraryName and then we can use the code line below to get site url:

    var siteurl = _spPageContextInfo.webServerRelativeUrl;

    Then combine the edit form url like below:

    <a href="siteurl+library+Forms/EditForm.aspx?ID={@ID}">

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, September 22, 2016 8:49 AM

All replies


  • @FileRef points to actual site, while you need current web url for concatenate it with "/Forms/EditForm.aspx?ID={@ID}", i.e. instead of @FileRef you need to use siteUrl. See e.g. How to Get current site URL and use it as a parameter in href (XSLT).

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    Wednesday, September 14, 2016 3:10 PM
  • Hi i get the correct path when using <a href="{@FileRef}/Forms/EditForm.aspx?ID={@ID}">Edit Document</a> but i just need to remove the document name and extension just leaving the URL, also the URL changes depending which library the merged document is from.

    Thanks

    Rik

    Thursday, September 15, 2016 9:09 AM
  • Hi Rikmj,

    We can get the library name using JavaScript Client Object Model like below:

    var ctx = new SP.ClientContext(siteUrl);
     var items = ctx.get_web().get_lists().getByTitle('Pages').getItems(new SP.CamlQuery());
     ctx.load(items, "Include(Id, Title, Author, EncodedAbsUrl, FileDirRef, FileRef)");
     ctx.executeQueryAsync(function () {
          var listEnumerator = items.getEnumerator();
          while(listEnumerator.moveNext()) {
              var page = listEnumerator.get_current();
              var library =page.get_item('FileDirRef');
          }
     });

    The FileDirRef will return the library name like /LibraryName and then we can use the code line below to get site url:

    var siteurl = _spPageContextInfo.webServerRelativeUrl;

    Then combine the edit form url like below:

    <a href="siteurl+library+Forms/EditForm.aspx?ID={@ID}">

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, September 22, 2016 8:49 AM