Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2008, 07:42 AM
Registered User
 
Join Date: Oct 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening a file using hyperlink

Hello,
I am trying to open a txt file using a hyperlink. This link is in the gridview. My code is following

<Columns>
    <asp:BoundField DataField="file_name" HeaderText="File Name"/>

    <asp:TemplateField HeaderText="Open">

    <ItemTemplate>
    <asp:HyperLink ID="Open" NavigateUrl='<%#DataBinder.Eval(Container.DataItem , "file_name","C:\\folder1\\{0}") %>' Text='<%# Eval("file_name") %>' runat="server" />
    </ItemTemplate>
    </asp:TemplateField>

</Columns>


When I hover the mouse on the link it shows files///c:/folder1/file1.txt but really does not open anything.

Please can someone help me with this? What am I doin wrong?
Should I write any code behind?

Please this is urgrent.

Thanks

 
Old October 8th, 2008, 08:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

In order for a browser to download a file from the server, the file must be accessible by the server over http. A path like c:\Folder1 only makes sense in the context of the web server, not the client.

Move the file to the root of your site and then reference it as something like:

... NavigateUrl="~/SomeFile.txt" ...

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old October 8th, 2008, 09:11 AM
Registered User
 
Join Date: Oct 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi there,

In order for a browser to download a file from the server, the file must be accessible by the server over http. A path like c:\Folder1 only makes sense in the context of the web server, not the client.

Move the file to the root of your site and then reference it as something like:

... NavigateUrl="~/SomeFile.txt" ...

Hope this helps,

Imar


Thanks Imar for your reply.
Right now this program is running from my m/c and the files and folders are on my m/c but eventually this file will be on server and clients will be accessing this. Also, in the database field I do not have full path of the file location, that's the reason I am appending C:\....

I am sorry I did not understand what you mean by 'Move the file to the root of your site'?


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old October 8th, 2008, 09:13 AM
Registered User
 
Join Date: Oct 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:Originally posted by Imar
Quote:
 Hi there,

In order for a browser to download a file from the server, the file must be accessible by the server over http. A path like c:\Folder1 only makes sense in the context of the web server, not the client.

Move the file to the root of your site and then reference it as something like:

... NavigateUrl="~/SomeFile.txt" ...

Hope this helps,

Imar


Thanks Imar for your reply.
Right now this program is running from my m/c and the files and folders are on my m/c but eventually this file will be on server and clients will be accessing this. Also, in the database field I do not have full path of the file location, that's the reason I am appending C:\....

I am sorry I did not understand what you mean by 'Move the file to the root of your site'?


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

[/quote]


Sorry, I wrongly posted my reply,

here is the original-
Thanks Imar for your reply.
Right now this program is running from my m/c and the files and folders are on my m/c but eventually this file will be on server and clients will be accessing this. Also, in the database field I do not have full path of the file location, that's the reason I am appending C:\....

I am sorry I did not understand what you mean by 'Move the file to the root of your site'?




 
Old October 8th, 2008, 09:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

No need to quote previous messages; the text is all here.

Anyway, not sure what you mean by m/c. Your server? With moving your files to the root, I meant to make them part of your site.

Let's say they page with the GridView is called Default.aspx. You access it like this (the actual address may vary):

http://localhost:3434/Default.aspx

Now, under the hood, Default.aspx exist on disk somewhere, at a location like c:\inetpub\wwwroot\default.aspx

The web server maps this physical address to ts virtual address. You need to do the same with your files: move them to c:\inetpub\wwwroot\ as well (or wherever your site is located) and address them like this:

http://localhost:3434/SomeFile.txt

Alternatively, look into Response.WriteFile: http://msdn.microsoft.com/en-us/libr...writefile.aspx

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a text file using hyperlink in a gridview absu General .NET 1 March 6th, 2009 02:03 AM
file opening jain_mj Visual C++ 0 November 4th, 2005 10:42 AM
how to print a file targated by a hyperlink in asp pinkuisadear Classic ASP Basics 0 April 15th, 2005 01:35 AM
Opening a new window from a hyperlink in an ItemTe acorbo ASP.NET 1.0 and 1.1 Professional 4 October 19th, 2004 01:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.