locked
Could not find a part of the path

    Question

  • I run an application on the server, get this error "Could not find a part of the path".

    The partial code is

    string outPath = @"\2222-ffff\Data\Work\BMS";
            string chrName = "chr{0}.psd";
            FileWriter[] fwChr = new FileWriter[45];
            for (int i = 0; i < fwChr.Length; i++)
            {
              fwChr[i] = new FileWriter(Path.Combine(outPath, string.Format(chrName, i + 1)));
              
            }
    
    Thanks for help.
    Wednesday, November 24, 2010 5:15 PM

Answers

  • Are you sure C:\Test\BMS exists?
    • Marked as answer by ardmore Thursday, November 25, 2010 2:49 PM
    Thursday, November 25, 2010 2:36 PM
  • Resloved it already. My fault.
    • Marked as answer by ardmore Friday, November 26, 2010 11:28 PM
    Friday, November 26, 2010 11:27 PM

All replies

  • string outPath = @"\2222-ffff\Data\Work\BMS";
    //add a disc and change to:
    string outPath = @"C:\2222-ffff\Data\Work\BMS"; //or some other disc drive
    

    
    
    Wednesday, November 24, 2010 5:20 PM
  • No. 2222-ffff is root already.
    Wednesday, November 24, 2010 5:40 PM
  • Hi ardmore,

    Your statement is very unclear. Can you provide more details about the problem?

    I imagine 2 possible options from what you've told us.

    1. You're running the application from file share - this means application is located on server, but executed on your local machine
    2. You're running the application straight on your server - this means server and client is the same machine

    Which of those scearios are you usings (if any)?


    Regards,
    Danijel

    Blog, Twitter
    Wednesday, November 24, 2010 9:37 PM
  • Maybe you should combine path and a file name together (to get a full path of the file - now there is no full path).
    Wednesday, November 24, 2010 10:47 PM
  • string
     outPath = @"\2222-ffff\Data\Work\BMS"
    ;

    here u missed the root directory drive letter.
    u can give the path like this:

    string outPath = @"C: \2222-ffff\Data\Work\BMS" ;

    If drive letter is missed in path, u will get an error like 'Could not find the part of the path'

    Hope this helps...


    Thanks, Srinivasa Rao Dhulipalla
    Thursday, November 25, 2010 5:57 AM
  •  

    Hi ardmore,

     

    Welcome to MSDN Forums!

     

    Can you post out a copy of the whole error message?

    I'm not a web application expert, and this code seems is a web application, is it right?

    The whole error message may be can help us narrow down this problem, and find the root cause, then we can make a suitable solution to help you solve this issue.

     

    And I think the following article may be helpful for you to solve your problem.

    ASP.NET Web Project Paths

    Converting a Virtual Path into a Physical Path

    The MapPath method returns the complete physical path for a virtual path that you pass to the method. For example, the following code returns the file path for the root of your Web site:

    String rootPath = Server.MapPath("~");
    

     

    You can combine your path after this root path, and then use this path to access files.

     

    If there's anything unclear or there's anything I had misunderstood, please feel free to let me know.

     

    Have a nice day!

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the other community members reading the thread.

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Thursday, November 25, 2010 6:28 AM
  • If you start a path with a "\", it will start at the root of the current working drive, which could  be any drive.

    You can check your CWD by calling Directory.GetCurrentDirectory().

    Thursday, November 25, 2010 10:26 AM
  • Okay. I just test it on the C driver.

    string inputFile = @"C:\Test\FinalReport";
            string outPath = @"C:\Test\BMS";
            string chrName = "chr{0}.ped";
            FileWriter[] fwChr = new FileWriter[23];
            for (int i = 0; i < fwChr.Length; i++)
            {
              fwChr[i] = new FileWriter(Path.Combine(outPath, string.Format(chrName, i + 1)));
            }
    The exception message is  {"Could not find a part of the path 'C:\\Test\\BMS\\chr1.ped'."} System.Exception {System.IO.DirectoryNotFoundException}
    Thursday, November 25, 2010 2:17 PM
  • Okay. I just test it on the C driver.

    string inputFile = @"C:\Test\FinalReport";
            string outPath = @"C:\Test\BMS";
            string chrName = "chr{0}.ped";
            FileWriter[] fwChr = new FileWriter[23];
            for (int i = 0; i < fwChr.Length; i++)
            {
              fwChr[i] = new FileWriter(Path.Combine(outPath, string.Format(chrName, i + 1)));
            }
    The exception message is  {"Could not find a part of the path 'C:\\Test\\BMS\\chr1.ped'."} System.Exception {System.IO.DirectoryNotFoundException}
    Thursday, November 25, 2010 2:17 PM
  • This error says the path is not valid. Please check the path and the file name to which you would like to access.

     

    btw. what is this, a file?: string chrName = "chr{0}.ped";

    Thursday, November 25, 2010 2:32 PM
  • Are you sure C:\Test\BMS exists?
    • Marked as answer by ardmore Thursday, November 25, 2010 2:49 PM
    Thursday, November 25, 2010 2:36 PM
  • What were we telling you? lol
    Thursday, November 25, 2010 5:33 PM
  •  

    Hi ardmore,

     

    Do you mean that your problem had been solved? And the root cause is the directory is not existing?

     

    If there's anything unclear or there's anything I had misunderstood, please feel free to let me know.

     

    Have a nice day!

    Mike

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Friday, November 26, 2010 2:14 AM
  • Resloved it already. My fault.
    • Marked as answer by ardmore Friday, November 26, 2010 11:28 PM
    Friday, November 26, 2010 11:27 PM
  • Hi ardmore,

     

    I'm glad to hear that the problem had been solved. Welcome back if there's any problem in future programming.

     

    Have a nice day!

    Mike

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Saturday, November 27, 2010 5:12 AM