c# - 错误 : The given path's format is not supported

标签 c#

出现此错误 不支持给定路径的格式。 在这一行

System.IO.Directory.CreateDirectory(visit_Path);

我在下面的代码中哪里做错了

void Create_VisitDateFolder()
        {
            this.pid = Convert.ToInt32(db.GetPatientID(cmbPatientName.SelectedItem.ToString()));
            String strpath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            String path = strpath + "\\Patients\\Patient_" + pid + "\\";
            string visitdate = db.GetPatient_visitDate(pid);
            this.visitNo = db.GetPatientID_visitNo(pid);
            string visit_Path = path +"visit_" + visitNo + "_" + visitdate+"\\";
            bool IsVisitExist = System.IO.Directory.Exists(path);
            bool IsVisitPath=System.IO.Directory.Exists(visit_Path);
            if (!IsVisitExist)
            {
                System.IO.Directory.CreateDirectory(path);
            }
            if (!IsVisitPath)
            {
                System.IO.Directory.CreateDirectory(visit_Path);\\error here
            }
        }

获取 visit_Path 的值

C:\Users\Monika\Documents\Visual Studio 2010\Projects\SonoRepo\SonoRepo\bin\Debug\Patients\Patient_16\visit_4_16-10-2013 00:00:00\

最佳答案

你不能在目录名中有 :,我建议你使用这个字符串来获取目录名中的日期:

DateTime.Now.ToString("yyyy-MM-dd hh_mm_ss");

它将创建如下时间戳:

2013-10-17 05_41_05

补充说明:

使用Path.Combine制作完整路径,例如:

var path = Path.Combine(strpath , "Patients", "Patient_" + pid);

最后

string suffix = "visit_"+visitNo+"_" + visitdate;
var visit_Path = Path.Combine(path, suffix);

关于c# - 错误 : The given path's format is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19424368/

相关文章:

C# 中的 JavaScript

c# - WPF - 防止绑定(bind)在加载数据时更新

c# - 如何提高 double 类型对于大数的精度?

c# - 具有 R3 和 ECC 的 SAP .NET Connector 3

c# - WinForms 上的单向绑定(bind)?

c# - Windows Phone 如何在后台运行应用程序?

c# - 将值数组四舍五入为 100%

c# - 如何在网站中实现移动内容/文本。在 asp.net 中

c# - InternalsVisibleTo - 如何防止某人创建具有相同名称的程序集并访问内部类或方法?

c# - HttpWebResponse 导致的奇怪字符