Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing A String

Passing A String

Scheduled Pinned Locked Moved C#
csharpvisual-studiodebuggingxmlhelp
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solent
    wrote on last edited by
    #1

    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

    P G N 3 Replies Last reply
    0
    • S solent

      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

      P Offline
      P Offline
      phannon86
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • S solent

        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

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • P phannon86

          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

          C Offline
          C Offline
          Christian Wikander
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            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

            S Offline
            S Offline
            solent
            wrote on last edited by
            #5

            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")

            L G 2 Replies Last reply
            0
            • C Christian Wikander

              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.

              S Offline
              S Offline
              solent
              wrote on last edited by
              #6

              Thanks everyone I could not see the wood for the trees. Just spotted the : missing. Thanks again

              1 Reply Last reply
              0
              • S solent

                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")

                L Offline
                L Offline
                Laddie
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • S solent

                  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")

                  G Offline
                  G Offline
                  Giorgi Dalakishvili
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • S solent

                    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

                    N Offline
                    N Offline
                    nelo_
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups