Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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#_Visual Studio 2008_String_Text - Fatal编程技术网

C# 将文件路径转换为字符串

C# 将文件路径转换为字符串,c#,visual-studio-2008,string,text,C#,Visual Studio 2008,String,Text,我正在用VS2008开发一个c#web应用程序,试图捕获所选文件的物理路径。使用IE,我现在终于能够在文本变量中检索到这个。但我想用字符串捕捉这些信息。我该怎么做 目前我正在使用: lb3.Text=Page.Request.PhysicalPath 它给了我: Text=“C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\AddFileToSQL\AddFileToSQL\Default.aspx”

我正在用VS2008开发一个c#web应用程序,试图捕获所选文件的物理路径。使用IE,我现在终于能够在文本变量中检索到这个。但我想用字符串捕捉这些信息。我该怎么做

目前我正在使用: lb3.Text=Page.Request.PhysicalPath

它给了我: Text=“C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\AddFileToSQL\AddFileToSQL\Default.aspx”

谢谢你们的评论/建议。我只是想用字符串捕捉文件路径。但当我尝试时: 字符串fullpath=Page.Request.PhysicalPath

在我的C#代码中,我在这一行设置了一个断点,我查看Watch窗口并输入fullpath,它说fullpath与上下文无关。这对你有意义吗?如何将路径放入字符串变量中

马文,不知道你的意思,但这更多是我在上下文中的代码:

protected void btnAppend_Click(object sender, EventArgs e)
        {
            Label lb3 = new Label();
            lb3.Text = Page.Request.PhysicalPath;
            string fullpath2 = Request.PhysicalPath;

我对它进行了测试,它工作正常。如果您稍后对它进行操作,则可能需要去掉字符串开头和结尾的引号

我对它进行了测试,它可以工作。如果您稍后使用它做些什么,您可能需要去掉字符串开头和结尾的引号“fullpath脱离上下文”-发生这种情况的原因很少,主要是因为您试图查看字符串对象时,字符串对象超出了范围

无论如何,您提供的代码是不正确的(如在Compileable中),但我明白了。你应该能够找到路径

protected void btnAppend_Click(object sender, EventArgs e) {
    System.Diagnostics.Trace.WriteLine("DEBUGGING! -> Page.Request.PhysicalPath = "
        + Page.Request.PhysicalPath);

    Label lb3 = new Label();
    lb3.Text = Page.Request.PhysicalPath;
    string fullpath2 = Page.Request.PhysicalPath;

    System.Diagnostics.Trace.WriteLine("DEBUGGING! ->  fullpath2 = " + fullpath2);
}
然后在IDE的“输出”窗口中查看结果。

“完整路径不在上下文中”-发生这种情况的原因很少,主要是因为您试图查看字符串对象时字符串对象超出了范围

无论如何,您提供的代码是不正确的(如在Compileable中),但我明白了。你应该能够找到路径

protected void btnAppend_Click(object sender, EventArgs e) {
    System.Diagnostics.Trace.WriteLine("DEBUGGING! -> Page.Request.PhysicalPath = "
        + Page.Request.PhysicalPath);

    Label lb3 = new Label();
    lb3.Text = Page.Request.PhysicalPath;
    string fullpath2 = Page.Request.PhysicalPath;

    System.Diagnostics.Trace.WriteLine("DEBUGGING! ->  fullpath2 = " + fullpath2);
}


然后在IDE的“输出”窗口中查看结果。

请求。PhysicalPath
已经是一个字符串。这不是您想要的吗?我想你回答了你的问题=)外面有满月吗?没有,但可能有;)你们能看到我修改过的问题吗?
请求。PhysicalPath
已经是一个字符串了。这不是你们想要的吗?我想你回答了你的问题=)外面有满月吗?没有,但可能有;)你们能看到我修改过的问题吗?谢谢,但这对我不起作用。请看我编辑的问题。将字符串fullpath=Request.PhysicalPath更改为fullpath=Page.Request.PhysicalPath谢谢谢谢谢谢!这起作用了。我只是错过了请求前的页面!不是的,只是一个简单的staringatcodetoolongitis的例子发生在所有的编码者身上。常见的症状是对编译错误感到过度不安,频繁遗漏;,下意识地修正密码。是的,劳伦斯。我可以补充一点吗?没有一个好的命名惯例,可能设计很差。谢谢,但这对我不起作用。请看我编辑的问题。将字符串fullpath=Request.PhysicalPath更改为fullpath=Page.Request.PhysicalPath谢谢谢谢谢谢!这起作用了。我只是错过了请求前的页面!不是的,只是一个简单的staringatcodetoolongitis的例子发生在所有的编码者身上。常见的症状是对编译错误感到过度不安,频繁遗漏;,下意识地修正密码。是的,劳伦斯。我是否可以补充一点:缺乏良好的命名约定,设计可能很差?
protected void btnAppend_Click(object sender, EventArgs e) {
    System.Diagnostics.Trace.WriteLine("DEBUGGING! -> Page.Request.PhysicalPath = "
        + Page.Request.PhysicalPath);

    Label lb3 = new Label();
    lb3.Text = Page.Request.PhysicalPath;
    string fullpath2 = Page.Request.PhysicalPath;

    System.Diagnostics.Trace.WriteLine("DEBUGGING! ->  fullpath2 = " + fullpath2);
}