Nicolas Raoul
Nicolas Raoul

Reputation: 60203

How to write a link to an Alfresco Share folder? (within a site)

I want to create an HTTP link to a particular folder in Alfresco Share.

Alfresco Share encodes paths in a rather convoluted way:

thesite
http://server/share/page/site/thesite/documentlibrary

thesite/documentLibrary/somefolder/anotherfolder
http://server/share/page/site/thesite/documentlibrary#filter=path|%2Fsomefolder%2Fanotherfolder

thesite/documentLibrary/éß和ệ
http://server/share/page/site/s1/documentlibrary#filter=path|%2F%25E9%25DF%25u548C%25u1EC7

thesite/documentLibrary/a#bc/éß和ệ
http://server/share/page/site/thesite/documentlibrary#filter=path%7C%2Fa%2523bc%2F%25E9%25DF%25u548C%25u1EC7%7C

I suspect it is a double URLencode, with the exception of slashes which are only URLencoded once.
But I am not 100% sure.

Is there a C# library that does this encoding?

Upvotes: 1

Views: 1991

Answers (3)

mikehatfield
mikehatfield

Reputation: 151

You might find it easier to use the legacy ?path= parameter for document library folder URL creation.

Using the example path /Sample Content/∞⊕⊗¤☺☹★☆★☆★ instead of building a URL of the form

http://alfresco.example/share/page/site/mike/documentlibrary#filter=path%7C%2FSample%2520Content%2F%25u221E%25u2295%25u2297%25A4%25u263A%25u2639%25u2605%25u2606%25u2605%25u2606%25u2605%7C&page=1

you can generate one that looks like

https://alfresco.example/share/page/site/mike/documentlibrary?path=/Sample%20Content/%E2%88%9E%E2%8A%95%E2%8A%97%C2%A4%E2%98%BA%E2%98%B9%E2%98%85%E2%98%86%E2%98%85%E2%98%86%E2%98%85

So using C# you'd use Uri.EscapeUriString() on the path and append it to the base document library URL with ?path=

You can see how the path parameter is interpreted in documentlibrary.inc.ftl

Upvotes: 4

Michael Böckling
Michael Böckling

Reputation: 7872

Check org.alfresco.repo.web.scripts.site.SiteShareViewUrlGetfor an implementation. Its not very elegant, but seems pretty complete, probably a good starting point for your own class.

There really should be a helper class for this, but maybe I'm missing something.

Upvotes: 2

Nicolas Raoul
Nicolas Raoul

Reputation: 60203

I could not find a library, so I wrote the following code:

if (path.Contains("documentLibrary"))
{
    int firstSlashPosition = path.IndexOf("/");
    string siteName = path.Substring(0, firstSlashPosition);
    string pathWithinSite = path.Substring(firstSlashPosition + "/documentLibrary".Length);
    string escapedPathWithinSite = HttpUtility.UrlEncode(pathWithinSite);
    string reescapedPathWithinSite = HttpUtility.UrlEncode(escapedPathWithinSite);
    string sharePath = reescapedPathWithinSite.Replace("%252f", "%2F");
    return "http://server/share/page/site/" + siteName + "/documentlibrary#filter=path|" + sharePath;
}
else
{
    // Site name only.
    return "http://server/share/page/site/" + path + "/documentlibrary";
}

Any correction or better answer would be much appreciated!

Upvotes: 0

Related Questions