Selecting a file via javascript

Asked

Viewed 140 times

0

I have a folder with several pdf files and needed to select the pdf 1348.pdf, but via javascript, is it possible to do this ? Would I have to use an Handler ? and how would I return this value (Binary,name and size) ?

~/files/1348.pdf

In a server method would look like this:

 DirectoryInfo diretorio = new DirectoryInfo(Server.MapPath("~/arquivos/"));
                FileInfo[] arquivos = diretorio.GetFiles("1348.pdf"); 

I wanted to know how to do this via javascript

  • Explain better what you want with examples of preference

  • @Rafaelaugusto put an example code that would be needed on the server for javascript but I do not know if it is possible.

  • What you intend to do with the selection of this file?

  • 1

    If the files are on the server you need some server-side script (.net, php and etc) or you can even do "only" with javascript... but you need to be able to configure the server so that it allows Browse access of content directly to the directory.

  • @Rafaelaugusto I made a screen that loads the data via javascript without going to the database and I include a pdf file per data if the user wishes, but when I load the page the other day and have the data there I need to load this pdf, so that he knows he has a file there and/or if he wants to delete it, then basically to show the name to the user and store it in fileupload and then delete if the client wants.

  • @Leandroangelo ok so basically I will need to use an ajax method that sends the parameters as "file name" and in Handler I select the file, but how would I return this file to ajax? context.Response.Write(file) ?

  • Sorry, @Voltz, but it’s still a little confused what you intend to do. You want to view the pdf on a web page, download the file or display on the screen the list of files you have in this directory?

  • @Leandroangelo If I can list them all via javascript I think I can already follow with my problem

  • @Leandroangelo I just need to get the files so I can delete them, all this via javascript/webmethod/Handler

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.