Angular2 - File download not working if the file name contains spaces - angular2-routing

Hi have a simple link that point to a file for download:
working file link
<a href="/assets/test/myFile.pdf" download>This Works</a>
The link works but if I try to implement a download link to a file with name that contains spaces, I get a corrupted file:
not working file link
<a href="/assets/test/my File not work.pdf" download>click here to download</a>
If I check the content of the corrupted file, I can find the html content of the homepage...
How can I manage the link to download for files that contains spaces?
Thanks

Space characters aren't allowed in URL's, so you have to encode them. Have you tried to change the name of the underlying file and referencing that?

Related

Download links in Blazor

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>

Opening an Excel .xlsx file in IE and following its embedded hyperlinks back to file server

I have an intranet site that lets users open files in the browser (by prompting for download). One of these files is an .xlsx workbook that contains hyperlinks which point to different locations of files (.pdfs, .docs) on the file server in which the .xlsx workbook is located.
It seems the file server path to the workbook is replaced by a "Temporary Internet Files/Content.IE5/" path, leading to the warning "cannot open the specified file" in Excel.
I tried downloading the Excel document first and then following the links, but they're still opening in the temp internet location
EDIT:
For instance, when hovering over the hyperlinks in excel they read: "file:///C:\Documents And Settings\%username%\Local Settings\Temporary Internet files\Content.IE5\40WSS3CB\" + filename
when they should read: "file:///\servername\Departments\Read\" + filename
How can I still open the excel file in the browser and retain the hyperlinks inside and have them not be replaced by the temporary internet files path?
can someone point me in the right direction ? Thanks!
I did some testing, and it almost comes from the way you store links. If you browse through the dialog of Insert hyperlink, then you will end with relative urls. That is, the common base is stored as a reference to the current xlsx file path, and the remainder is stored and displayed as link.
You are totally in the issue Richard Hare mentions, so following the procedure from the microsoft support site should help. It did the trick on my test at least.
UPDATE to sum up down.with.the.bass comments :
One option to solve this, if doable, is to open xlsx file from its network share location and not through the website. If it is forbidden for whatever reason, you may be able to update the links using a macro.
Do you have an option like "Update links on save" enabled?
In an earlier version of Excel it was set in Tools, Options, General-tab, Web Options-button, Files-tab.
Try unchecking it and resaving the document.
I just did in my server the same task (the one I understood):
Uploaded the hyperlink to some asp.net webpage.
<p>
test<br />
</p>
The "book1.xlsx" file has inside a cell which refers (hyperlinks) to some share directory (i.e \\NHSTXX1\TEST\MS OFFICE EXCEL - \\SERVERNAME\FOLDER\OTHER FOLDER )
And when clicked the hyperlinked cell, it opened the share directory I was looking for.
I tried with Firefox.
hope this help
Hyperlinks shouldn't just mysteriously change. I saved an excel file with a hyperlink in it - opened it with html - saved it - open it in excel again - and the link stays the same. So I'm not sure how this could be happening to you(if I understand your situation correctly).

Why is my <a href="test.xls"> is working and .txt is not?

I have a folder named Test. I have some .xls files and .txt , .doc files in it.
In the html I have
<p> Download excel file </p>
- when I click on this link it is opening a download window (Working fine)
<p> Download Text file </p>
<p> Download excel file </p>
But these 2 are not working. Instead of opening a download window they are going to that .doc file link and saying that the page cannot be found.
why the download window is coming for .xls and not for .do or .doc? How can I fix this??
You need to configure your server's MIME types, otherwise either the file will not be served up (and you'll get a 404) or the browser will not know how to handle the type of file.
See this article for more information.
Sounds silly, but I'm guessing that you need to check the file names and references to them and make sure they are exactly the same. Unless you are on a Windows box, case sensitivity is something to take into account too.
You would want to check this http://www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET

How to stop server-generated Word .DOCs from saving with "_files" folders?

I have a Word .DOCument that's being generated by a (classic ASP) server. It's an HTML file that's being output as a .DOC using the application/msword content type. The document is generated fine, saves fine, opens up fine in Word, and is fully editable...
The problem occurs on the next document save in Word. A folder is created in the document's directory with the name "<filename>_files" -- just as if you were saving a web page in IE. Inside this folder are three files: colorschememapping.xml, filelist.xml and themedata.thmx. This happens when originally generating the document using IE or Firefox.
-> How can I prevent these _files folders from being created when saving in Microsoft Word?
(flow: users clicks link in browser, Save (.doc) As..., open .doc in MS Word, edit, save -> "_files" folder)
It doesn't only happen generating file from Firefox/IE.
Microsoft Word 2007 does it when editing any HTML file and saving.
The issue is that if you delete the directory, the HTML file get deleted too.
My workaround:
Edit the file in Word usual
Save the file
Close the file (exit Word, or just
close it)
Right click on file in Explorer
Select "Open With"->Notepad.
Delete the file in Explorer
Go back to Notepad and Save
You now only have a HTML file an no _files directory.
If your output isn't too complicated try using RTF. I've had a decent amount of success by outputting RTF files with a .doc extension.
Word 2007 and 2010 default to multi file HTML documents, linking the document to the content files. This is the default behavior for HTML based documents.
The only way around it, that I've found, is to create a real Word Doc without basing it on HTML, or the user has the select "Single File Web Page" when they do a Save As.
Delete to recycle bin. This deletes both the word doc and the unwanted folder. Restore the word doc and then empty the bin.

Asp display txt from access

i got a field that contains txt files in my access database.
i want to display this txt file on my page. how can i read the file and display it exactly as it in file written? In which asp component can i display it? I know some methods to read file but they don't work as i want. my text files have a format and i want to display them so in my page.
Thanks
Solved!
it was very easy. i am giving the path to the file and just calling Response.Write(pathToFile)
in template.

Resources