Get SPList and SharePoint.Client.List web relative url - url

I am working with sharepoint list and sharepoint client list objects. Is there any way to get web relative urls of those objects?
I know about ServerRelativeUrl, DefaultViewUrl but they don't solve my problem.
I want exactly web relative urls, without view url parts.
For example my tasks list has a url like this
http://example.com/sites/developer/lists/tasks/CustomDefaultView.aspx
and i want only lists/tasks part.
For example my shared documents has a url like this
http://example.com/sites/developer/shared%20documents/Forms/AllItems.aspx
and i want only shared%20documents part.
I need this both for SPList class and for SharePoint.Client.List class
thanks!

So i found the solution. I need to use SPList.RootFolder.Url which returns Web site-relative url of the list(just what i want), and also need to do some manipulations for Client.List class as has no RootFolder.Url property, instead it has RootFolder.ServerRelativeUrl. So if i subtract the server relative url of the parent web of that list from RootFolder.ServerRelativeUrl i will get what i wanted for Client.List class.

Related

Get ASP.NET bundle URL for use with CDN?

I'm using the ASP.NET bundling feature and want to know how I can get the URL returned by the Render helpers such as Scripts.Render("~/bundles/scripts").
Currently the optimized output is has a relative URL. I want to use a CDN that does origin-caching, so the final URL needs to be something like http://static.mydomain.com/bundles/scripts?v=XXXXXX
My plan is to simply write my own helper method, but I can't figure out how to get the version number relative URL for a given bundle.
The solution was rather simple. There is a static method Scripts.Url and Styles.Url that give me exactly what I want. I was able to incorporate this into my own helper to concatenate the CDN's base URL.

Mapping URLs formed by page name to a single different URL

Am having many xhtml pages in my application. First page that a User gets to see is named index.xhtml, when User is asked to update his Profile it will be updateProfile.xhtml etc. When I hit my application my page names gets displayed on the URL. When user is updating profile, URL will be http:/myDomain/myServlet/updateProfile.jsf.
Am interested in knowing whether its possible to map all my xhtml page names which gets displayed on the URL to some other name. For eg., in the above case, I want all the URLs which matches *.jsf pattern to be displayed to user as http:/myDomain/myServlet/myAccount.
I dont see a possible threat if a end user gets to know my page names, but still, I dont have much knowledge on Security/Hacking, so atleast I dont want to display *.jsf in my URL. Because, a user can know that am using JSF.
In JavaServer Faces to rewrite URL you need basically a Filter. In your case your rewrite could be done by something like PrettyFaces http://ocpsoft.org/prettyfaces/.
With PrettyFaces you will be able to configure rewrite patterns and everything you need.
Edit : When creating your own Filter to redirect URL, you also need to create a ViewHandler and override the getActionURL() function so that actions will go to the new URL.

how to remove sitecore folder name in the url?

I created a sitecore year/month/day folder structure in the content tree, when i view each article under the folder node, the url could be http://local/landing/year/month/day/article1.aspx, how could I make the url like this: http://local/landing/article1.aspx?
just remove the year/month/day structure in the url.
Is there some function in sitecore like remove or hide special templates in the frontend url ?
Any help , Thanks .
You can do it in 2 ways:
Use IIS 7 Url rewrite module to change the url. This way the url will be rewritten before it gets to sitecore and you don't need to change any code. You can find more info at the iis website
You can create a custom Item resolver and add it to the RequestBegin sitecore pipeline. Alex Shyba wrote about it here.
It sounds like you may have thousands of these items, but even so, you may want to use the built in functionality of Sitecore and consider creating aliases for each of these items. Programmatically creating an the alias on an ItemSaved event or ItemCreated is probably easiest.
As #marto and #seth have said, you can use URL rewriting or aliases to solve this.
There is, however, a drawback to doing this, irrespective of how you choose to do it.
If you have very many items (your structure makes it sound like you may do) then either method will require that the URL is unique. Removing the date structure from the URL means that all items in your landing section will require unique URLs (whether inherited from their item names or by some other means). This can impact on SEO for your site, as authors may have difficulty finding an unused name that is also human readable and good for SEO. It's unlikely you want to use ugly GUIDs in your URLs.
2 options
Change Bucket configuration and the set the required folder structure, bucket configuration can be found in Sitecore.Buckets.config file
Extend GetFromRouteValue Item Resolver and overwrite the ResolveItem() method to get the bucket item.
The default GetFromRouteValue class reference can be found in Sitecore.MVC.config file and replace this with your own customized implementation.
We have implemented with customized routing and getting the exact item if the route path matches.
Thanks,
Jisha

Rails Absolute URL for public directory

What is the method I need to call to find the root URL for a rails application. For example, I have a site where the address is "https://host:1234/foo/app-main".
What method should I be using to get "https://host:1234/foo/images" to get the absolute url for images in the public url?
image_path(image_name)
Edit: Steve has a good point, this will only get you part of the way there. To get the rest you must be inside of a request (you probably are)
In that case though, you can combine the above with Justice's approach,
"#{request.scheme}://#{request.host_with_port}/#{request.script_name}#{image_path(image_name)}"
This question makes sense only on a per-request basis, since your one process might easily be listening on multiple domain names and on multiple schemes.
"#{request.scheme}://#{request.host_with_port}#{request.script_name}"
See Rack::Request.

What is the simplest way to return different content types based on the extension in the URL?

I'd like to be able to change the extension of a url and recieve the model in a different format.
e.g. if
/products/list
returns a html page containing a list of products, then
/products/list.json
would return them in a json list.
Note: I like the simplicity of the ASP.NET MVC REST SDK, it only requires about 5 lines of code to hook it in, but the format is specified as a query string parameter i.e. /products/list?format=json which is not what I want, I could tweak this code if there are no other options, but I don't want to reinvent the wheel!
I wrote a blog post that shows one possible example. It's a tiny bit complicated, but might work for your needs.
http://haacked.com/archive/2009/01/06/handling-formats-based-on-url-extension.aspx
You should be able to just use routes in conjunction with the rest sdk
If you have the flexibility to drop Apache or something similar in front of your service, you can always use mod_rewrite to rewrite an external http://products/list.json into http://products/list?format=json which your framework can render more easily.
Instead of "list.json", you could choose "list/json" and use a route like
{controller}/{action}/{id}
Then ProductController.List would be called, with an ID parameter of "json". The .List() action then would decide whether or not to return an HTML view or JSON content.

Resources