Ask the Expert

How can I make IIS automatically save the XML file into a directory?

I'm a rookie when it comes to IIS (using 5.0) and XML. I'm getting an XML pushed to my IIS. How can I automate for IIS to save the XML file into a directory? Any help will be greatly appreciated.
It depends on how the file is being "pushed." IIS is not only about Web applications; it is also an FTP server. So the file could be pushed through FTP, which is really straightforward with regards to saving it to a folder.

On the other hand, if the receiver is an ASP.NET application, you can easily achieve the same effect by creating an IHttpHandler that receives incoming files and stores them in a know location. The handler code would be something like the following:

using System;
using System.IO;
using System.Web;

public class FileSaver : IHttpHandler
{
 public bool IsReusable
 {
  get { return true; }
 }

 public void ProcessRequest(HttpContext context)
 {
  context.Request.Files[0].SaveAs(@"c:incomingdata.xml");
 }
}

Then, you map this handler to a certain location in the Web.config file:

<configuration>
 <system.web>
        <httpHandlers>
            <add verb="POST" path="filesaver.ashx" type="FileSaver,
MyAssembly" />
        </httpHandlers>        
 </system.web>
</configuration>

Now you can POST a file to the filesaver.ashx URL and the handler will save it to the location specified.

This was first published in September 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: