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

标签 c# visual-studio-2008 string text

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

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

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

谢谢大家的意见/建议。我只是想捕获字符串中的文件路径。但是当我尝试时: string fullpath = Page.Request.PhysicalPath;

在我的 C# 代码中并在此行上设置了一个断点,我查看了 Watch 窗口并输入了 fullpath,它说 fullpath is out of context。你能理解这个吗?如何将路径获取到字符串变量中?

Marvin,不确定你的意思,但这是我在上下文中的更多代码:

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

最佳答案

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

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

我测试了它,它可以得到一个完整路径的字符串,如果你以后用它做一些事情,你可能需要去掉字符串开头和结尾的引号

关于c# - 将文件路径转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2640931/

相关文章:

c# - 如何从sql server数据库检索数据并在C#中操作它?

c# - 我们可以锁定目录吗?

python - 神秘的 "1;3409;0c"行从何而来

c++ - Visual Studio 2008 项目的 msbuild

java - 为什么我不能将 java 线程名称与字符串进行比较?

javascript - 匹配字符串

c# - Entity Framework 5 性能问题

c# - 如何从 Google API 获取 JSON 数据并将其存储在变量中?

javascript - 给定文化的文化特定货币

c++ - 是否可以将其他文件类型添加到 Visual Studios 清理程序中?