C# 在asp.net c中访问文件服务器时出现的问题?

C# 在asp.net c中访问文件服务器时出现的问题?,c#,asp.net,C#,Asp.net,我试图连接到远程服务器并访问该服务器中的特定目录以搜索文件,但由于某种原因,它显示该目录在服务器上不存在,即使它实际上存在。我猜我的文件路径是错误的。如果我犯了语法错误,有人能建议我吗 filepath = @"\\172.17.20.11\E$\MessageLogs\" + logType + "\\" + country + "\\" + year + "\\" + month + "\\" + day + "\\"; private void GetFiles(string file

我试图连接到远程服务器并访问该服务器中的特定目录以搜索文件,但由于某种原因,它显示该目录在服务器上不存在,即使它实际上存在。我猜我的文件路径是错误的。如果我犯了语法错误,有人能建议我吗

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;
        }

    }

正如您所说,您的目录可能存在权限问题。 请确保运行代码的帐户具有该文件夹的权限

还请注意,在IIS中部署后,请将apppool的标识更改为具有权限的域用户

如果要验证其权限是否存在问题,请不要仅执行此操作。
右键单击该文件夹并授予所有人和测试权限

如果出现语法错误,它将无法编译。如果该目录确实存在,则这是权限问题。您可能没有权限,或者该文件夹未在网络上共享。假设您已经验证了程序也正在生成文件夹名correctlySee。