Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从数据库中打开文档_C# - Fatal编程技术网

C# 无法从数据库中打开文档

C# 无法从数据库中打开文档,c#,C#,我正在保存文件名中有空格的文档,因此数据库中的url为: http://wingtipserver/Lists/Knowit.Cv-EmployeeDocumentsListInstance/attachments/2/My Example Pdf File.pdf 但是,当我想在imagebutton中使用imagebutton.PostBackUrl打开它时,它将不会打开,因为文件路径是: http://wingtipserver/Lists/Knowit.Cv-EmployeeDocum

我正在保存文件名中有空格的文档,因此数据库中的url为:

http://wingtipserver/Lists/Knowit.Cv-EmployeeDocumentsListInstance/attachments/2/My Example Pdf File.pdf
但是,当我想在imagebutton中使用
imagebutton.PostBackUrl打开它时,它将不会打开,因为文件路径是:

http://wingtipserver/Lists/Knowit.Cv-EmployeeDocumentsListInstance/attachments/2/My%20Example%20Pdf%20File.pdf

如何删除空格?或者我应该对文件上传进行验证,这样我就不能上传带有空格的文档了?

如果直接查看文件系统,编码的空格直接等同于空格

是的,您应该规范化您的文件名,在我看来,不使用空格,而是用连字符或其他一些“规范”字符替换是有意义的。但是,除此之外,当你点击URL时会发生什么?404? 500? 如果你告诉我们你正在经历什么,那么我们可能会假设一个合适的解决方案,但就目前情况而言,你认为问题所在的地方实际上不应该是问题所在



在这里我要更正一下,在数据库中查找文件时,字符串自然不匹配。为了克服这个问题,应该在查找之前使用
Server.UrlDecode(urlPart)对URL中的路径进行解码

您可以在将url写入db之前对其进行url编码,然后它应该与第二个版本匹配。我可以尝试验证,因此不允许使用空格,现在我正在检查您是否只能使用以下表达式上载
文档、docx和pdf
(.*。([Dd][Oo][Cc])|.*。([Dd Oo][Cc][Xx])|.*。([Pp][Dd Ff]))
我该如何输入,使其也不允许有空格?