我正在使用 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/