 |
| 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 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
|
|
|
|

March 5th, 2007, 07:25 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'.
|
|

March 6th, 2007, 02:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

March 6th, 2007, 01:14 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

March 6th, 2007, 05:03 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 6th, 2007, 05:16 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 6th, 2007, 05:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

March 6th, 2007, 07:17 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 6th, 2007, 07:22 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!!!!!
|
|

March 6th, 2007, 07:34 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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????
|
|

March 7th, 2007, 03:10 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |