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

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:How to open files from a specific route in ASP-NET c#?