CodeJunky
asked on
ASP Web Form to open files
Hi all, I'm very new to this; but have been coding in VB.NET for decades. I want to place hyperlinks on a form and when clicked, grab the tag value and open the file, such as a pdf, word, exec, etc.. In just VB I would add a hyperlink, this is client/server of course, and in the click event grab that tag value, being the file name and location, and pass that onto a function to open the file.
I don't even know if this is best practice; but it is what I am familiar with.
I don't even know if this is best practice; but it is what I am familiar with.
ASKER
Thanks HainKurt,
I don't understand this. I don't necessarily need to open file inside the browser. Everyone has a pdf viewer and microsoft office, so the system association should automatically be able to open any file.
Where do I get the FID from.
Do I place the full path in the File1, File2, etc....
I was expecting a click-event; but I don't think the Hyperlink has one like a button does.
I don't understand this. I don't necessarily need to open file inside the browser. Everyone has a pdf viewer and microsoft office, so the system association should automatically be able to open any file.
Where do I get the FID from.
Do I place the full path in the File1, File2, etc....
I was expecting a click-event; but I don't think the Hyperlink has one like a button does.
you dont need click event
your page will list the files with FID, a unique identifier that helps you find the file info from somewhere, probably db
and after getting file info, you will read the file, and put the content in response
set the meta tags and send to browser/client
then browser will get this and based on meta tag, it will open associated app and show the document retrieved...
your page will list the files with FID, a unique identifier that helps you find the file info from somewhere, probably db
and after getting file info, you will read the file, and put the content in response
set the meta tags and send to browser/client
then browser will get this and based on meta tag, it will open associated app and show the document retrieved...
You said click event, are you trying to do this using client side javascript?
In that case, it could look like
HTML
In that case, it could look like
HTML
<a class="doc" id="abc123" data-document="somefile.docx">Some File</a>
JAVASCRIPT/JQUERY$( document ).ready(function() {
$('.doc').on('click',function(){
//grab file from server directly if on the public www
// or ajax request to call up file if hidden from the public
});
});
As an aside, if your documents are at least semi-private, it is good practice to keep them out of the public www. If the document lives in the public like www.mysite.com/files/document1.docx then anybody with that URL can grab the file. You can instead store the files outside of your public folder and user your vb to call up the file on the server and send it to the browser (to open in the browser or force download).
ASKER
This is an ASP.net application using winforms.
ASKER
I'm currently working on this project on my desktop environment and would move it to an IIS server. I would want to place the files in a folder, on the server eventually, and source them from that location, whatever that location is going, or should, be. At this point I'm not using a database.
so this is internal application, not open to internet...
if so, something will just work fine...
<a target="_blank" href="file:///Z:/documents/File1.pdf">File1</a>
<a target="_blank" href="file:///Z:/documents/File2.docx">File2</a>
<a target="_blank" href="file:///Z:/documents/File1.xlsx">File3</a>
no OnClick event or any other code is required...
if so, something will just work fine...
<a target="_blank" href="file:///Z:/documents/File1.pdf">File1</a>
<a target="_blank" href="file:///Z:/documents/File2.docx">File2</a>
<a target="_blank" href="file:///Z:/documents/File1.xlsx">File3</a>
no OnClick event or any other code is required...
ASKER
That would be perfect but it didn't work. nothing happens when I click on the link.
Does it matter if the file has spaces in it? The file is also on my computer.
Does it matter if the file has spaces in it? The file is also on my computer.
ASKER
I just realized I'm using Edge Chromium. Like Chrome, it does not support direct file access. Is this correct?
ASKER
Just tried with IE and it still does nothing.
it does not matter
copy paste one of the file code here, so I can check what's wrong...
copy paste one of the file code here, so I can check what's wrong...
<a target="_blank" href="file:///Z:/documents/File1.pdf">File1</a>
That will not work on a iis web server
ASKER
<p>
<a target="_blank" href="file:///F:/DEV/ARDC_ASP/DocumentStores/Financial/Commit Payments Instructions.pdf">Commit Payments Instructions</a>
</p>
if browser does not allow this, then
on web server, you need to create a virtual folder and point to the path where files are...
for example, your page is here
c:\www\mySite
which is set as root for default web site on server
here, you define a Documents folder and point it to F:/DEV/ARDC_ASP/DocumentStores/
then your page will be
on web server, you need to create a virtual folder and point to the path where files are...
for example, your page is here
c:\www\mySite
which is set as root for default web site on server
here, you define a Documents folder and point it to F:/DEV/ARDC_ASP/DocumentStores/
then your page will be
<p>
<a target="_blank" href="/Documents/Financial/Commit Payments Instructions.pdf">Commit Payments Instructions</a>
</p>
then it will work...
ASKER
I'll give that a try in a little bit. I'm tired right now. Thanks so very much for you help and patience, I very much appreciate it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The workflow being proposed is wrong and should not work on an iis web serverit works everywhere as long as it is in intranet not open to public/internet...
if it is internet, I already suggested what to do...
here
https://www.experts-exchange.com/questions/29201954/ASP-Web-Form-to-open-files.html#a43204061
and after that post...
ASKER
Thanks to both of you. I will review all this and get back to you. This project is entirely internal and not in the public domain in any way.
<a href="openFile.asp?FID=873645">File2</a>
<a href="openFile.asp?FID=762455">File3</a>
openFile.asp
get the FID Request("FID")
do some lookup on db to find path and check session login if required
then open the file as binary
write to response
check this, it is for .Net but ASP is almost identical
Use ASP.NET and Visual C# .NET to write binary files to the browser
https://docs.microsoft.com/en-us/troubleshoot/aspnet/write-binary-files-browser-csharp