2
Reply

C# access a file

dc

dc

Sep 17 2012 2:38 PM
1.3k

In a C# 2008 console application, I have a line of code that fails a try catch block.

The line of code is:
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

The wholse section of code looks like:
   public Attachment AttIputDoc(String custId, String fileName)
         {

            Attachment att = new Attachment();
             byte[] buffer = null;
             try
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
catch (Exception e)
     {
     }
The line of code is trying to access a file that does not exist in a specific location.

Can you tell me how the code listed above knows where the directory path is for the file that needs to get uploaded at? The place it thinks the file needs to be loaded from is where the source code of where the application is acutally running from.

How would I override the default location so I can obtain the value from the app.config file?

Answers (2)