当我单击链接标签打开文档时,不支持给定路径的格式。 [英] The given path's format is not supported, when i click a linklabel to open a document.

查看:82
本文介绍了当我单击链接标签打开文档时,不支持给定路径的格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiii每个人



我在c#windows窗体中有一个linklabel。它必须打开服务水平协议pdf,以便客户只读。或者如果它是一个word文档,管理员必须能够读取或写入它。

我的代码下面会引发错误,说不支持给定路径的格式。

















string file_name =C:\\Users\\matimu.shibambu \\Desktop \\ ExponantSystem \\ET \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ br />
{

file_name = Environment.GetFolderPath(Environment.SpecialFolder.Resources)+ file_name;

StreamReader objReader;

objReader = new StreamReader(file_name); //此处出错(不支持给定路径的格式。)

objReader.Close();



}

否则

{

MessageBox.Show(文件不存在+ file_name);

}

Hiii everyone

I have a linklabel in c# windows form. it has to open a service level agreement pdf for clients to read only. or if it is a word document an administrator must be able to read or write on it.
my code below it raises an error saying "The given path's format is not supported."








string file_name = "C:\\Users\\matimu.shibambu\\Desktop\\ExponantSystem\\ETS\\ETS\\SLA\\Template - SharePoint SLA 2013 V1 00.doc";
if (System.IO.File.Exists(file_name) == true)
{
file_name = Environment.GetFolderPath(Environment.SpecialFolder.Resources) + file_name;
StreamReader objReader;
objReader = new StreamReader(file_name);// error here ("The given path's format is not supported.")
objReader.Close();

}
else
{
MessageBox.Show("file does not exist" + file_name);
}

推荐答案

Environment.GetFolderPath(Environment.SpecialFolder.Resources)返回一个没有终止'\'字符的路径:

Environment.GetFolderPath(Environment.SpecialFolder.Resources) returns a path without a terminating '\' character:
C:\Windows\resources

所以你需要首先添加'\',然后转储<$ c中当前存在的路径$ c> file_name

您现在生成的字符串是:

so you need to first add a '\' to that, then dump the path that currently exists in your file_name
The string you are generating at the moment is:

C:\Windows\resourcesC:\Users\matimu.shibambu\Desktop\ExponantSystem\ETS\ETS\SLA\Template - SharePoint SLA 2013 V1 00.doc

请尝试以下操作:

So try this:

string file_name = "C:\\Users\\matimu.shibambu\\Desktop\\ExponantSystem\\ETS\\ETS\\SLA\\Template - SharePoint SLA 2013 V1 00.doc";
...
file_name = Environment.GetFolderPath(Environment.SpecialFolder.Resources) + "\\" + Path.GetFileName(file_name);


这篇关于当我单击链接标签打开文档时,不支持给定路径的格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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