Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Media Selection Url Issue View modes: 
User avatar
Member
Member
amarwadi-gmail - 8/31/2010 6:27:00 PM
   
Media Selection Url Issue
Hello,
I am using a Media Selection control on a Document type that I have created. When I upload the file using the Media Selection control, it generates the URL as follows:
/TestCmsSite/Images/Executives/TestMan.aspx?width=97&height=145&ext=.jpg

Where TestCmsSite is the site code name and the TestMan is the name of the file.

When I publish this site to test.companyname.com site name, i noticed that the Images still have the TestCmsSite alias in there.
Thus the path of the site now is: http://test.companyname.com/TestCmsSite/Images/Executives/TestMan.aspx?width=97&height=145&ext=.jpg

However, the correct URL should be:
http://test.companyname.com/Images/Executives/TestMan.aspx?width=97&height=145&ext=.jpg

Is there a way by which we can generate these URL's correctly? Also, is it possible to generate relative URLs? It shouldn't be referencing the entire path, but just start from the correct relative path right?

In my transformation we're using the Media Selection Control as follows:

<%@ Register TagPrefix="cms" TagName="Media" Src="~/CMSInlineControls/MediaControl.ascx" %>

<cms:Media id="memberPhoto" runat="server" Url='<%# Eval<string>("MemberPhoto")%>'/>



Any thoughts?

Any guidance would be appreciated.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/1/2010 11:28:48 AM
   
RE:Media Selection Url Issue
Hello,

do you mean that you created the attribute of Text type and field of Media Selection type in your custom document type?

In this case relative path to image (unfortunately with site code name) is created and stored in database.

So you will need to remove it in your transformation. Please take a look at following workaround transformation code. You can choose if you want to create absolute or relative URL without alias.


<%@ Register TagPrefix="cc2" Namespace="CMS.CMSHelper" Assembly="CMS.CMSHelper" %>
<%@ Register TagPrefix="cc3" Namespace="CMS.GlobalHelper" Assembly="CMS.GlobalHelper" %>

<script runat="server">

// creates a relative URL path without site code name

protected string getRelURL()
{
// gets value from database
string withAlias = (string)CMSContext.CurrentDocument.GetValue("MediaSelection");
// removes "/TestCmsSite" and adds ~
string withoutAlias = "~" + withAlias.Substring(12);

return withoutAlias;
}

// creates an absolute URL path without site code name

protected string getAbsoluteURL()
{
string withAlias = (string)CMSContext.CurrentDocument.GetValue("MediaSelection");
string withoutAlias = withAlias.Substring(12);

return "http://"+UrlHelper.GetFullDomain()+withoutAlias;
}

</script>

<p>
<img src="<%=getRelURL() %>" />
</p>

<%=getAbsoluteURL() %>



I hope this code helps you.

I also created a requirement to remove site code name from image path in one of next version.

Best regards,
Ivana Tomanickova