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
Try testing for additional file type extensions: