Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old March 5th, 2007, 07:25 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when I add that the grid view becomes all gray with the text:
Error Cretaing Control- GridView1
System.Web.UI.Webcontrols.DataControlFieldCollecti on must have items of type 'System.Web.UI.WebControld.DaraControlField'. 'a' is of type 'System.Web.UI.HtmlConrols.HtmlAnchor'.


  #12 (permalink)  
Old March 6th, 2007, 02:40 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Sorry, forgot to say that explicitly: you need to use that inside a TemplateColumn, just as you did with HyperLink1:

<asp:TemplateField>
  <ItemTemplate>
    <a id="A1" href='<%# ~/downloadPDF.aspx?fullname=" + Eval("FullName") %>' runat="server">Download</a>
  </ItemTemplate>
</asp:TemplateField>

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #13 (permalink)  
Old March 6th, 2007, 01:14 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,
I get the following error:
The 'href' property had a malformed URL: '~/downloadPDF.aspx?fullname=C:\TEMP\pdf\001-XXXXX\001-001XX\001-00100_REV_A.pdf' is not a valid virtual path..

But it works when I use 'name' instead of 'FullName' !!!!!!

Here is the template field:
<asp:TemplateField HeaderText="TempLateDownload">
                    <ItemTemplate>
                        <a id="A1" href='<%# "~/downloadPDF.aspx?fullname=" + Eval("fullName") %>' runat="server">Download</a>

                    </ItemTemplate>
                </asp:TemplateField>

I had to add (") before ~/downloadPDF.aspx?... to make it work. It does not appear in your code:
<a id="A1" href='<%# ~/downloadPDF.aspx?fullname=" + Eval("FullName") %>' runat="server">Download</a>


  #14 (permalink)  
Old March 6th, 2007, 05:03 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In regards to the last error your getting, I wouldnt pass directory information through your links.

Its bad practice security wise. You should use releative pathing so you link.

You will want to use a relative path, and server.mappath() if you want to search using absolute pathing.

Your malformed URL problem, comes from the fact you have backslashes in your url I believe, without testing it first.

Your urls should be directory/directory/file.pdf not c:\dir\files.pdf

That is unless im reading this wrong. Are you trying to navigate the user into the right folder, or use your code to list all the files in a folder?



  #15 (permalink)  
Old March 6th, 2007, 05:16 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After a user enters a 'Part Numer', I want to display a list of files(pdf's) found on a certain folder. From there I want the user to be able to click on a link and open the file or view it..like you do on the posting in your website.

  #16 (permalink)  
Old March 6th, 2007, 05:28 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

The initial code I posted:

<a href='<%# "SomeUrl.aspx?Path=" + Eval("FullName") %>' runat="server">Download</a>

works fine. Things broke down when I added the example of the ItemTemplate and reused some of the stuff that you posted. I could be mistaken in my judgement, but since you posted this in a professional forum, I was sort of hoping you'd be able to figure out minor "I am typing this in a textarea with no compile time checking" errors in my post yourself.

Anyway, <a> is a simpe tag which doesn't use ~ syntax. So this:

<a id="A1" href='<%# "/downloadPDF.aspx?fullname=" + Eval("FullName") %>' runat="server">Download</a>

should work instead provided you paste this code in the ItemTemplate I posted earlier.

This should give you results like:

http://YourServer/downloadPDF.aspx?f...h\SomeFile.ext

And I agree with click: it's not really a good idea to pass full path info around in the querystring.....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #17 (permalink)  
Old March 6th, 2007, 07:17 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Imar,
I never worked with ASP and started using ASP.NET only few months ago. This is only my second 'small' project: i don't think i'll be able to spot too many "errors". For right now, people like yourself and others are my only resources which I appreciate very much.
I removed the ~ and the hyperlink is 'alive'.
But now i have another problem...although the querystring parameter is passed correctly, i am not able to open a pdf file (either I save it or open from the dialog box)
I am getting an Adobe Reader error message where the file name shown is a little different from the file name passed by the querystring:
if fullName is: C:\TEMP\pdf\001-XXXXX\001-001XX\001-00100_REV_A.pdf
The adobe box shows:C__TEMP_pdf_001-XXXXX_001-001XX\001-00100_REV_A[1].pdf
Any idea?


  #18 (permalink)  
Old March 6th, 2007, 07:22 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code i have for "downloadPDF.aspx:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim fileName As String
        If Request.QueryString.Get("FullName") IsNot Nothing Then

            fileName = Request.QueryString.Item(0).ToString
            Response.ContentType = "application/x-unknown"
            Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName)

        End If

        Me.TextBox1.Text = filename

    End Sub

and actually the "File Downlaod" dialog box shows...
********
Do you want to open or save this file?
Name: ...df_001-XXXXX_001-001XX_001-00100_REV_A.pdf
Type: Adobe Acrobat 7.0 Document, 836 bytes
From: localhost
**********
somehow the file name changed!!!!!!!

  #19 (permalink)  
Old March 6th, 2007, 07:34 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi click,

Thank you for your suggestion. The link is 'alive' with back or forward slash...I guess it doesn't matter.
I am not using relative path right now because i am just 'playing' with this. I want to see if i am able to make it work before I add it to my project. On the other hand, what I'd like, is to read files in folders that are not on the webserver(intranet actually).
I tried to connect to another server, but I was able to do it only from the application on my machine. When I moved the project files to the intranet server and used the browser I was not able to access a server that was different from the intranet server.
Maybe I should open another question regarding this problem????

  #20 (permalink)  
Old March 7th, 2007, 03:10 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the code of "downloadPDF.aspx" to this and it's working:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim fileName As String
        If Request.QueryString.Get("FullName") IsNot Nothing Then

            fileName = Request.QueryString.Item(0).ToString
            Response.Clear()
            ' Response.ContentType = "application/x-unknown"
            Response.ContentType = "application/octet-stream"
            Response.AppendHeader("Content-Disposition", "attachment; filename=" & Right(fileName, 10) + """")
            Response.Flush()
            Response.WriteFile(fileName)

        End If

        Me.TextBox1.Text = filename

        'If (myFile.ContainsFile) Then
        'Response.BinaryWrite(myFile.FileData)
        'Else
        'Response.WriteFile(Path.Combine(AppConfiguration. UploadsFolder, myFile.FileUrl))
        'End If


    End Sub

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
HyperLink in a gridview contro to open word docmen Otoniel ASP.NET Espanol 0 October 7th, 2008 01:11 AM
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Using Hyperlink field in GridView asp_convert ASP.NET 2.0 Basics 2 February 7th, 2007 07:33 PM
hyperlink pab006 Classic ASP Basics 5 December 17th, 2003 10:33 AM



All times are GMT -4. The time now is 11:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.