views:

428

answers:

1

Hello everyone,

I find when reading from a local file from Silverlight, we have to use special path separator "/" other than normal path separator "\" or else Silverlight can not get related local file, for example we need to write as c:/test/abc.wmv, other than write as c:\test\abc.wmv.

Two more questions,

  1. Any simple solution to use normal file separator?

  2. C# File/FileInfo class will use normal path separator to represent a file name (full path name), how to change all the normal path separator into this special path separator so that Silverlight could recognize?

I am using VSTS 2008 + C# + .Net 2.0.

thanks in advance, George

+2  A: 

You could use an Extension Method:

public string ToSilverlightPath(this string s)
{
  return s.Replace("\\", "/");
}

or

public string ToSilverlightPath(this Path p)
{
  return p.GetFullPath().Replace("\\", "/");
}

Edit:

After thinking about it some more Silverlight probably works with URIs'.
That is, all paths in Silverlight are URIs'.
So instead of using Path you should probably use Uri, like:

Uri mySilverlightPath = new Uri(myPathString);

or

Uri mySilverlightPath = new Uri(myPath.GetFullPath());

Not sure about this though but I guess it would make sense.

Sani Huttunen
Thanks CKret, any ideas how to make Silverlight recognize normal path separator?
George2
Well haven't worked with Silverlight but I thought about it some more and edited the post with my thoughts.
Sani Huttunen
But how to get the input value for myPathString? Using separator \ or using separator /?
George2
Whichever you prefer. If you use \ the Uri changes it to / automatically.
Sani Huttunen