-3

I am trying to connect to a remote server and access a specific directory in that server for searching a file but for some reason it shows that the directory doesnt exist on the server even though it actually exists. I am guessing that my file path is wrong. Can anyone please suggest me if I made a syntax error?

filepath = @"\\172.17.20.11\E$\MessageLogs\" + logType + "\\" + country + "\\" + year + "\\" + month + "\\" + day + "\\";

 private void GetFiles(string filePath)
    {
        try
        {
            tblFileContent = new DataTable();
            getColumns(tblFileContent);
            //C:\MessageLogs\ElmaCore\KENYA\2016\March\22
            //filePath = @"C:\MessageLogs\"+filePath; //Pick a folder on your machine to store the uploaded files

            if (!Directory.Exists(filePath))
            {
                fn.MessageLine(this.Page, "Log folder does not exist.", System.Drawing.Color.Red, "lblMessageLine");
                dtDate.Focus();
                return;
            }

            string searchReference = txtReference.Text.Trim();
            //string filePath = System.Configuration.ConfigurationManager.AppSettings["InFolder"].ToString();

            DirectoryInfo DirInfo = new DirectoryInfo(filePath);
            FileInfo[] CsvFiles = DirInfo.GetFiles("*" + searchReference + "*.log").OrderByDescending(p => p.LastWriteTime).ToArray();


            if (CsvFiles.Length > 0)
            {
                foreach (var file in CsvFiles)
                {
                    string FileName = file.Name;
                    string sourceFile = System.IO.Path.Combine(filePath, FileName);

                    ProcessFile(FileName, sourceFile);



                }

                //LoadGrid();
            }
            else {
                fn.MessageLine(this.Page, "Sorry, No files found for the specified reference.", System.Drawing.Color.Red, "lblMessageLine");
                txtReference.Focus();
                return;
            }
        }
        catch (Exception ex)
        {
            fn.MessageLine(this.Page, "Sorry an Error Occured. Please try again", System.Drawing.Color.Red, "lblMessageLine");
            ErrLogger.LogError("filelog-" + ex.Message);  //oledbconn.Close();
            return;
        }

    }
Nelly
  • 1
  • 3
    If you made a syntax error, it wouldn't compile. If the directory actually exists, this is a permissions issue. – CodeCaster Dec 22 '16 at 09:45
  • either you don't have permissions, or the folder is not shared on the network. (Assuming you've verified that the program is generating the folder name correctly) – ADyson Dec 22 '16 at 09:47
  • See also [Directory.Exists not working for a network path](http://stackoverflow.com/questions/10196811/directory-exists-not-working-for-a-network-path). – CodeCaster Dec 22 '16 at 10:04

1 Answers1

0

As you say your directory exists than it might the problem with permission. Please make sure account under which code is been running have permission to that folder.

Also note that once you deploy in IIS, change identity of apppool to a domain user who has permission.

If you want to verify if its permission problem, than just do this. Right click into that folder and give permission to everyone and test.

Manish Makkad
  • 237
  • 1
  • 5
  • 13