1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / File link issue

File link issue

6 posts, 0 answered
  1. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    25 Mar 2009
    Link to this post
    For our site we needed to make our own video/audio player control so we can disable it for pdas, that part is working fine. The issue is that after selecting the file there are issues with the url. for the example the video is stored in the files directory.

    using a selector for the file we get ~/files/video.mpg
    which on a page that is in the main part of the site (parent page) works fine if I remove the "~/" (I know this is fixed in the 3.6 hotfix but it's not the issue)

    The problem becomes when the file is used on a child page

    the proper address is www.mysite.com/files/video.mpg
    but the address that gets generated is www.mysite.com/parentpage/files/video.mpg

    how I can have so it keeps going to the proper url without having to recode it each time?

    This is the code for the video player:
    //ascx  
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Video.ascx.cs" Inherits="WebUserControl" %>  
        <div id="test" runat="server"></div>  
    //cs  
    using System;  
    using System.Collections;  
    using System.Configuration;  
    using System.Data;  
    using System.Web;  
    using System.Web.Security;  
    using System.ComponentModel;  
    using System.Collections.Generic;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using Telerik.Cms.Web.UI;  
    using System.ComponentModel;  
    using Telerik.Web.UI;    
     
    public partial class WebUserControl : System.Web.UI.UserControl  
    {  
        private string VidURL,VidHeight,VidWidth;  
     
        [WebEditor("Telerik.FileManager.UrlWebEditor,Telerik.FileManager")]    
        [Category("Video Settings")]  
        public string VideoURL  
        {  
            get 
            {  
                  
                return VidURL;  
            }  
            set 
            {  
                VidURL = value;  
            }  
        }  
        [Category("Video Settings")]  
        public string VideoHeight  
        {  
            get 
            {  
                return VidHeight;  
            }  
            set 
            {  
                VidHeight = value;  
            }  
        }  
        [Category("Video Settings")]  
        public string VideoWidth  
        {  
            get 
            {  
                return VidWidth;  
            }  
            set 
            {  
                VidWidth = value;  
            }  
        }  
          
        protected void Page_Load(object sender, EventArgs e)  
        {  
            System.Web.HttpBrowserCapabilities browser = Request.Browser;  
     
            if (Session["mobile"] == "true")  
            {  
                test.InnerHtml = "This feature has been disabled for Mobile Browsers";  
            }  
            else if (browser.Type.StartsWith("IE"))  
            {  
                test.InnerHtml = "<object width='" + VidWidth + "' height='" + VidHeight + "' id='Player1' classid='CLSid:6BF52A52-394A-11d3-B153-00C04F79FAA6' ><param name='URL' value='" + VidURL + "' /><param name='autostart' value='true' /><param name='stretchToFit' value='true' /><param name='AutoRewind' value='true' /><param name='uiMode' value='full'/><param name='Volume' value='50'/></object>";  
            }  
            else 
            {  
                test.InnerHtml = "<object id='Player' type='application/x-ms-wmp' width='" + VidWidth + "' height='" + VidHeight + "' runat='server'>  <param name='url' value='" + VidURL + "' />  <param name='autostart' value='true' />  <param name='AutoRewind' value='true' /></object>";  
            }   
        }  
    }  
     
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    25 Mar 2009
    Link to this post
    Hi Gregory,

    Thank you for contacting us.

    You should use the ~/files/video.mpg url. Do not remove the "~/". When generating the html output just use this line of code: VirtualPathUtility.ToAbsolute(VidURL)
    instead VidURL

            if (Session["mobile"] == "true")   
            {   
                test.InnerHtml = "This feature has been disabled for Mobile Browsers";   
            }   
            else if (browser.Type.StartsWith("IE"))   
            {   
                test.InnerHtml = "<object width='" + VidWidth + "' height='" + VidHeight + "' id='Player1' classid='CLSid:6BF52A52-394A-11d3-B153-00C04F79FAA6' > 
    <param name='URL' value='" + VirtualPathUtility.ToAbsolute(VidURL) + "' /> 
    <param name='autostart' value='true' /> 
    <param name='stretchToFit' value='true' /> 
    <param name='AutoRewind' value='true' /> 
    <param name='uiMode' value='full'/> 
    <param name='Volume' value='50'/></object>";   
            }   
            else  
            {   
                test.InnerHtml = "<object id='Player' type='application/x-ms-wmp' width='" + VidWidth + "' height='" + VidHeight + "' runat='server'>   
    <param name='url' value='" + VirtualPathUtility.ToAbsolute(VidURL) + "' /> 
    <param name='autostart' value='true' />   
    <param name='AutoRewind' value='true' /></object>";   
            }    

    I hope this information will help you.

    Best wishes,
    Parvan
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    25 Mar 2009
    Link to this post
    That works perfectly, thank you very much.
  4. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    26 Mar 2009
    Link to this post
    Actually I tried this another machine while my local machine was hosting. The file directories still get a little mixed up

    The url where the file is kept: http://localhost/Prototype1/Files/Video.mpg

    prototype1 is where the website is 

    The url that the other computer got for the video is:

    http://192.168.0.100/Prototype1/Media/Prototype1/Files/Video.mpg

  5. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    26 Mar 2009
    Link to this post
    sorry the file url should be

    http://192.168.0.100/Prototype1/Files/Video.mpg
  6. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    26 Mar 2009
    Link to this post

    I managed to solve the problem:

    string x = Request.Url.ToString();
            string y = Request.Path;
            x = x.Replace(y, "");
            x = x + VirtualPathUtility.ToAbsolute(VidURL);
    Request.Url.ToString gives full address (www.mysite.com/folder1/page.aspx)
    Request.path gives the relative address of current page(/folder1/page.aspx)
    x = x.Replace(y, ""); gets (www.mysite.com)
    VirtualPathUtility.ToAbsolute(VidURL); gets /files/video.mpg
    x = x + VirtualPathUtility.ToAbsolute(VidURL); gives the full address for the video www.mysite.com/files/video.mpg

    therefore giving a hardcoded address that works no matter what the www.mysite.com actually is

Register for webinar
6 posts, 0 answered