Download links in Blazor - asp.net

I'm programatically creating links to download files of different formats like .csv and .yml.
My code is
<a href="/organs/#organ/#policy/#folder.Name/#file.Name" download>#file.Name</a>
so lets say these links get created:
https://localhost:44372/organs/Heart-Lung/03-15-2020/data/fakedata.yml
https://localhost:44372/organs/Heart-Lung/03-15-2020/data/testdata.csv
the .csv works as it should, I click and it downloads. the .yml however opens a new web page at that link and then says that it can't be found
I'm really not sure what I'm doing wrong, is there a way force it to download or should I be doing this a different way?

I ended up using javascript to do this, based on https://wellsb.com/csharp/aspnet/blazor-jsinterop-save-file/
most of the code is the same, but I changed the link to this to pass in the variable and to keep it as a clickable link that doesn't go anywhere
<a href="javascript:void(0)" #onclick=#(() => DownloadFile(file.FullName))>#file.Name</a>

Related

how to get the dynamic loaded content from a webpage (Alphafold database)

I think similar topics may have been discussed before. But I still could not find the solution. Here is the example page
https://alphafold.ebi.ac.uk/entry/P82662
I want to extract the target downloading URL:
https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.pdb
When I "Inspect" this page in Chrome, I could see the desired URL here:
<a _ngcontent-brn-c12="" class="vf-button vf-button--secondary vf-button--sm" style="color: #3B6FB6;" href="https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.pdb">PDB file </a>
I used request.get to get the html but could not find the target URL, and realized this could be dynamically loaded. Then, under the Network tab and Fetch/XHR I could only see a similar URL without the desired file type:
https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.cif
So how can I get this URL string using request?

Absolute external links bug, url of the current page added at the beginning of the url

I have a very strange external links behavior on this page:
https://dev.switchonpaper.site/en/daniel-g-andujar-the-artist-as-a-thinker-and-augur-of-what-happens/
There is a list of external links visible by clicking on "Go Deeper".
On some links, the address of the current page is added at the beginning of the external link.
E.g.: iSAMâ„¢ (1997)
E.g.: TTTP Photo Collection - 1997
All external links are absolute links.
When you look at the source code, the links are correct.
This site runs under Wordpress, the links are contained in a Gutenberg block built with the ACF plugin.
I tested the following things:
Disable all plugins.
The browser or something else continues to add the current page address on some links only.
I emptied the server cache, removed all the .htaccess rules except the wordpress part.
I made sure that the PHP file that writes these links is in UTF-8.
By recreating the links, it is always the same ones who are affected.
Does anyone have any idea what could cause this?
Thank you for your time and help!
You have the so called "hidden characters" before your link start. I suggest you to check it by yourself with some online tool like this: https://www.soscisurvey.de/tools/view-chars.php. If you try to paste there the link copied by your source code you will see you have hidden stuff before "https:..."
The solution to this issue is that you delete all the characters and you write them all over again by yourself, w/o copy/pasting them from another source or in alternative paste them inside some non-HTML text editor before pasting them to your website

Remove link to document caching in ASP.NET

I'm trying to append DateTime.Now.Ticks to my link to stop it from caching as I'll be replacing it often. The problem I'm having when I do the code below is that it's adding a Content path in the url.
The original link was:
<a target="_blank" href="~/Documents/Data/Acct/MyDocument.pdf">Document</a>
This obviously caches the file on the browser so when I overwrite MyDocument.pdf the users don't see that unless they Ctrl-F5. So I changed it to the following:
<a target="_blank" href=#string.Format("{0}?t={1}", "~/Documents/Data/Acct/MyDocument.pdf", DateTime.Now.Ticks)>Document</a>
This produces a link that looks like: Content/~Documents/Data/Acct/MyDocument.pdf" which obviously doesn't exist because it's adding in Content and keeps the ~. If I remove the ~ I still get Content/Documents/Data/Acct/myDocument.pdf. How do I stop .NET from adding this Content/ to my link?
To add, the page that this link is in, is inside a folder called Views/Content. So I guess that's where it's being called from, but the ~ I assume should go up a level but it's not.
<a target="_blank" href=#string.Format("{0}?t={1}", "../Documents/Data/Acct/MyDocument.pdf", DateTime.Now.Ticks)>Document</a>
If you want to go up a level in your Url use ../ should get rid of the Content

Google Tag Manager - Event - Track Download on .aspx

I have an issue where I am trying to track the filedownloads on a website trough Google Tag Manager events. What I am doing is and already done on many websites is to find out if the "Click Url" contains any of the filetypes I am looking for like pdf, docx and so on. The issue here is that the Click Urls does not contain the information and are ending with .aspx. What is the best method to solve this issue?
I'd rephrase the question: what do these links (elements) have in common, that point to various downloadable files, and that is different from anything else, what is not a download link. This can be referred in GTM as a trigger.
Consider the following example:
<a class="button file_download" id="file_link_12" href="index.aspx?action=download&file_id=12">Download file</a>
If any of these can be identified in your HTML source code, then you can use these as triggers, which describes your elements used to point to downloadable files, e.g.:
Click Classes contains file_download
Click ID contains file_link
Click text equals Download file
Click URL contains action=download
If you are able to alter the HTML code, than you can choose any of these methods above, that bests suits your needs.

Plone 4 Zope Display Contents of specific folder TALES

Problem
I have a customer that wishes to display the entire contents of a certain folder (containing images) on their search page, should the search return 0 results. The folder is located at mysite.com/images
Setup:
As a test environment I have setup a seperate site with the following structure:
ROOT
|-Folder1 <-- current directory I am viewing
| |-images
|-Other folders
I modified the folder_summar_view template, to include the following code (I decided to modify a view to see if I could hack that to pieces to make it do what I want):
<div tal:define="image context/images/getFolderContents">
<div tal:content="i" tal:repeat="i image" />
</div>
What I see:
<Products.ZCatalog.Catalog.mybrains object at 0x9d2ddb8>
Things I've tried and further explanations
I was under the assumption that when the context/images/getFolderContents returns a brain for the 'objects' in my images folder, I could then iterate through each 'object' using my tal:repeat statement below it. Then display them on my page.
If I just use the following code:
<div tal:content="context/images/getFolderContents" />
My output is very similar to the above 'What I see' section:
<Products.ZCatalog.Catalog.mybrains object at [...]>
where [...] is another number
I've been doing some research and reading the Plone Theming book, but my code is similar to their tal:repeat examples on page 169, it seems the only difference is they are not using this on a brain (as far as I can tell).
I tried this, although it produced the same results (not sure why I tought it wouldn't):
<div tal:define="image python:context.images.getFolderContents()">
<div tal:content="i" tal:repeat="i image" />
</div>
I don't seem to be able to 'get inside' the returned brain. Everything I've looked for online doesn't quite help that much, I've also trawled through the atct_album_view and folder_listings templates to know avail. - I think I'm overlooking or missing something.
The first link I stumbled across was this, however I have moved on since that as although similar, it's not quite what I was trying to do.
The Plone guys on their chat room were kind enough to give me the context/images/getFolderContents statement, I tried to press on without asking for help again but it seems I've hit a wall.
More stuff I've tried
Using this link as inspiration I decided to try the following:
<div tal:define="image context/images/getFolderContents">
<div tal:content="image/getURL" />
</div>
But that throws an error when I try to view the template. The error reads along the lines of the 'getFolderContents brain does not have the attribute getURL' - Although image/Title displays the name of the folder, but that's not really what I need.
I also found this link however because I am making use of the default search, I don't really want to have to edit python scripts as I fear it may adversely effect the normal Plone site search. Also in this link they seem to be making use of more Python scripts. - To expand on this point, I'm not sure on how these scripts 'link' with page templates (how they know to 'talk' to one another).
Conclusion
In conclusion I need to display all of the images contained within a folder named "images" located at the root of my site, I am unable to access the contents of a returned brain using getFolderContents. And other than displaying the title of the "images" folder or the brain identifcation (<Products.ZCatalog.Catalog.mybrains object at 0x9d2ddb8>) , I have had no luck. Any help or ideas welcomed!
As getFoldercontents returns a list of brains i cant see how your code can work.
Just repeat over it with something like that :
<tal:block tal:repeat="image context/images/getFolderContents">
<a tal:attributes="href image/getURL" tal:content="image/Title"/>
</tal:block>

Resources