Passing A String
-
Hi, I am setting a Property in a class using the following: xmloutput.FileName = @"c\projects\text.xml"; Then I use the following to open a new XMLTextWriter; XmlTextWriter xmlWriter = new XmlTextWriter(_FileName, System.Text.Encoding.UTF8); However the Filename gets changed to : D:\\My Documents\\Visual Studio 2005\\Projects\\Scanner\\Scanner\\bin\\Debug\\c\\projects\\text.xml I cannot understand why the D:\\ etc gets put onto the front of the string. Any help would be appreciated
-
Hi, I am setting a Property in a class using the following: xmloutput.FileName = @"c\projects\text.xml"; Then I use the following to open a new XMLTextWriter; XmlTextWriter xmlWriter = new XmlTextWriter(_FileName, System.Text.Encoding.UTF8); However the Filename gets changed to : D:\\My Documents\\Visual Studio 2005\\Projects\\Scanner\\Scanner\\bin\\Debug\\c\\projects\\text.xml I cannot understand why the D:\\ etc gets put onto the front of the string. Any help would be appreciated
-
Hi, I am setting a Property in a class using the following: xmloutput.FileName = @"c\projects\text.xml"; Then I use the following to open a new XMLTextWriter; XmlTextWriter xmlWriter = new XmlTextWriter(_FileName, System.Text.Encoding.UTF8); However the Filename gets changed to : D:\\My Documents\\Visual Studio 2005\\Projects\\Scanner\\Scanner\\bin\\Debug\\c\\projects\\text.xml I cannot understand why the D:\\ etc gets put onto the front of the string. Any help would be appreciated
Because the sting you are passing isn't a valid path so your program thinks it is a relative path and appends it to the current directory of your application.
Giorgi Dalakishvili #region signature my articles #endregion
-
Not sure if this is 100% the issue, but I'm assuming 'c' is a drive and not a folder. Set the filename to @"C:\\projects\\text.xml"
He who makes a beast out of himself gets rid of the pain of being a man
When you put a @ in front of the string you don't need \\ to get a \. But otherwise it's correct. There is a : missing in the path.
-
Because the sting you are passing isn't a valid path so your program thinks it is a relative path and appends it to the current directory of your application.
Giorgi Dalakishvili #region signature my articles #endregion
-
When you put a @ in front of the string you don't need \\ to get a \. But otherwise it's correct. There is a : missing in the path.
-
Hi, Thanks for the responses. However, c:\projects does exist on my PC and I have also tried @c:\\projects but am still getting the same problem. However if I hard code as in the following it works fine. XMLDoc.Save(@"c:\projects\text.xml")
May be it is taking what you gave in the xmlDoc.FileName as the FILENAME and not the actual path. So the batch will be now [Default solutionpath]\FileName. In the lter case the Save accepts the actuall path to the file and works fine. May be you can try storing the path differently nad get it to the scene only in the save function
Thanks Laddie Kindly rate if the answer was helpful
-
Hi, Thanks for the responses. However, c:\projects does exist on my PC and I have also tried @c:\\projects but am still getting the same problem. However if I hard code as in the following it works fine. XMLDoc.Save(@"c:\projects\text.xml")
c:\projects is a folder, not a file so how can xmlwriter write to it? You need to specify file path. If you need to path of folder for something else try this: @C:\projects\
Giorgi Dalakishvili #region signature my articles #endregion
-
Hi, I am setting a Property in a class using the following: xmloutput.FileName = @"c\projects\text.xml"; Then I use the following to open a new XMLTextWriter; XmlTextWriter xmlWriter = new XmlTextWriter(_FileName, System.Text.Encoding.UTF8); However the Filename gets changed to : D:\\My Documents\\Visual Studio 2005\\Projects\\Scanner\\Scanner\\bin\\Debug\\c\\projects\\text.xml I cannot understand why the D:\\ etc gets put onto the front of the string. Any help would be appreciated
Simple problem. See if you can spot the difference: xmloutput.FileName = @"c\projects\text.xml"; xmloutput.FileName = @"c:\projects\text.xml"; In essence the path you specified is not what you had intended. You meant to specify an absolute path. The compiler didn't detect the drive (c:) and treats the whole thing as path relative to wherever the application is being run from. In your case the bin\Debug.