DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Windows Phone 7 Tip Of The Day: Call resources by their absolute path

Denzel D. user avatar by
Denzel D.
·
Mar. 04, 11 · Interview
Like (0)
Save
Tweet
Share
8.41K Views

Join the DZone community and get the full member experience.

Join For Free

There are situations when developers need to call specific resources only by their absolute path. Of course, this situation mostly applies to cases when web resources are invoked (on Windows Phone 7 this is extremely fenced), but can also be applied to local (built-in) entities. So what do you do in this case?

a) host the resource somewhere and then invoke it

b) access it locally via an absolute path

If you answered a, then you are thinking in the wrong context here - Windows Phone 7 won't allow the developer to invoke remote resources directly through an Uri (e.g. to set an image). The second method doesn't seem quite plausible, though.

The limitation here consists in the fact that the actual application path (relative to the phone file system) is hidden by default - there is no way it can be obtained by using standard methods - the developer is limited to the existing resource access layer and the isolated storage. This, however, doesn't mean that undocumented features can't be used. Chris Walshie discovered that the default App.Current.Host implementation carries a hidden property, that shows the path to the application folder.

A simple method call for it will reveal it (given that a breakpoint is set at the work line):

App.Current.Host.GetType();

In my case, I get this:

file:///Applications/Install/4FFA38B5-00AF-4760-A7EB-7C0C0BC1D31A/Install/

Remember that the GUID will ultimately change depending on the application.

So, if I want to access a specific image from my Resources folder (given that it's copied there and is set to be of type Content), I can use a snippet like this:

string imagePath = "file:///Applications/Install/4FFA38B5-00AF-4760-A7EB-7C0C0BC1D31A/Install/Resources/dice.png";
BitmapImage image = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
testImage.Source = image;

There is one but here. Try guessing whether this will work or not:

XDocument doc = XDocument.Load("file:///Applications/Install/4FFA38B5-00AF-4760-A7EB-7C0C0BC1D31A/Install/Resources/feed.xml");

The answer is no - an exception will be thrown anyway:

BitmapImage doesn't really see a problem downloading an image, therefore it is possible to use an absolute URL to an online resource (image) and it will still accept it. On the other hand, XDocument is restricted to local resources and therefore will only accept a relative URI as a possible parameter.

Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • HTTP vs Messaging for Microservices Communications
  • Fargate vs. Lambda: The Battle of the Future
  • Cloud Performance Engineering
  • Spring Boot vs Eclipse MicroProfile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: