Saturday, September 1, 2012

Correct Way to use Relative Path to Access a file in Client Bin in a Silverlight Application

Correct Way to use Relative Path to Access a file in Client Bin in a Silverlight Application

I have a WCF Service that I call from the client of my silverlight application, and I pass it a string filename parameter and a string parameter containing xml. In the service method I construct an XDocument instance containing the xml string, and then save it to a file in the ClientBin folder on the server. I have been using an absolute path, and now am trying to switch to a relative path, but am unsure how to do it correctly. My code looks like this:

public void WriteXmlToServer(string filename,string xmlString) {     //xml document to hold the information for the group that is registered     XDocument xDoc = new XDocument(XDocument.Parse(xmlString.ToString()));       XDocument DataInFile = new XDocument();      try     {         xDoc.Save(Path.Combine("..\\ClientBin\\", filename));         //the complete absolute path to the .xml file ->C:\Users\Me\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1.sln            }     catch (FileNotFoundException e)     {              Console.WriteLine(e.InnerException.ToString());     } } 

I am currently getting this exception message:

System.IO.DirectoryNotFoundException was unhandled by user code   HResult=-2147024893   Message=Could not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\ClientBin\ServerGroups.xml'. 

Could someone please instruct me on the correct way to use a relative path to a file in the client bin in a Silverlight application? Thanks in advance for the assistance.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog