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. Cannot Resolve Path Error

Cannot Resolve Path Error

Scheduled Pinned Locked Moved C#
csharplinqhelptutorialquestion
16 Posts 10 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.
  • P Pete OHanlon

    BobJanova wrote:

    .Net allows the separator to go either way.

    There are soooooo many jokes just crawling all over that statement.

    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

    B Offline
    B Offline
    BobJanova
    wrote on last edited by
    #6

    Yes, but this is a serious forum, so I thought it would be okay :-\

    P 1 Reply Last reply
    0
    • B BobJanova

      Yes, but this is a serious forum, so I thought it would be okay :-\

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #7

      BobJanova wrote:

      Yes, but this is a serious forum,

      Is it? Good gravy man, that's news to me.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      1 Reply Last reply
      0
      • P Peter_in_2780

        You need to learn about character escaping in strings.

        computerpublic wrote:

        byte[] data = File.ReadAllBytes("c:\tempPath");

        That string is (shown 1 character per line for clarity)

        c
        :
        tab character (\t)
        e
        m
        p
        P
        a
        t
        h

        What you probably mean is "c:\\tempPath" . While you are at it, read up on Unicode. Peter

        Software rusts. Simon Stephenson, ca 1994.

        C Offline
        C Offline
        computerpublic
        wrote on last edited by
        #8

        Peter, When I make it ("C:\\tempPath", it gives me the following error: Unhandled Exception: System.IO.FileNotFoundException: Could not find file 'c:\te mpPath'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea n useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllBytes(String path) at ConsoleApplicationTEST2.Program.Main(String[] args) in C:\Users\computerpu blic\Desktop\ConsoleApplicationTEST2\ConsoleApplicationTEST2\Program.cs:line 18 Press any key to continue . . .

        Z 1 Reply Last reply
        0
        • C computerpublic

          I wrote this small program from an example in the C# book and it compile fine, but gives a path error for the file that I am reading. I created an external file at c:\tempPath Can someone please advise? Thanks. using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplicationTEST2 { class Program { static void Main(string[] args) { string tempPath = Path.GetTempFileName(); string tempPath2 = Path.GetTempFileName(); if (File.Exists(tempPath)) { byte[] data = File.ReadAllBytes("c:\tempPath"); File.WriteAllBytes(tempPath2, data); Console.WriteLine("First byte: {0}", data[0]); Console.WriteLine("Last byte: {0}", data[data.Length]); Console.WriteLine(data.Length); } } } } OUTPUT: Unhandled Exception: System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path) at System.IO.Path.GetFileName(String path) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllBytes(String path) at ConsoleApplicationTEST2.Program.Main(String[] args) in C:\Users\computerpu blic\Desktop\ConsoleApplicationTEST2\ConsoleApplicationTEST2\Program.cs:line 20 Press any key to continue . . .

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #9

          It looks like you want to 'copy' a file from one directory to another. You give it 2 arguments: source and destination. correct? In that case I would rather go for:

          byte[] data = File.ReadAllBytes(tempPath);

          "C:\tempPath" denotes a directory ,not a file. PS: note that the other comments are valid, the \ backslash character needs to be escaped as follows.

          "C:\\tempPath\\"
          //or
          @"C:\tempPath\"
          //I would not use this: "C:/tempPath/", the / character is used in URL's and might work confusing.

          Another thing is see going wrong is this line:

          Console.WriteLine("Last byte: {0}", data[data.Length]);

          //it should be
          Console.WriteLine("Last byte: {0}", data[data.Length-1]);
          //or it will give you an IndexOutOfBounsException

          Hope this helps.

          V.

          1 Reply Last reply
          0
          • C computerpublic

            I wrote this small program from an example in the C# book and it compile fine, but gives a path error for the file that I am reading. I created an external file at c:\tempPath Can someone please advise? Thanks. using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplicationTEST2 { class Program { static void Main(string[] args) { string tempPath = Path.GetTempFileName(); string tempPath2 = Path.GetTempFileName(); if (File.Exists(tempPath)) { byte[] data = File.ReadAllBytes("c:\tempPath"); File.WriteAllBytes(tempPath2, data); Console.WriteLine("First byte: {0}", data[0]); Console.WriteLine("Last byte: {0}", data[data.Length]); Console.WriteLine(data.Length); } } } } OUTPUT: Unhandled Exception: System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path) at System.IO.Path.GetFileName(String path) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllBytes(String path) at ConsoleApplicationTEST2.Program.Main(String[] args) in C:\Users\computerpu blic\Desktop\ConsoleApplicationTEST2\ConsoleApplicationTEST2\Program.cs:line 20 Press any key to continue . . .

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #10

            computerpublic wrote:

            static void Main(string[] args)

            string tempPath = Path.GetTempFileName();
            string tempPath2 = Path.GetTempFileName();
            if (File.Exists(tempPath))
            {
            byte[] data = File.ReadAllBytes("c:\tempPath");

            Oh my. 1. As Path.GetTempFileName() tries to provide you with a randomly chosen file name in order NOT to clash with existing files, how on earth do you expect File.Exists() to ever return true? 2. Code should be put inside PRE tags, to preserve formatting and improve readability. 3. And if there is some code sitting in between both method calls, you really should have indicated so. 4. There is absolutely no relation between a variable called tempPath, and a file path with the value @"C:\tempPath". Did you skip your morning coffee? :confused:

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            C P 2 Replies Last reply
            0
            • C computerpublic

              Peter, When I make it ("C:\\tempPath", it gives me the following error: Unhandled Exception: System.IO.FileNotFoundException: Could not find file 'c:\te mpPath'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea n useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.ReadAllBytes(String path) at ConsoleApplicationTEST2.Program.Main(String[] args) in C:\Users\computerpu blic\Desktop\ConsoleApplicationTEST2\ConsoleApplicationTEST2\Program.cs:line 18 Press any key to continue . . .

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #11

              That's because it is a directory. You need to point to a file.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              1 Reply Last reply
              0
              • L Luc Pattyn

                computerpublic wrote:

                static void Main(string[] args)

                string tempPath = Path.GetTempFileName();
                string tempPath2 = Path.GetTempFileName();
                if (File.Exists(tempPath))
                {
                byte[] data = File.ReadAllBytes("c:\tempPath");

                Oh my. 1. As Path.GetTempFileName() tries to provide you with a randomly chosen file name in order NOT to clash with existing files, how on earth do you expect File.Exists() to ever return true? 2. Code should be put inside PRE tags, to preserve formatting and improve readability. 3. And if there is some code sitting in between both method calls, you really should have indicated so. 4. There is absolutely no relation between a variable called tempPath, and a file path with the value @"C:\tempPath". Did you skip your morning coffee? :confused:

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                C Offline
                C Offline
                computerpublic
                wrote on last edited by
                #12

                I changed the file name to "c:\\temp" and it still does not work.

                Richard Andrew x64R 1 Reply Last reply
                0
                • C computerpublic

                  I changed the file name to "c:\\temp" and it still does not work.

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #13

                  The file name is stored in your variable tempFile. Why are you giving it a string literal that says "C:\tempFile"? Try

                  byte[] fileData = File.ReadAllBytes(tempFile);

                  The difficult we do right away... ...the impossible takes slightly longer.

                  1 Reply Last reply
                  0
                  • P Peter_in_2780

                    You need to learn about character escaping in strings.

                    computerpublic wrote:

                    byte[] data = File.ReadAllBytes("c:\tempPath");

                    That string is (shown 1 character per line for clarity)

                    c
                    :
                    tab character (\t)
                    e
                    m
                    p
                    P
                    a
                    t
                    h

                    What you probably mean is "c:\\tempPath" . While you are at it, read up on Unicode. Peter

                    Software rusts. Simon Stephenson, ca 1994.

                    P Offline
                    P Offline
                    ProEnggSoft
                    wrote on last edited by
                    #14

                    5! :thumbsup:

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Yeah, what he said. Or you could use a verbatim string -- @"c:\tempPath" .

                      P Offline
                      P Offline
                      ProEnggSoft
                      wrote on last edited by
                      #15

                      5! :thumbsup:

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        computerpublic wrote:

                        static void Main(string[] args)

                        string tempPath = Path.GetTempFileName();
                        string tempPath2 = Path.GetTempFileName();
                        if (File.Exists(tempPath))
                        {
                        byte[] data = File.ReadAllBytes("c:\tempPath");

                        Oh my. 1. As Path.GetTempFileName() tries to provide you with a randomly chosen file name in order NOT to clash with existing files, how on earth do you expect File.Exists() to ever return true? 2. Code should be put inside PRE tags, to preserve formatting and improve readability. 3. And if there is some code sitting in between both method calls, you really should have indicated so. 4. There is absolutely no relation between a variable called tempPath, and a file path with the value @"C:\tempPath". Did you skip your morning coffee? :confused:

                        Luc Pattyn [My Articles] Nil Volentibus Arduum

                        P Offline
                        P Offline
                        ProEnggSoft
                        wrote on last edited by
                        #16

                        5! :thumbsup:

                        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