0

I need to write an asp.net application for use on our intranet. The user should be able to download a given large csv file from a file server using a web page. There are two reasons for using a web application for that - we want control and log the file loading, and also some of the users who will be loading the files use Macs, so I can not develop a win form application for them.

I would like to provide my users with a nice "Download File" button just like Microsoft or DownLoad.CNet do when I go there to download some software.

When I looked for javascript code samples, they all require me to provide a full destination file name, but in case of Apple computers, I do not know what the download path will be.

I also understand that I can just provide a link for download, but I would like to store the original files on a file server, not inside the web site, and I keep getting into permission problems when I specify file:// in href.

Could anyone please explain how this can be done?

Thank you.

user819490
  • 125
  • 1
  • 11
  • There might be a better solution than handling the file saving from within javascript, in that if you can get the generated file saved to a byte array, you can simply do a `Response.Clear()` then a `Response.BinaryWrite()` and close out the Response entirely after that. You'll want to add a content-disposition of inline to force the file to download as opposed to being displayed within the browser. – user2366842 Nov 06 '14 at 22:33

2 Answers2

0

Might work to just open a new window with the file server url, depends on how you have the ftp stuff configured:

window.open('ftp://myServer/catalog/someFile');

This is of course not very elegant, but it's at least an alternative. JavaScript uses http/websocket, so it's complicated when introducing ftp.

Amund Midtskog
  • 209
  • 1
  • 8
0

After reading more of the StackOverflow answers, I fond the answer that worked for me:

How to implement a file download in asp.net

The important part was the content type. I was trying to use content type 'text', whereas I needed to use this:

        Response.AddHeader("Content-Disposition", "attachment; filename=" + sourceFileInfo.Name)
        Response.AddHeader("Content-Length", sourceFileInfo.Length.ToString())
        Response.ContentType = "application/octet-stream"

Thanks everyone for help!

Community
  • 1
  • 1
user819490
  • 125
  • 1
  • 11