Windows blocking .XLS files downloaded from the Internet where the contents are HTML - asp.net

We have a legacy ASP.NET application that allows users to export the contents of a GridView control to Excel. This was achieved using this technique.
Recently, users have complained that they are unable to open their downloaded files in Excel. I tried it myself and discovered that Windows was blocking the downloaded file, preventing Excel from opening it.
It looks like Windows now regards XLS files that have been created from web page content as suspect. Is this the result of a recent Windows update? And is this technique of creating Excel files from web pages not recommended?

Correct, recent updates have broken this behavior (thanks to Nikki9696 for the article).
There are three workarounds listed:
Stop using HTML files masquerading as XLS
Unblock access to individual files (client side solution)
or add the source of the files to the Trusted Locations list in Excel (client side solution)
The best thing to do is #1. You should not be serving files with one data type as another file type. It's always generated a warning for users. Many Office clients that otherwise know how to open XLS files (such as Office for iPad) will choke when presented with an HTML file masquerading as XLS.
Instead, use a library to generate a modern XLSX file (which can be opened by Office 2003 and newer). There are several solutions such as EPPlus, NPOI, and Open XML SDK.
In the future, be careful to use supported solutions rather than cobbling together a hack like serving a file with the wrong extension.

Related

How to use AJAX File Browser for editing PDF files

AJAX File Browser works great with Microsoft Office documents. However, I do note that the same does not work well with PDFs.
Currently in our application, 95% of the documents being reviewed/edited are PDFs. So is there a way I can make the PDFs work with Ajax File Browser?
Basically I'm looking at a solution/product which will help us with editing the PDFs using Adobe reader/professional and storing them directly on the server.
The only way to open the the PDF document is using Java applet (or potentially other method with unrestricted access to local file system). The Ajax File Browser is provided with Java applet which mount mounts local file system and opens document for editing. The Java applet automatically engaged for non-MS Office documents or if MS Office is not found. This works on Windows, OS X and Linux.
You can find info about when the Java applet is engaged here: http://www.webdavsystem.com/ajax/programming/opening_ms_office_docs

Loading/Saving Word Documents from Web App (asp.net MVC)

I'm making a web app. Part of it includes the automatic generation of word documents (letters). Those documents need to be opened by the end user, then saved back to the server once they've finished editing.
I tried using webdav for this but the only browser I could actually launch word from (using active-x) was IE. I also found a plugin for firefox, but for Chrome I couldn't find a way that worked.
Next I thought about making the clients map a drive to webdav (or similar), then offering up the files as file://... links, but that only works if the webpage is on the local machine.
Before I resort to ditching word (the clients won't like this) and using CKEditor or TinyMCE, is there another way?
In short, I'd like to have links to a document on the page, which when clicked are opened in word, but the file should stay remote - and then when saving, it's the remote file that gets updated.
I've also looked at Zoho but it could be very expensive for this project, plus I don't think it can be white-labelled and also looks a bit old fashioned, UI wise.
Maybe Sharepoint can do what I need? Haven't looked at that much. Also thought of making a client app to run in the system tray and deal with things.
If there was a decent way of editing Word docs from within the browser with something like CKEditor/TinyMCE and once finished, conversion back to Word format actually worked 100%, that would suffice.
I'm open to totally fresh ideas if anyone has any...
Currently Chrome, Firefox and Safari support MS Office plugin. They can open and save documents directly to server. I have tested this with MS Office 2007 and MS Office 2007 just about a month ago.
Ideally, your users would be able to use Word natively. Is there any chance you could create an Office Add-In that hooks into the BeforeDocumentSave event, looks for some indicator that the file is associated with your application, and save the updated file to your server?
Saving to the server via the Word Add-In would probably need to include some unique identifier (in addition to file name), so you could overwrite the previous version server-side. Then, if you were using something like SignalR, you could trigger a refresh on the web page when the file was saved successfully (assuming they were still on that web page) on the server (via FileSystemWatcher).
Had same problem myself.
I solved it by setting up a webdav share on the server with digest authentication (SabreDAV), and tied it into the users table on my app backend.
In relation to the client end, I solved accessing this by creating a small java applet which uses the java Desktop class (getDesktop().open()) to open the file. You will need to make sure the path is handled right for the client machine type (Windows, OS X or Linux)
You will also need to get your end users to permanently mount or map the webdav share locally.

Multiple files download in asp.net

I have some scenario in my application where i need to give multiple download functionality.
As much i come to know that multiple download is not possible using HTTP.Either we have to use multiple popup with javascript or we can do using web client.
I want to know that is there any other way to this.
Can we use FTP for multiple download in asp.net?
if yes, then how?
Check out this JQuery plug-in that does most of the work for you (and doesn't require you to ZIP all files):
https://github.com/biesiad/jquery-multidownload/ (fixed link)
No you can't use FTP in ASP.NET, however you could add all files to a single zip-file and let the user download that file (containing all files).
I would be tempted to zip the files on the server and send them down that way. Is that possible?
Alternatively you could try emailing the files to them.
Via HTTP you would probably need to use AJAX or iframes. The iframe option would be akin to making new windows just the user wouldnt need to see them. In this way you would have multiple http requests. I'm not sure how all of the browsers would deal with this though at the minute I am just speculating.
Most modern websites solve this problem by sending you the collection of files in a zipped package, sites like Google Drive for example. This is a perfect solution especially if you are expecting a large number of files.
However, if you expect a relatively low fixed number of files, and these files are statically stored in the server (meaning not generated at run-time), you can develop a client-side ajax script (jquery presumably) that will download the files one by one.
Initially this script would request a list of files to download (in json format for example), once received then it will enumerate through the result, firing an asynchronous request for the file one by one.

Is there a program that lets me edit web files with a native editor?

Before I attempt to program the following function myself, I wonder if something already exists.
What I would like to do is click an edit link on my website for a given document, and have that document launch in the native editor on my local machine (via a temporary file mechanism).
When I save the document in the native editor, the document is HTTP PUT back to the website. This can be accomplished by watching the file for writes, or watching the editor process for exit.
This way I can more easily edit documents on the web (instead of going through the download / edit / upload cycle).
My design would work as follows:
Register .webedit files on the local machine.
When a .webedit file is downloaded, launch webedit.exe with the file.
The file contains a URL (http://server/document) which is checked against a security database to ensure we're only opening allowed URLs.
The URL is downloaded to a temporary location.
The temporary file is launched in the native editor.
The file is watched for changes, and uploaded (HTTP PUT) on change detection (or when the editor is closed, if it's not a single-instance multiple-document editor).
Lots of FTP / SCP GUIs have this type of functionality, but I have not been able to find it for the web in general, or a shared library that allows you to plug in to this function.
Has anyone seen a program that does this?
SharePoint works like this.
It's great for managing shared documents in corporate environments.
Users can even checkout/checkin documents & the features are very extensible..you can customize pretty much anything if you know how.
Edit:
Since you're on Linux..i've heard that Alfreco is a great alternative.
I've never used it, but I know a couple organizations using it instead of SharePoint.
It integrates with Microsoft Office as well.
Also, it will definitely be cheaper.

asp.net(c#) Create Excel Worksheet, do i need Excel installed on the server?

I have created an application that uses Microsoft.Office.Interop.Excel, in my local and testing environments everything worked fine, but the app does not work in the production environment.
Turns out I have Office installed locally, as does the Test server, however, the production server does not have Excel installed.
I really can't go back and change my code, however, I would really not like to have to install Excel on the production server.
Do I have any other options other than installing Office Excel on the production server to get the application working?
Thanks,
Appreciate your assistance.
Steven
Office Interop does require that Office be installed on the server.
In the more general case, you do not need Excel to create worksheets, and you should avoid any solution that requires it for web use. That includes office interop: it doesn't scale in a web environment.
See this question for more options:
Generating an Excel file in ASP.NET
Did you try to find some free cost excel components for .NET. For example, these two components have free version for creating excel files:
gembox excel component (xlsx and xls files up to 150 rows)
excel jetcell net component (without restriction writes text to excel files xls and xlsx)
The Excel interop libraries work by opening the Excel application in the background to process the spreadsheet. So without updating your code, you will need to have Excel installed on the server. However using interop is a very slow and error prone solution to working with Excel from ASP.NET, the link Joel gave provides several good alternatives.

Resources