I'm not sure what sharifee's talking about because (unless some upgrade's happend that I'm unaware of) the ASP.NET FileUpload control does not work in an UpdatePanel which allows you to preform an asynchronous postback to the server (to upload/save the file)
When developing web applications you always have a clear understanding about what's executed client side (in the browser) and what's executed server side.
Your .NET code works server side. It cannot do anything client side...for example you cannot use .NET code to open a File Open Dialogue because the File Open Dialogue is run in the client's browser.
The only way you can actually get this to appear is using the
ASP.NET FileUpload control...which is rendered as an
<input type="file">.
There are a lot of restrictions with respect to the FileUpload control because of the potential security risks of allowing a website open files....imagine if a FileUpload object were able to read files client side.....it could be used to read any file (like a password, or banking information file).
So, the FileUpload control can only be used to upload files to the server. The path that it contains cannot be modified using JavaScript and you cannot set the path using .NET code either.
With this in mind you can see that you must upload the file to the server before you can read it's contents.
After that point you can use your C# code to set the innerHtml of the element that is being used to display the file contents.
Better yet, you should consider using an ASP.NET Localize control. The
Localize control can be used to print text into the web page without any HTML tags around it.
For example, if you had something like:
-
<div>
-
<asp:Label ID="SectionWhereTheFileContentIsDisplayed" runat="server"></asp:Label>
-
</div>
-
The HTML generated for the above would look like:
-
<div>
-
<span ID="SectionWhereTheFileContentIsDisplayed"> file content </span>
-
</div>
But if you were to use a Localize control instead:
-
<div>
-
<asp:Locolize ID="SectionWhereTheFileContentIsDisplayed" runat="server"></asp:Locolize >
-
</div>
-
The page would be rendered as:
-
<div>
-
file content
-
</div>