?
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
Medium Priority
?
66 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

741 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