Skip to main content

Programmatically create a Zip Archive file and send it as ActionResult using native ASP.NET MVC C#

If you’re working with ASP.NET or ASP.NET Core and you need to create a zip file on-the-fly within your controller – for example to allow the user to download multiple files with a single request – you can easily do that using the ZipArchive class, introduced in Framework 4.5.

Here’s a quick code sample using a MemoryStream and a couple of byte arrays representing two files:

(more…)

 

WannaCry: how to check if your system is protected using a PowerShell script

If you’ve stumbled upon this post you are probably well-aware of the Win32/WannaCrypt Ransomware, better known as WannaCry: we already talked about it in this other post, which contains an extensive list of links to download the various patches to shield almost any Windows-based operating system against this dangerous treat.

However, you might also need to find a way to quickly check if your system is effectively protected against WannaCry or not: this could come very handy if you are a System Administrator and you don’t know which server is missing the updates or not. Altough the best suggestion we can give would always be “patch everything”, you can also use this great PowerShell script (which we stole from this great post from SpiceWorks community site – credits to CarlosTech for the great job):

(more…)

 

80070005 Access is denied error while accessing Word Interop from the Server in a ASP.NET Application – How to fix

Last week I published a couple post regarding the use of the Microsoft.Office.Interop.Word namespace within an ASP.NET C# Application, respectively about opening a DOC or DOCX file from a Byte Array and converting them to PDF files. Although these techniques can be very useful to deal with MS Word documents, they have more than a couple drawbacks that we should always take into consideration when using them:

  • They are often painfully slow and inefficient, especially when dealing with huge amount of files (batch processing).
  • They consume a massive amount of memory – considering the task given to them.
  • They have a terrible multi-thread support, to the point that they might lead to scale/concurrency issues.
  • They do require MS Office installed where we use them.
  • They do require an awful set of permissions to allow the IIS users to access the required DCOM components the IIS.

I’m not saying we shouldn’t use them: as a matter of fact we kinda have to, unless we want to donate a kidney to some commercial libraries that can handle these tasks in a much better way. At the same time, we should get ready to experience some issues because they will create some havoc here and there sooner or later.

(more…)

 

Programmatically convert MS Word files to PDF in ASP.NET C#

Who never had the urge to convert one or more MS Word DOC and DOCX files into a PDF at least once? Truth to be told, it wasn’t that trivial back in the day: until the release of Office 2010, when the PDF extension appeared among the various  formats supported by the Save As… command, using Ghostscript-based software or installing PDF printer drivers was the only way to go.

After Office 2010 the problem was finally solved even for the average user, with the sole exception that he still has to have MS Office installed on his machine. Those who didn’t have it can continue to use the aforementioned free alternatives ond purchase a software that will take care of the job for them.

What about doing that in a programmatic approach? What if we are developing a C# application and we need to convert some DOC or DOCX files into PDF, thus making then available to download without giving the source document to the users, possibly without having to waste an Office license to our web server/web publishing machine?

(more…)

 

How to open and edit a Word DOC or DOCX file from FileSystem or Byte array in C#

If you’re working with ASP.NET C# and you need to open, edit or otherwise access a Microsoft Word DOC or DOCX file, you can easily do that using the Microsoft.Office.Interop.Word library package. This post explains how to do so: you might find it useful in case you need to perform such task or whenever you want to read some insights regarding the process.

Introducing Interop.Word

To access the namespace from your ASP.NET project you have two main choices:

Needless to say, you should really go for the second option, but we’ll leave that to you.

(more…)