11376

How to open files from a specific route in ASP-NET c#?

I need a button that allows me to open any given file through ASP.NET C#.

Here's what I have already.

string strArchivo = "FileNameHere"; string strExtension = Path.GetExtension(strArchivo).ToLower(); if (strExtension == ".pdf") { //I open a file which is located in a folder called Archivos Response.Write("<script>window.open('/Archivos/" + strArchivo + "');</script>"); }

Here's the problem, I know that this method is used to open pdf files since they are opened on the browser, and then you can either download them or print them from there.

My boss is asking me that at least I could also open WORD, EXCEL and POWERPOINT files, since those are the most common.

Is there a way that I could either open or download those kind of files (or any file if possible)??

Oh and one more thing, about the code I showed you, I'm noticing that everytime this method is used to open a file, my website suddenly switches fonts (some letters become larger in size, and other just switch to gray like color), Is it because I'm missing something in that code or how can I work around it??

Thanks in advance

Answer1:

Try testing for additional file type extensions:

string strArchivo = "FileNameHere"; string strExtension = Path.GetExtension(strArchivo).ToLower(); if (strExtension == ".pdf" || strExtension == ".docx" || strExtension == ".doc"... etc) { //I open a file which is located in a folder called Archivos Response.Write("<script>window.open('/Archivos/" + strArchivo + "');</script>"); }

Recommend

  • Jersey: How to register MultiPartConfigProvider class
  • Efficient data structure to hold employee's activities?
  • How to Get A Count From Another Table In SQL?
  • Using Selenium, xpath cannot find 'text' element
  • Entity Framework unable to delete database, database in use
  • sudo easy_install for SimpleITK not that easy
  • Linking Ghostscript to pypdfocr in Windows Platform
  • in batch how do i use taskkill properly
  • Vuejs: Lifecycle hooks of child routerview components using keep alive
  • Portable JRE on Linux - possible?
  • saving file generated by TCPDF
  • Content-Length header not returned from Pylons response
  • Python urlparse: small issue
  • Read a local file using javascript
  • DomPDF {PAGE_NUM} not on first page
  • Email format validation in mvc3 view
  • Javascript simulate pressing enter in input box
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to add date and time under each post in guestbook in google app engine
  • Can I make an Android app that runs a web view in Chrome 39?
  • Importing jscolor library in angular 2
  • Why winpcap requires both .lib and .dll to run?
  • A cron job substitute?
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • How to set the response of a form post action to a iframe source?
  • coudnt use logback because of log4j
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal