Question

At the moment I'm pointing to a file on my machine, but I'm wondering how I would point the string to a folder I created within the project. For example the path to the folder in visual studio is,

C:\Users\Drian Darley\documents\visual studio 2013\Projects\KinectBVversion1\KinectKickboxingBVversion1\Gesture\jabtwo.xml 

I have heard of pack URI's, would that suit in this situation or how would I set one up?

This is how it is pointing to the file at present, which is not ideal as it has to point to a file stored locally on the machine.

private string gesturefile =
            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GesturePak\\wave.xml";
Was it helpful?

Solution

Try like this

string gesturefile= Path.Combine(Environment.CurrentDirectory, @"GesturePak\wave.xml");

Examples:

http://msdn.microsoft.com/en-us/library/fyy7a5kt(v=vs.110).aspx http://www.dotnetperls.com/path

or

Use Path.GetFullPath

Example : http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx

OTHER TIPS

If you do not want to store files separately you need to set their Build Action to Resource (in the Properties window in Visual Studio) and access them by a Pack URI:

var uri = new Uri("pack://application:,,,/GesturePAK/wave.xml");
var resourceStream = Application.GetResourceStream(uri).Stream;

Now you can access the content of the XML file by resourceStream. For example reading the file content into a string could be done like this:

string content;
using (StreamReader reader = new StreamReader(resourceStream, Encoding.UTF8))
{
    content = reader.ReadToEnd();
}

for example, if you create a folder called "Images" within your project, then you can point like:

string address="Images/dukenukem.jpg";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top