Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: hyperlink to a text file in asp.net

0 views
Skip to first unread message

Bruce Barker

unread,
Feb 27, 2006, 2:25:13 PM2/27/06
to
browser security prevents a website from opening a file on the local disk

-- bruce (sqlwork.com)

"Sohan Kamat" <Sohan...@discussions.microsoft.com> wrote in message
news:EE012542-58EE-4A8C...@microsoft.com...
> Hi,
>
> I have a webform and I want to create a hyperlink to a text file, so that
> it
> opens on internet explorer in a new window.
> I have added the following
> <a href="file:///D:/Test/Test.txt" id="hplTest" runat="server"
>>testhyperlink</a>
>
> Now when I click on the hyperlink, nothing is happening. No error.
> when I open a browser and type file:///D:/Test/Test.txt, the file is
> opening.
>
> I would appreciate if anybody could help me out.
> Thanks,
> Sohan
>


Raymond

unread,
Feb 27, 2006, 4:46:51 PM2/27/06
to
That would've worked a few years ago, but no more.
One of the IE security patches from a couple of years
ago removed that capability.

Sohan Kamat

unread,
Feb 27, 2006, 10:56:28 PM2/27/06
to
So is there any other way to open a text file from local disk in internet
explorer in a webform?

Thanks,
Sohan

Raymond

unread,
Feb 28, 2006, 1:28:10 AM2/28/06
to
You can prompt the user to send you
the local file using a file input form field in
a form submission.

There is also something where you can write to
and then retrieve some small amounts of data, other than
in cookies, called IsolatedStorage.

As for arbitrarily sending the local path of that file from the
server and have it open automatically in IE, that's a no no.


"Sohan Kamat" <Sohan...@discussions.microsoft.com> wrote in message

news:4FB85F52-01D0-4638...@microsoft.com...

Sohan Kamat

unread,
Feb 28, 2006, 1:40:27 AM2/28/06
to
Prabably my question is not very clear. I think you are assuming that the
files are in user's machine. Its not. I will try to explain.
The text files are in the local folder of the server. I dont want to copy
the files to the folder where website is located. I want to provide some
feature where user can open those files and view them.
How can this be done.

Thanks,
Sohan

Raymond

unread,
Feb 28, 2006, 2:21:29 AM2/28/06
to
Well that's different. You can do something like this:


private void Page_Load(object sender, System.EventArgs e)
{
System.IO.StreamReader sr = new System.IO.StreamReader("c:\\test.txt");
Response.ContentType = "text/plain";
System.IO.TextWriter tx = Response.Output;
tx.Write(sr.ReadToEnd());
sr.Close();
}

"Sohan Kamat" <Sohan...@discussions.microsoft.com> wrote in message

news:7F045514-B199-43BC...@microsoft.com...

Sohan Kamat

unread,
Feb 28, 2006, 8:09:27 AM2/28/06
to
This works. Thanks.
I also want to do the following:
We have a webgrid (Infragistic - ultrawebgrid) on a Asp form (.net 2005),
and there is a column which will be populated with file names. On clicking on
a cell in the column, we need to open that file in internet explorer.

The files are located at D drive on the server. So basically we need to
append the absolute path to that column value(which I am able to do) and then
open that file in internet explorer in a new window(which I am not able to
do).
Could you help me on this please
Thanks,
Sohan

Raymond

unread,
Feb 28, 2006, 11:16:02 AM2/28/06
to
Add an anchor tag control to that column, set it's target attribute
to "_blank", it's href to an aspx page that will stream the
text data, as in the previous code sample I wrote, and pass the
file name via a querystring in the href URL to that page. Either that or
instead of using "_blank", add a client-side onclick handler for the
anchor tag, use window.open() to open the new window, and return
false to the onclick event.


"Sohan Kamat" <Sohan...@discussions.microsoft.com> wrote in message

news:A94CD575-E804-4021...@microsoft.com...

0 new messages