Solved

Why am I pointing to two different directory paths in the following C# code and how can I resolve it?

Posted on 2016-08-30
1
53 Views
Last Modified: 2016-08-31
I am writing a C# application using .Net Framework 4.0

I have a snippet of code as follow in my program:

Why am I pointing to two different directory paths in the following code?

The filenames are the same.

My correct path is defined by TARGET_DIR_IN

However, "File.ReadAllBytes(fileName)" defines the path as "\\m\USERS\z\My Documents\Visual Studio 2010\Projects\W\bin\Debug\20160824.ard.out'"             as I can tell from the debugger.

------------------
const string TARGET_DIR_IN = @"\\v\na\ctrls\dev\W\data\Test\";

string[] files = Directory.GetFiles(TARGET_DIR_IN, "*.out", SearchOption.TopDirectoryOnly);
            foreach (string file in files)
            {
                string fileName = Path.GetFileName(file);
                byte[] imgBits = File.ReadAllBytes(fileName);
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 41777515
Because the GetFileName returns the file name from the supplied string.  You are stripping the path out.
https://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.110).aspx

The string 'file' should be the complete path to the file which I think is what you want.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help converting bitmap to image in VB.Net 8 45
I need help adding validation to my MVC.Net view 6 21
C# Windows Form Navigation - Total Beginner 9 46
c#, case, if 4 19
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question