change URL's? - General Discussions - General Discussions - Progress Community
 General Discussions

change URL's?

  • change URL's?
  • I created a usercontrol to show my news items, (the current news widget won't work within my display). I'm able to pull out the news title and the urlname, however the urlname is just the title of my news item. How can I get the correct URL for my news item like the out of the box news widget has?

    here is what I'm referring to:
    if I enter in a news item in the backend and title it: The following items are being discontinued, the url for that item shows up as /2011/02/23/the-following-items-are-being-discontinued

    if I show that same news item in my user controls, the url is:
    /the-following-items-are-being-discontinued

    and when I click on it nothing happens, where when I click on the URL in the news widget, I can see my news.

    how can I get the correct URL for each news item within my user control?
    here is that code that i used for the news:

     

    var news = from n in App.WorkWith().NewsItems()
                          where n.Status == ContentLifecycleStatus.Live
                          orderby n.Title
                          select n;

     



    I then bind it to my datalist and show [title] and [urlname], what should I be using for the URL?

  • Hello CsharpGuy,

    Thank you for contacting Telerik Support.

    You can get the default url by subscribing to the DataList control's ItemDataBound event. Consider the sample bellow:
    void  dt_ItemDataBound(object sender, DataListItemEventArgs e)
       
           if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
           
               NewsItem itemBound = (NewsItem)e.Item.DataItem;
               string url = itemBound.Urls.Where(u=> u.RedirectToDefault == false).FirstOrDefault().Url;
               //this will give you /2011/02/23/the-following-items-are-being-discontinued
               //then you need to construct a link to your page which contains news control and append the url to this link
           
       
    Please pay attention to the last comment - the string url will refer to the default URL of the news item, but you need to reference the link to your page containing the news control, in order to make the news visible when accessed from your custom control.

    I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

    Greetings,
    Boyan Barnev
    the Telerik team
  • wow, never would have figured that out. You guys should build a code library or something and have real world working examples like this. So far the v4 documentation isn't that great and has nothing like this in it.


    Is something like this possible to pull out all of my pages?
  • Hi CsharpGuy,

    We started working on the documentation articles, so the manual is going to be updated very soon with new samples and How tos. As for the pages, there is implementation for additional urls for pages that can be set from the UI, so you can specify completely differentiate url to resolve the same page with no coding. The feature will be included in the Q1 release.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
  • That codes works for me. I also used myNewsItem.Urls[0].Url and that returns the right Url. 
    However, 
    how can I control the URL path. mainly I don't want dates in the URL (in general I need to flexibly do the paths ) 
    example: 
    I want to change "/2011/03/29/how-to-write-code"  to --> "/code/how-to-write-code"

    Any tips, hints.

    Thanks 
  • Hello Taha,

    There is an option to change the url format of the content modules go to Administration >> Settings >> Advances and expand the News node. Then add urlFormat parameter to the provider. For Key enter "urlFormat". For value enter "/[UrlName]". All without the quotes.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  • Can we change the urlFormat for blogs as well?  I tried adding the urlFormat key for the blog provider and it did not update my blog URL's when using a blog posts control.
  • @Dave, I'm pretty sure you need to a) restart your web app (aka edit the web.config) and b) it will only be applied to new blogs going forward. I did this same change to the Libraries as I didn't think the date in the url to an image made any sense. It would only work for new albums, so I basically had to delete all my images and albums and start from scratch. Hope that helps.

    Phill
  • Hello Ivan,

    I have the same issue of Dave, I changed the urlFormat for the blogs and I created new posts but still the url of the new blog posts have the format "date/urlName"

    Did I miss anything?

    Thanks.
  • Hello AmrElsayed,

    After saving the changes to urlFormat, did you restart the application? You need to do this, because we are not restarting it automatically on adding the key for urlFormat.  Please try modifying the web.config (just press space couple of times and then save) and then make a new blog post and inform me if the issue still persists.

    Greetings,
    Boyan Barnev
    the Telerik team

  • 261009_2011-04-04-1305.png
    Helo Boyan,

    yes, I added the "urlFormat" parameter, then I restarted the application (and I tried to make any changes in the web.config), then I created a new post in a blog.
    the url of the new post is still in the format "date/urlName".

    I am using version 4.0.1210.0

    Thanks.


  • I've mentioned already that I had this issue with Libraries and Albums. The key was that after changing the URL format I had to delete the album and start from scratch. I would assume this is the same as Blogs, you can just create a new blog post you need to delete the blog and create a new one, then create a blog post and see if it works. Have you done that?

    Cheers,
    Phill
  • Hello AmrElsayed,

    Indeed there is a registered  bug concerning this behavior, which is for blogs only. Generally the url should be changed without deleting the old data. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

    All the best,
    Boyan Barnev
    the Telerik team

  • Hello AmrElsayed,

    Indeed there is a registered  bug concerning this behavior, which is for blogs only. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

    All the best,
    Ivan Dimitrov
    the Telerik team