开发者

convert file path to string

I am developing a c# web application with VS 2008 where I am trying to capture the physical path of the selected file. Using IE, I am finally able to retrieve this now in text variable. But I want to capture this information in string. How do I do this?

Currently I am using: lb3.Text = Page.Request.PhysicalPath;

And it gives me: Text = "C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\AddFileToSQL\AddFileToSQL\Default.aspx"

Thank you guys for your comments/advice. I am just trying to capture the file path in a string. But when I try: string fullpath = Page.Request.PhysicalPath;

in my C# code and set a breakpoint on this line, I look at the Watch window and enter fullpath and it says fullpath is out of context开发者_Python百科. Does this make sense to you? How do I get the path into a string variable?

Marvin, not sure what you mean but this is more of my code in context:

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;

to

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

I tested it and it works it gets a string to the fullpath if you do something with it later you might need to take off the quotation marks off the beginning and end of the string


"fullpath is out of context" - this can happen for few reasons, primarily because the string object was out of scope when you were trying to watch it.

Anyway, the code you provided is not correct (as in compilable), but I get the idea. You should be able to get the path.

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);
}

Then see in the 'output' window in the IDE to see the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜