views:

439

answers:

4

I have a an ASP.NET user control where i wanto run a flash movie using flashplayer.How can i set the path of flash movie file properly so that this would work in all pages irrespective of the folders. ie; it should work inside a page in FolderA and a page in FolderASub1 which is in FolderA and a page in the Root folder too.My Flash file resides in a Folder called FlashGallery in root.My User control resides in a Subfolder in Root.

I am not sure how can use ~ here .Since its(Object tag to play flash) not a server control. And infact i cant place the full relative path too.

Anythoughts ?

+2  A: 

You can use a root-based path: /FlashGallery/movie.swf

Or you could generate a path string in your code, and place it in the aspx file like this:

<%= flashPath %>

Ray
+1 If you know the path of the SWF and it doesn't chnage you can simply use an absolute URL. You have no need to use "~" as it's not a serverside path
Greg B
+1  A: 

Use an absolute path based off the root of your domain. Instead of using a relative url path like

"mymovieplayer.fla"

or

"../mymovieplayer.fla"

do this

"/flash/mymovieplayer.fla"

Nick Berardi
But my user control is in a subfolder of root
Shyju
In my suggestion, and in Nick's, the root folder is represented by the initial "/" - then you add the subfolder and the file name: "/FlashGallery/movie.swf"
Ray
It doesn't matter. Because all you care about is the resulting path that is rendered out to the browser. You just need to specify a static for the flash path.
Nick Berardi
But when the user control is in a subfolder in root,how does it work ? I tried it .It did not.I know using ~ would make it to the root.But does / do it ?
Shyju
the browser interprets / as the root folder of the site where the current page lives. So /FlashGallery is a subfolder under the root. Assuming permissions are granted to serve files from that folder, your browser will be able to load your movie.
Ray
You are relying on the framework way too much. You just need to put the path in to the src of the <object /> tag
Nick Berardi
+1  A: 

FYI: I use this (Free)Control: http://www.junasoftware.com/servercontrols/swfobject.net/download.aspx

You can use the '~' tilde to use relative paths to the site root and it will work on a master page, even if content pages are in different directories, you can use it like this:

<%@ Register Assembly="SWFObject.Net" Namespace="Juna.Web.UI" TagPrefix="SWF" %> . . .

Its FREEEEE!

Robert Dondo
A: 

Using a root based path is fine if you always know your site will be installed to the root, but this isn't realistic and best practise.

It would've been nice of we could use the server side relative path prefix of ~/ for the ... tag, but as you know it's not a user control so it just gets rendered out to the client as is. Below is a trick to allow you to specify the ~/ relative path for a client side script block.

I essentially use the VirtualPathUtility class and a protected method on the code behind of the page, master page, or control and it works very well for me.

Here's the method:

protected string GetPageRelativePath(string targetPath)
{
    return VirtualPathUtility.MakeRelative( Request.AppRelativeCurrentExecutionFilePath, targetPath );
}

And here's how you can use the ~/ prefix in the script block:

<script type="text/javascript" src='<%=GetPageRelativePath("~/Scripts/MyScript.js") %>'></script>

Essentially you could use this with other src paths, even paths to images or Flash files.

Hope that helps.

Jaans