views:

168

answers:

2

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. 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;
+2  A: 

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

Laurence Burke
Thanks but this isn't working for me. See my edited question please.
salvationishere
changed string fullpath = Request.PhysicalPath to fullpath = Page.Request.PhysicalPath
Laurence Burke
Thank you thank you thank you! This worked. I was just missing the Page before Request!
salvationishere
lol... that's it? I thought it was tough problem. =D
Nayan
nope just a simple case of staringatcodetoolongitis happens to all coders. common symptoms are getting overly upset at compile errors, frequent omissions of ;, and correcting code subconsciously.
Laurence Burke
Yes Laurence. May I add lack of a good naming convention and possibly poor design?
Nayan
+1  A: 

"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.

Nayan