Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Double backslashes appearing in string path C#

Posted on 2011-02-12
6
Medium Priority
?
2,657 Views
Last Modified: 2016-10-14
I have a application that was working perfectly, i have just moved my website to a different server and the save path of created xml files has changed, instead of having it hard coded, i decided to place the path in the appsettings so i could edit it in the future if the path ever changed again, without having to recompile.

my problem is that when the path is getting picked up from the web config, the backslashes are being duplicated and the application doesnt see the path as a legitimate windows path giving the following error

The given path's format is not supported.

How can i stop this from happening.

Code in webconfig

      <appSettings>
            <add key="SaveLocation" value="c:\home\c\o\complus\www\"/>
      </appSettings>

picked up in the code like so:

string savelocation = System.Configuration.ConfigurationManager.AppSettings["SaveLocation"].ToString();
0
Comment
Question by:QuinnDester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:s_chilkury
ID: 34878706
Access the variable savelocation prefixing @.

Also check if the path is evaluating to the right location by debugging/logging it at the savelocation path assignment.
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 34878724
like this?

string savelocation = System.Configuration.ConfigurationManager.AppSettings[@("SaveLocation")].ToString();
0
 
LVL 1

Accepted Solution

by:
barbessio earned 2000 total points
ID: 34878743
No, like:
      <appSettings>
            <add key="SaveLocation" value=@"c:\home\c\o\complus\www\"/>
      </appSettings>

Open in new window


Hope it helped :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:QuinnDester
ID: 34878789
Thanks... I didnt think it needed that in the webconfig xml as it isnt compiled

Ill give it a go and let you know
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 34878810
I have fixed it...

it wasnt the duplicated backslashes causing the problem, it still shows them but must be an issue with the debugger..

the problem was this line

string xmlpostfix = ( HttpContext.Current.Request.ServerVariables["HTTP_HOST"]);

as i was running it in debugger that was evaluating as localhost:nameofserver, this was creating an invalid file name, i hard coded a url in its place and it works perfectly

Thanks for trying.
0
 

Expert Comment

by:Curtis Brooks
ID: 41843954
I too am having this problem.  Placing and "@" in the web.config does not work. It actually produces an error in the web.config file.

I am trying to retrieve local path data from the web.config file and C# is adding \ slashes to everything so that an item in the web.config that reads
    <add key="DevCromerrCorUrl" value="\\devdotnet\wwwroot\air\CROMERR_COR\"/>
is returned to the method as "\\\\devdotnet\\wwwroot\\air\\CROMERR_COR\\"

Is this some subtle way that microsoft tries to tell us not to use these sort of things in web programming? By the way we are using server 2012 R2

cb
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question