Open an XML file in a browser window

Hi ,
I want to open an XML file in a new browser window through a vb.net
web application.
The XML is placed in shared network location and i am getting its path
from the DB.
Could you let me now how to do it.
Regards,
VikramLike most, you can achieve this in a number of ways. Here are a couple of options:

1. You could map a path to the shared directory on IIS and use http URLs.

2. You could use file paths like this "file:///C:\sharedDirectory\file.xml" or "\\servername\sharedDirectory\file.xml". I don't prefer this method however it may be the easiest approach if you are allowing/denying access to the files via user access levels.

3. The application can open the file, read the bytes from the file, stream the bytes to the browser and add the proper response headers. This would be my preferred method.Thanks Cstick for your reply.
I think approach 2 and 3 would be useful to me .
Approach 2
Could you let me know which method should I call to open file by giving file path as parameter.
Approach 3
If read contents of the file which method should I call which redirects the contents of
the file to the browser.In approach 2 I assumed that you would create a anchor tag and use the network path like this <a href=http://www.webdeveloper.com/forum/archive/index.php/"\\myserver\mydirectory\myfile.xml" target="_blank">myfile.xml</a>. However, you may be able to do a response.redirect("\\myserver\mydirectory\myfile.xml").

For approach 3, once you have the file bytes you can use the following lines to stream to the browser assuming its an XML file:

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "text/xml" 'The file's MIME type.
Response.AddHeader("Content-Disposition", "inline; filename=myfile.xml")
Response.BinaryWrite(FileBytes) 'The bytes from your file
'Using response.End() rather than response.Flush() is important
'because it will send the stream before any html is added to the buffer
Response.End()
 
Back
Top