Last post Sep 21, 2011 02:54 PM by Deadveloper
Sep 20, 2011 04:20 PM|Deadveloper|LINK
What I am trying to do is: I have 3 apps that all use the same connection strings and app settings. So what I did in my web.config file was to add this.
So there is a folder called ProdConfig in each app that holds AppSettings.xml and ConnectionStrings.xml. I get those values from the file.
I am creating a new app that will allow us to read, modify, and save the files back.
The file I am reading is a local file to the new app and is a .txt file. I tried .xml but when it renders I cannot modify the contents.
I have it opening and saving the .txt file.
What I need to do now is to upload the doc to the other server in that Prod folder, but as a xml file so it can be read by the web.config.
How can I transform this to a .xml file and upload WITHOUT using the upload control and to a different server?
Sep 20, 2011 05:52 PM|Aminjun|LINK
Unfortunately I couldn't understand what was the problem.
You have a problem reading the file or manipulate it's content? Or your problem is about saving the file with .xml extension?
Please post your code if you think it's needed.
Sep 20, 2011 06:01 PM|Anton Palyok|LINK
For creating xml you can use two classes:
2) XDocument (part of LINQ):
Also you can upload your file using class HttpWebRequest:
And can find some examples by folowing link:
Sep 20, 2011 06:20 PM|Deadveloper|LINK
I was able to get the app to upload the file to the correct location by using a UNC share as a start.
So I have it all working except for one little problem.
After it saved the file, I went to look at it to verify that the changes were there, and they are BUT all < characters were replaced with < and all the > characters were replaced with >.
It did not show those values when I debug and hover over the content variable, it still shows the < or >.
Is there a way to encode this so it doesn't change?
Sep 21, 2011 04:36 AM|Anton Palyok|LINK
In the text of xml next symbols should be encoded:
only xml tags can contain symbols < and >. But other text should encode this symbols.
Later you can decode back this symbols if needed by using HttpUtility.HtmlDecode Method:
Sep 21, 2011 11:42 AM|Deadveloper|LINK
Perhaps you misunderstand me.
I do not want the symbols encoded to look like & and so on.
I want them to look like < or > and so on.
Sep 21, 2011 11:50 AM|Anton Palyok|LINK
I think that in your case encoding occurred when you read text file and create xml.
Try to investigate that place.
Also you can use method HttpUtility.HtmlDecode(myString) to retrieve symbol "<" from "<" etc.
Sep 21, 2011 11:59 AM|Deadveloper|LINK
The web.config is retrieveing the file not me.
So it has to have the < or the >.
Sep 21, 2011 02:54 PM|Deadveloper|LINK
I solved my issue by opening a FileStream, StreamWriter, and StreamReader.
I open the file and read it into a string so I can do a Replace.
Then I write it back.