Answered by:
Realtive path (Benjamin) - 5/9/2006 4:18 AM PST

Question
-
By: Benjamin
Hi, I've got a problem using relative paths for my images. "myPicture.png" is the picture I want to display and is in the root directory of my project. I'm trying to put something like "myPicture.png" in the source property of my image control but the image would'nt display. To make it work, I must use a plain path ("file:///C:/MyDirectory/.../myPicture.png"). I have tried to put the picture in the "Debug" folder... It doesn't work neither... I'm sure there's something I'm doing wrong... but what? Thanks! -- Benjamin
Tuesday, February 19, 2008 12:05 AM
Answers
-
Unni Ravindranathan (MS) - 5/10/2006 10:42 PM PST
Hi Benjamin,
Sorry for the late reply - I was kept busy most of the day :).
The difference between the HTML world and here is that your application
needs to be built (compiled, etc.) before it is run. So what you may see as
relative at the time of designing the application may not be so from the
location where the built executable is located.
I think what you want to do (which we don't support as far as authoring is
concerned) is to link to a folder. As an example, check out the Project ->
Link to existing item menu. What this does is that it lets you specify a
"link" to an image on your disk which is relative to your project. Check
that out and check out what changes are made to your .csproj as a result.
You can then change this to include entire folders this way (by replacing
foo.jpg with *.jgp). This is useful if you are exporting from a tool which
is producing a bunch of rasterized images, and each time you export from the
tool, you don't want to go thru this process of updating the project file.
Once this is done, you will notice that you can now use relative paths in
your XAML files AND the image will be available for deployment as well.
I plan to write a small article around this at some point, and how this will
affect the designer scenarios.
Thanks,
-Unni
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Benjamin" <Benjamin@discussions.microsoft.com> wrote in message
news:594CAA0D-61E7-4B6E-8EFC-D98D1615F8C2@microsoft.com...
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:34 AM
All replies
-
By: Benjamin - 5/9/2006 4:27 AM PST
I'm sorry, I haden't seen it had been posted a few hours ago (and the search
engine doesn't seem to work very well...).
But I still have got a question:
I do not want to add every picture I will display in my project, I just want
to display them... let's say... as ACDSee or Picasa does...
I have to use relative paths without addin all the files to my project...
Is it possible (I'm sure the answer is "Yes")... and how (that's the
interesting part of the answer :-) )?
--
Benjamin
"Benjamin" wrote:
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:29 AM -
By: Unni Ravindranathan (MS) - 5/9/2006 12:23 PM PST
Hi Benjamin,
As you said, it is indeed possible. However, it would like to know your
scenario better. Can you describe where the files will be located relative
to the project, how the folder structures on disk will look like, how you
want your deployment to look like, etc?
It is possible to copy a folder to an output directory, or embed all the
files in a folder as a resource rather than pick on them individually, etc.
However, when you talk about relative paths, what is relative to the design
surface will not be relative at the time of running the application. So if
you don't make right tweaks to your project file, you will find that things
might work at design time and not at run-time, and vice versa. Knowning your
scenario might help.
Thanks,
-Unni
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Benjamin" <Benjamin@discussions.microsoft.com> wrote in message
news:5561C8A3-7DE8-42AD-A9EF-7E5FAC33D241@microsoft.com...
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:30 AM -
By: Benjamin - 5/10/2006 12:36 AM PST
OK, let's say:
- I have got a ".\pictures" folder in my root directory.
- I want to display the picture ".\pictures\myPicture.png" in my application
(using an Image control).
- But I don't want to import the file myPicture.png in my project because
this file will change (for instance, in order to do a skin).
I thought I could use a "web-style" path saying that the soucre of the
picture I want to display is ".\pictures\myPicture.png".
It's not working unless I put the real path
"C:\myProjectFolder\pictures\myPicture.png".
Is the decription of the problem OK this time?
thaaanks...
--
BenjaminTuesday, February 19, 2008 1:32 AM -
Unni Ravindranathan (MS) - 5/10/2006 10:42 PM PST
Hi Benjamin,
Sorry for the late reply - I was kept busy most of the day :).
The difference between the HTML world and here is that your application
needs to be built (compiled, etc.) before it is run. So what you may see as
relative at the time of designing the application may not be so from the
location where the built executable is located.
I think what you want to do (which we don't support as far as authoring is
concerned) is to link to a folder. As an example, check out the Project ->
Link to existing item menu. What this does is that it lets you specify a
"link" to an image on your disk which is relative to your project. Check
that out and check out what changes are made to your .csproj as a result.
You can then change this to include entire folders this way (by replacing
foo.jpg with *.jgp). This is useful if you are exporting from a tool which
is producing a bunch of rasterized images, and each time you export from the
tool, you don't want to go thru this process of updating the project file.
Once this is done, you will notice that you can now use relative paths in
your XAML files AND the image will be available for deployment as well.
I plan to write a small article around this at some point, and how this will
affect the designer scenarios.
Thanks,
-Unni
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Benjamin" <Benjamin@discussions.microsoft.com> wrote in message
news:594CAA0D-61E7-4B6E-8EFC-D98D1615F8C2@microsoft.com...
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:34 AM -
By: Benjamin - 5/10/2006 11:57 PM PST
OK, thanks for the answer... I'll try to do something like this...
--
Benjamin
"Unni Ravindranathan (MS)" wrote:
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:35 AM -
By: Benjamin - 5/10/2006 11:59 PM PST
Thanks for the answer... I'll try this solution.
--
Benjamin- Edited by Expression Newsgroup Migrator1 Tuesday, February 19, 2008 1:36 AM changed font
Tuesday, February 19, 2008 1:36 AM -
By: Benjamin - 5/11/2006 12:00 AM PST
Thanks for the answer, I'll try this solution
--
Benjamin
"Unni Ravindranathan (MS)" wrote:
Click to show or hide original message or reply text.Tuesday, February 19, 2008 1:38 AM -
By: Benjamin - 5/11/2006 12:00 AM PST
Thanks for the answer, I'll try this solution
--
BenjaminTuesday, February 19, 2008 1:39 AM