How do I get the path to the files you upload when uploading files using the file control in HTML? The video of Beida Jade Bird tells us to use:
File1.PostedFile.FileName
But in the breakpoint debugging, I found the problem.
In both Firefox and IETester, only filenames are displayed, not the full path of the file, and the filename obtained is also the file name. For example, the full path of the picture I selected is "e:\ accelerated Course Practice (i) \images\niunanlogo.jpg", but the browser shows "Niunanlogo.jpg", and the filename shown in debugging is also " Niunanlogo.jpg ", although this is very convenient, do not let us as the video said, to specifically intercept this part of the string (because the video shows the full path, you need to intercept the file name.) But what is this for? What if we need a full file path someday? Haha, these problems have already been solved, here I will learn from:
For IE or ietester, we found: Options-internet Properties-security-Custom level,:
The "File upload to server with local directory path" entry is set to start,
This will show the full path.
For Firefox also have a solution, interested can check it yourself Ah!
Solve the above problems, and create new doubts, this time breakpoint debugging found my program (VS2010 C #) in the filename display as:
E:\ \ Accelerated Course Practice (Me)\\images\ \ Niunanlogo.jpg "
And the video shows:
@"E:\ Accelerated Course Practice (Me)\images\niunanlogo.jpg "
What the hell is going on here?
Let's not worry about answering these questions first, let me imagine the following scenario:
If you want to display a word in the label, as follows:
A lot of English phrases related to "take"
How do you do it in the program?
If you write directly in the program:
Label1.Text = "Take" is associated with a lot of English phrases ";
This is not going to work.
As a general rule:
"" is used to indicate that the content it encloses is a string.
But now we just want to show it a double quote?
This time you need to escape the character, we must be unfamiliar, a "\" function is extremely powerful, it can "force" other characters to make changes.
Then we can write this:
Label1.Text = "Take \ " and "take" related to the English phrase a lot ";
Then there's no problem!
Now, fake into what we want the label to show:
E:\ Accelerated Curriculum Practice (i) \images\niunanlogo.jpg
So how do we write it?
If we write in the program:
label1.text= "E:\ Accelerated Curriculum Practice (i) \images\niunanlogo.jpg";
Error message: "Unrecognized escape sequence"
That is, by default, \ means the escape character, but we want it to represent only a backslash, so we write:
label1.text= "e:\\ Accelerated Curriculum Practice (i) \\images\\niunanlogo.jpg";
Then we find out the rules, and if we want to change the original meaning of a character, use the escape character (\) + The character you want to change the meaning to be OK. If we use n as a newline, we write \ n.
As you can see, if there are multiple \ in a path string, then I have to write the same number of additional \, is there a simple way?
Of course, it's written in the following form:
Label1.Text = @ "E:\ Accelerated Course Practice (i) \images\niunanlogo.jpg";
We know that, by default, \ is treated as an escape character, but after you precede it with @, the \ In the string behind it is handled as a backslash, not as an escape character.
So, now let's see why the video is not the same as my VS2010 display? In fact, they are one thing, but two kinds of writing, the purpose is to make \ represents a backslash. So the two are equivalent.
Summary:
This article is mainly through my practice in the problems encountered, said how to use the HTML file control to display the full path and the basic knowledge of escape characters, the content is very simple, but the process of solving the problem is very exciting!
Asp. NET summary--uploading files