不支持给定路径的格式。 [英] The given path's format is not supported.

查看:621
本文介绍了不支持给定路径的格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string  fileNameOnDisk = appendName + newRequestId +   _ + filename; 
// 将文件保存为服务器上的基本名称。
fileInput.PostedFile。 SaveAs(ConfigurationManager.AppSettings [ FilePath] + \\CRAttachments \\ + fileNameOnDisk);





我尝试过:



i尝试过

 fileInput.PostedFile.SaveAs 

解决方案

我们无法分辨,因为我们无法看到您的数据包含什么 - 它可能是不允许的字符文件名,或者包含路径说明符。



因此,请使用调试器,查看要传递给SaveAs的值,并确切了解您要求它执行的操作:

  string  fileNameOnDisk = appendName + newRequestId +   _ + filename; 
string fn = ConfigurationManager.AppSettings [ FilePath] + \\CRAttachments\\ + fileNameOnDisk;
fileInput.PostedFile.SaveAs(fn);

SaveAs 行放置断点,并查看<$ c的内容$ c> fn

无论如何都要连接文件路径元素是个坏主意,你应该在最后阶段使用Path.Combine,因为它会为你删除不必要的路径分隔符。 / BLOCKQUOTE>

string fileNameOnDisk = appendName + newRequestId + "_" + filename;
                      // Save file as base name on server.
                      fileInput.PostedFile.SaveAs(ConfigurationManager.AppSettings["FilePath"] + "\\CRAttachments\\ " + fileNameOnDisk);



What I have tried:

i have tried

fileInput.PostedFile.SaveAs

解决方案

We can't tell, because we can't see what your data contains - and it could be characters which aren't allowed in file names, or which contain path specifiers.

So use the debugger, look at the values you are passing to SaveAs and see exactly what you are asking it to do:

string fileNameOnDisk = appendName + newRequestId + "_" + filename;
string fn = ConfigurationManager.AppSettings["FilePath"] + "\\CRAttachments\\ " + fileNameOnDisk;
fileInput.PostedFile.SaveAs(fn);

Put a breakpoint on the SaveAs line, and look at the content of fn
It's a bad idea to concatenate file path elements anyway, you should use Path.Combine for the final stage as it removes unnecessary path separators for you.


这篇关于不支持给定路径的格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆