1

I have an strange problem I have an app that scan a directory and gets a list of files. it processes each file by reading it and doing some stuff. it works fine in the development computer but when I deploy it to the client it gives me the error. Here is the code

public void ProcessIMFiles()
    {
        DirectoryInfo di = new DirectoryInfo(Globals.ITMDIR);
        FileInfo[] Files = di.GetFiles("*.txt");            
        foreach(FileInfo file in Files)
        {
            try
            {
                processThisIMFile(file.FullName);
                movefile(file.FullName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("error : " + ex.Message);
            }
        }
    }

The error happens in the call to processThisIMFile(file.FullName) see below. Globals.ITMDIR is a valid path.

private void processThisIMFile(string FileName)
    {
        string[] Fields = null;
        setconnection();
        DataTable dt = null;
        try
        {
            string[] Lines = System.IO.File.ReadAllLines(FileName);

            foreach (string line in Lines)
            {
                Fields = line.Split(Globals.delimiter);
                if (Fields.Length == 7)
                {
                   //stuff happens here
                }
        }//Try
        catch (Exception e)
        {
            if (Interactive)
            {
                MessageBox.Show("Error in the Path: ->" + FileName);
                writeToLog(true, "error opening file " + FileName);
            }
        }
    }//end of processThisItemFile

the error happens in the "string[] Lines = System.IO.File.ReadAllLines(FileName)" line. FileName comes from the di.GetFiles("*.txt"); when I show the actual path it looks ok to me. I have tried with UNC paths and with drive letters path as in C:\tmp\filename.txt or \\server\tmp\filename.txt both fail in the deplopyment machine with "The given path's is not supported" but it works fine in the development machine.

What is going on?

JRN
  • 11
  • 2

1 Answers1

0

I'm wondering if this could be related to file.fullname somehow altering the file path string and giving an unacceptable result. Can you troubleshoot by using processThisIMFile(Path.GetFullPath(file))? Also, use messagebox.show(file.FullName) prior to processthisimfile to confirm that the result is as expected.

peterpep
  • 314
  • 3
  • 11