C# 使用内部服务器名称无法识别转义序列

问题描述 投票:0回答:1

快速浏览了一下,没有看到这个问题针对我的具体问题得到解答。 我有一个内部服务器; xyz2112.internal.rush.com。 我们将文件复制到该服务器上的一个名为 Cygnus 的目录中。 我需要编写代码来打开位于此处的任何文件,无论是 .doc、.jpg、.xls 等...

所以,我从 intarwebz 的各个部分中提取了这段代码:

if (usr.Production == true)
{
    strURL = "\\\\xyz2112.internal.rush.com/Cygnus/" + ((Label)GridView_Attachments.Rows[index].FindControl("Question_Attachments")).Text;
}

new Process
{
    StartInfo = new ProcessStartInfo(@"" + strURL + "")
    {
        UseShellExecute = true
    }
}.Start();

这似乎不起作用。 当我单步执行代码时,strURL =“\xyz2112.internal.rush.com/Cygnus/C35392_10_24_2024_10_15_23 AM_10_Steps.jpg”。 如果我在服务器和文件夹名称之间使用“\”而不是“/”,则会收到“无法识别的转义序列”错误。我认为它没有正确转义引号? 我不太确定。 有人可以告诉我我做错了什么吗?

c#
1个回答
0
投票

经过一番尝试和错误后,这有效了:

strURL = "\\\\xyz2112.internal.rush.com\\Cygnus\\" + ((Label)GridView_Attachments.Rows[index].FindControl("Question_Attachments")).Text;

希望这可以帮助其他可能尝试做同样事情的人。

© www.soinside.com 2019 - 2024. All rights reserved.