Display link to in table open file in classic asp - sql

I have set for files in Upload folder. Also file name & file created date is stored in Database. Now
I have to bind the table with record set & provide link to download file . How I can achieve this ? All uploaded files present in Upload Folder. Below is my code for the same.
<%
Do While NOT FileResultStatus.Eof
%>
<tr>
<td> <%= FileResultStatus.Fields("sr") %> </td>
<%
Dim link
link = Server.MapPath("Upload")
link = link +"\" + FileResultStatus.Fields("filename")
%>
<td> <a href= "<%= link %> "</a> <%= FileResultStatus.Fields("filename") %> </td>
<td> <%= FileResultStatus.Fields("records") %> </td>
</tr>
<%
FileResultStatus.MoveNext
Loop
%>
</table>
<%
FileResultStatus.Close
Set FileResultStatus=nothing
Connection.Close
Set Connection=Nothing
%>

I am not sure what your problem or question is. Please state more clearly what is not working.
Given that you are referencing the recordset in a correct way, there is one thing in that code that looks odd. The Server.MapPath function returns the physical path of Upload, i.e.something like C:\inetpub\wwwroot\my-application\Upload which is clearly not what you want as a href in your link. You want link like href="Upload/myfilenameFromRecordset.txt".

The link should be a relative path to the file uploads folder, not the physical path.
In your browser just type in the location to one of the known files and use that as the link.
For example, if your download link that you type in looks like:
http://yourserver/Upload/filename.ext
then your code should be:
Dim link
link = "Upload/" + FileResultStatus.Fields("filename")
You may have to experiment with the above or
link = "./Upload/" + FileResultStatus.Fields("filename")
depending on your setup

Related

In Middleman, how can I use the srcset attribute, and with relative file paths?

In Middleman, I can generate a relative image file path like so:
<%= tag :img, :src => "/images/down-caret-1x.png" %>
Which will output this:
<img src="/images/down-caret-1x.png">
I'd like to get an output that looks like this:
<img src="/images/down-caret-1x.png" srcset="/images/down-caret-2x.png 1000w">
Anyone know how to do that?
The docs mention using this:
<img src="<%= image_path('100px.jpg') %>" srcset="<%= image_path('300px.jpg') %> 3x, <%= image_path('200px.jpg') %> 2x, <%= image_path('100px.jpg') %> 1x">
but I don't see anywhere to set the image_path variable or whatever that is.
Thanks
You set it in your config.rb like this:
set :images_dir, "path/to/images"
I found this blog quite useful for configuring middleman: https://richardkall.se/building-static-websites-with-middleman-part-two/

Rails 3 export csv from partial?

I followed RBate's Railscast on the subject, but I have a caviat.
The view starts with a form to define the table's variables. On clicking submit, the form posts back to the same view and re-renders the partial (which is just the HTML table). It's not AJAX, it's all form params.
RBates uses a single variable and calls .to_csv on it. I have a complex table with many variables defined by the params and so don't know how to call .to_csv on the entire HTML table.
I need to be able to export just the results in the partial.
Thanks in advance for the ideas.
&&&&&&&& AS REQUESTED, SAMPLE CODE: &&&&&&&&
So, the full code is probably more confusing than helpful, but here's a slimmed down version:
stats/reporter.html.erb: (stat_reporter_path matches this URI)
<%= form_tag( :stat_reporter, method: :post ) do %>
form is in here
<%= submit_tag "Get my report" %>
<% end %>
<div>
<%= render 'stat_select' %>
</div>
stats/_stat_select:
<table>
<thead>
<tr>...column heads...</tr>
</thead>
<tbody>
<% #counties.each do |c| %>
<td><%= c.name %></td>
<% c.programs.each do |p| %>
<td><%= p.name %></td>
<% p.events.each do |e| %>
<td><%= e.name %></td>
...and so on...
</table>
Here's a screenshot
Looking back on this post, I would:
Create a link to a new view and pas all the variables to in the URL.
That view would use all the variables to create an HTML output that could be used to create the to_csv method
Once the csv file was created, the controller would render the original view.

How to compute path to file in public folder?

I created a folder called Uploads in my public folder.
I'd like to have people be able to click a link and download a file in that Uploads folder.
Here's my code:
<p>
<b>Certifications</b>
<%= link_to #tutor.tutor_degrees.first.name, # => "AS Level English"
root_path + #tutor.tutor_degrees.first.certification_scan %>
</p>
http://localhost:3000/Screen%20shot%202013-02-04%20at%206.01.11%20PM.png
It's missing the /uploads/ bit in the URL path.
If I add that string manually, I get a borked URL:
<p>
<b>Certifications</b>
<%= link_to #tutor.tutor_degrees.first.name,
root_path + '/uploads/' + #tutor.tutor_degrees.first.certification_scan %>
</p>
http://uploads/Screen%20shot%202013-02-04%20at%206.01.11%20PM.png
Try this...
<%= link_to #tutor.tutor_degrees.first.name, "http://#{request.host}/uploads/#{#tutor.tutor_degrees.first.certification_scan}" %>
must work :)

Grab file path from upload

I have an RoR script that when given the file path for an XML file, will parse it. I want to be able to find the file with the GUI, and then allow for my script to run. Here's what I have in the view:
<%= form_for :setup, :html=>{:multipart=>true}, :url=>{action=>"create"} do |f| %>
<%= f.file_filed :my_file %>
<%= f.submit "Upload" %>
<% end %>
The controller for the create area is:
$XML_FILE = params[:my_file]
routers = Router.new
#title = routers.overall_setup
if #title == "Everything worked" then
redirect_to "/"
end
Basically from here, how do you snag the file path out? I know that once the correct file path can be placed to $XML_FILE that the rest of the code works
After you've submited a form you can find upploaded file this way:
path = params[:setup][:my_file][:tempfile].path
where params[:setup][:my_file] is your file_filed name in the form
Rails 3
path = params[:setup][:my_file].path

Cucumber click only working when #javascript is used?

I know there's a simple fix for this but for the life of me I can't remember what it is.
My feature file is as following:
Scenario: Editing locations
When I edit "Western Australia"
And fill in "Name" with "Tasmania"
And I press "Save"
Then I should see a form success message
And I've defined the 'Edit' step as the following:
When /^I edit "([^"]*)"$/ do |name|
within(:xpath, "//tr[./td[contains(text(), '#{name}')]]") do
find(:css, "a img[alt=Edit]").click
end
end
The HTML for the index page it works on is as follows:
<tr>
<td>Western Australia</td>
<td>WA</td>
<td>
<img alt="Edit" src="/images/icons/pencil.png" title="Edit" />
</td>
</tr>
And then the form HTML:
<%= semantic_form_for [:admin, #location] do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :abbreviation %>
<% end %>
<%= f.submit "Save" %></li>
<% end %>
As it is, it doesn't work - I get the following error:
And fill in "Name" with "Tasmania" # features/step_definitions/web_steps.rb:39
cannot fill in, no text field, text area or password field with id, name, or label 'Name' found (Capybara::ElementNotFound)
But the form element 'name' is clearly there on the page.
If I add 'Then show me the page' before the 'Fill in' then capybara saves the index page, leading me to think it isn't getting to the edit form at all.
... Yet if I add the '#javascript' tag to the feature, it works perfectly, even though there is no Javascript on this page.
I've solved this once before, but for the life of me I can't work out how...
Well I managed to solve the problem - the issue was with my CSS selector that was clicking the 'Edit' link. I don't know why it didn't work as-was, but I changed the find(:css, "a img[alt=Edit]").click to read click_link('Edit') and it worked perfectly.
Source: http://groups.google.com/group/ruby-capybara/browse_thread/thread/9c997395306d40e2/
For starters, you need to actually "visit" the edit page using the Capybara visit method within your When block. Also, I don't believe you want to use fill_in for inserting text into your tags (at least according to the error message it is only for text fields/areas).