当前位置:编程学习 > C#/ASP.NET >>

File.WriteAllText报具有非法路径

在应用File.WriteAllText报具有非法路径,主要原因是传的路径类似:
F:\2013\"双十一"保障信息.html
如果遇到这种情况怎么解决?因为路径中包含了双引号的原因 asp.net --------------------编程问答-------------------- 路径是拼接出来的? --------------------编程问答-------------------- 验证一下文件名,不让输非法字符
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- 路径是拼接出来的,
类似代码如下:
string fileName = Info.TITLE + ".html";
                    string xfilePath = "Files/DocCenter/03/98/" + System.DateTime.Now.Year.ToString() + "/" + Info.GUID + "/";
                    string rfilePath = Server.MapPath("../../" + xfilePath);
                    if (!Directory.Exists(rfilePath)) Directory.CreateDirectory(rfilePath);
                    File.WriteAllText(rfilePath + fileName, strMainBodyHtml, System.Text.Encoding.UTF8);
拼接出来的如:F:\2013\"双十一"保障信息.html
就会报错,因为html文件名不能包括、\/:*?"<>| --------------------编程问答--------------------
求一个正则表达式 去除字符中包含的这些字符、\ / : * ? " < > |   
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,